Home Case

青青


青青
A statically generated blog example using{" "}
因为在最后,可能会被trim掉,拼接的时候
gray-matter 专门用来解析 Markdown 文件顶部的 YAML 元信息(frontmatter)。
运行
npm install gray-matter
代码部分:
import fs from 'fs'
import matter from 'gray-matter'
const fileContent = fs.readFileSync('./post.md', 'utf8')
// 解析
const { data, content } = matter(fileContent)
解析结果 data:frontmatter 对象(标题、日期、slug、标签等) content:正文 Markdown 原文