-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(umi-plugin): support to read frontmatter (#4)
- Loading branch information
1 parent
7a399ba
commit 63d5392
Showing
6 changed files
with
59 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
packages/umi-plugin-father-doc/src/transformer/remark/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
import unified from 'unified'; | ||
import stringify from 'rehype-stringify'; | ||
import frontmatter from 'remark-frontmatter'; | ||
import prism from '@mapbox/rehype-prism'; | ||
import parse from './parse'; | ||
import rehype from './rehype'; | ||
import yaml from './yaml'; | ||
import jsx from './jsx'; | ||
|
||
export default (raw: string, dir: string) => { | ||
const processor = unified() | ||
.use(parse) | ||
.use(frontmatter) | ||
.use(yaml) | ||
.use(rehype, { dir }) | ||
.use(stringify, { allowDangerousHTML: true }) | ||
.use(prism) | ||
.use(jsx); | ||
|
||
return processor.processSync(raw).contents as string; | ||
return processor.processSync(raw); | ||
}; |
12 changes: 12 additions & 0 deletions
12
packages/umi-plugin-father-doc/src/transformer/remark/yaml.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import yaml from 'js-yaml'; | ||
import visit from 'unist-util-visit'; | ||
|
||
export default () => (ast, vFile) => { | ||
visit(ast, 'yaml', (node) => { | ||
// save frontmatter to data | ||
vFile.data.frontmatter = Object.assign( | ||
vFile.data.frontmatter || {}, | ||
yaml.safeLoad(node.value), | ||
); | ||
}); | ||
} |