-
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.
refactor(umi-plugin): use a common way to parse yaml config from md (#20
- Loading branch information
1 parent
cfdf256
commit 3290147
Showing
4 changed files
with
146 additions
and
60 deletions.
There are no files selected for viewing
13 changes: 3 additions & 10 deletions
13
packages/umi-plugin-father-doc/src/routes/getFrontMatter.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,19 +1,12 @@ | ||
import fs from 'fs'; | ||
import yaml from 'js-yaml'; | ||
|
||
const FRONT_MATTER_EXP = /^\n*---\n([^]+?)\n---/; | ||
import path from 'path'; | ||
import transformer from '../transformer'; | ||
|
||
/** | ||
* extract Front Matter config from markdown file | ||
*/ | ||
export default (filePath: string): { [key: string]: any } => { | ||
const content = fs.readFileSync(filePath).toString(); | ||
const raw = (content.match(FRONT_MATTER_EXP) || [])[1]; | ||
const result = {}; | ||
|
||
if (raw) { | ||
Object.assign(result, yaml.safeLoad(raw)); | ||
} | ||
|
||
return result; | ||
return transformer.markdown(content, path.parse(filePath).dir, true).config; | ||
} |
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