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

14 lines
353 B
TypeScript
Raw Normal View History

2022-10-17 23:37:01 +08:00
import { VFile } from 'vfile';
2023-07-09 14:19:21 +08:00
import { visit } from 'unist-util-visit';
2022-10-17 23:37:01 +08:00
import { load } from 'js-yaml';
2023-07-09 14:19:21 +08:00
import { Parent } from 'unist';
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
}