docs_vue2/one/build/remark-extract-frontmatter.js
2020-08-13 11:47:56 +08:00

17 lines
345 B
JavaScript

import visit from 'unist-util-visit'
import remove from 'unist-util-remove'
import yaml from 'js-yaml'
export default function attacher () {
return (tree, file) => {
let { data } = file
visit(tree, 'yaml', node => {
data.meta = yaml.safeLoad(node.value)
return visit.EXIT
})
remove(tree, ['yaml', 'toml'])
}
}