tailwind-nextjs-blog/lib/remark-extract-frontmatter.ts
2022-10-17 15:37:01 +00:00

13 lines
329 B
TypeScript

import { VFile } from 'vfile';
import { visit, Parent } 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
file.data.frontmatter = load(node.value);
});
};
}