2022-10-07 13:55:39 +08:00
|
|
|
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() {
|
2022-10-07 13:55:39 +08:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|