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

13 lines
329 B
TypeScript
Raw Normal View History

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