-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(v2): read first heading as title and use it in front-matter (#4485)
* feat(v2): read first heading as title and pass it to front-matter * fix(v2): always trim content after extracting front-matter * fix(v2): remove heading from rss and keep duplicate heading * fix(v2): rollback some unnecessary comment changes * test(v2): add unit tests to blog * test(v2): add unit tests to docs * test(v2): correct issue on windows * test(v2): add additional test cases
- Loading branch information
Showing
16 changed files
with
448 additions
and
35 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
5 changes: 5 additions & 0 deletions
5
...plugin-content-blog/src/__tests__/__fixtures__/website/blog/heading-as-title.md
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,5 @@ | ||
--- | ||
date: 2019-01-02 | ||
--- | ||
|
||
# some heading |
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
1 change: 1 addition & 0 deletions
1
...ugin-content-docs/src/__tests__/__fixtures__/simple-site/docs/headingAsTitle.md
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 @@ | ||
# My heading as title |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,9 @@ | |
}, | ||
"engines": { | ||
"node": ">=12.13.0" | ||
}, | ||
"devDependencies": { | ||
"@types/dedent": "^0.7.0", | ||
"dedent": "^0.7.0" | ||
} | ||
} |
137 changes: 137 additions & 0 deletions
137
packages/docusaurus-utils/src/__tests__/__snapshots__/parseMarkdown.test.ts.snap
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,137 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`load utils: parseMarkdown parseMarkdownString should delete only first heading 1`] = ` | ||
Object { | ||
"content": " | ||
test test test test test test | ||
test test test # test bar | ||
# test | ||
### test", | ||
"excerpt": "", | ||
"frontMatter": Object { | ||
"title": "test", | ||
}, | ||
"hasFrontMatter": false, | ||
} | ||
`; | ||
|
||
exports[`load utils: parseMarkdown parseMarkdownString should ignore heading if its not a first text 1`] = ` | ||
Object { | ||
"content": "foo | ||
# test", | ||
"excerpt": "foo", | ||
"frontMatter": Object {}, | ||
"hasFrontMatter": false, | ||
} | ||
`; | ||
|
||
exports[`load utils: parseMarkdown parseMarkdownString should parse first heading as title 1`] = ` | ||
Object { | ||
"content": "", | ||
"excerpt": "", | ||
"frontMatter": Object { | ||
"title": "test", | ||
}, | ||
"hasFrontMatter": false, | ||
} | ||
`; | ||
|
||
exports[`load utils: parseMarkdown parseMarkdownString should preserve front-matter title and warn about duplication 1`] = ` | ||
Object { | ||
"content": "# test", | ||
"excerpt": "test", | ||
"frontMatter": Object { | ||
"title": "title", | ||
}, | ||
"hasFrontMatter": true, | ||
} | ||
`; | ||
|
||
exports[`load utils: parseMarkdown parseMarkdownString should read front matter 1`] = ` | ||
Object { | ||
"content": "", | ||
"excerpt": undefined, | ||
"frontMatter": Object { | ||
"title": "test", | ||
}, | ||
"hasFrontMatter": true, | ||
} | ||
`; | ||
|
||
exports[`load utils: parseMarkdown readFrontMatter should delete only first heading 1`] = ` | ||
Object { | ||
"content": "test test test # test bar | ||
# test | ||
### test", | ||
"excerpt": "", | ||
"frontMatter": Object { | ||
"title": "test", | ||
}, | ||
"hasFrontMatter": false, | ||
} | ||
`; | ||
|
||
exports[`load utils: parseMarkdown readFrontMatter should ignore heading if its not a first text 1`] = ` | ||
Object { | ||
"content": "foo | ||
# test", | ||
"excerpt": "", | ||
"frontMatter": Object {}, | ||
"hasFrontMatter": false, | ||
} | ||
`; | ||
|
||
exports[`load utils: parseMarkdown readFrontMatter should parse first heading as title 1`] = ` | ||
Object { | ||
"content": "", | ||
"excerpt": "", | ||
"frontMatter": Object { | ||
"title": "test", | ||
}, | ||
"hasFrontMatter": false, | ||
} | ||
`; | ||
|
||
exports[`load utils: parseMarkdown readFrontMatter should parse first heading as title and keep it in content 1`] = ` | ||
Object { | ||
"content": "# test", | ||
"excerpt": "", | ||
"frontMatter": Object { | ||
"title": "test", | ||
}, | ||
"hasFrontMatter": false, | ||
} | ||
`; | ||
|
||
exports[`load utils: parseMarkdown readFrontMatter should parse front-matter and ignore h2 1`] = ` | ||
Object { | ||
"content": "## test", | ||
"excerpt": "", | ||
"frontMatter": Object { | ||
"title": "title", | ||
}, | ||
"hasFrontMatter": true, | ||
} | ||
`; | ||
|
||
exports[`load utils: parseMarkdown readFrontMatter should preserve front-matter title and warn about duplication 1`] = ` | ||
Object { | ||
"content": "# test", | ||
"excerpt": "", | ||
"frontMatter": Object { | ||
"title": "title", | ||
}, | ||
"hasFrontMatter": true, | ||
} | ||
`; | ||
|
||
exports[`load utils: parseMarkdown readFrontMatter should read front matter 1`] = ` | ||
Object { | ||
"content": "", | ||
"excerpt": "", | ||
"frontMatter": Object { | ||
"title": "test", | ||
}, | ||
"hasFrontMatter": true, | ||
} | ||
`; |
Oops, something went wrong.