tailwind-nextjs-blog/lib/remark-extract-frontmatter.ts

14 lines
346 B
TypeScript
Raw Normal View History

import { Parent } from 'unist'
import { VFile } from 'vfile'
2022-07-17 21:40:41 +08:00
import { visit } from 'unist-util-visit'
import { load } from 'js-yaml'
export default function extractFrontmatter() {
return (tree: Parent, file: VFile) => {
visit(tree, 'yaml', (node: Parent) => {
//@ts-ignore
2022-07-17 21:40:41 +08:00
file.data.frontmatter = load(node.value)
})
}
}