mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-24 22:46:57 +02:00
feat: siteConfig.markdown.parseFrontMatter hook (#9624)
This commit is contained in:
parent
28e7298211
commit
affca7a9a2
27 changed files with 486 additions and 133 deletions
|
@ -120,6 +120,45 @@ The API documentation of each official plugin lists the supported attributes:
|
|||
|
||||
:::
|
||||
|
||||
:::tip enhance your front matter
|
||||
|
||||
Use the [Markdown config `parseFrontMatter` function](../../api/docusaurus.config.js.mdx#markdown) to provide your own front matter parser, or to enhance the default parser.
|
||||
|
||||
It is possible to reuse the default parser to wrap it with your own custom proprietary logic. This makes it possible to implement convenient front matter transformations, shortcuts, or to integrate with external systems using front matter that Docusaurus plugins do not support.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
markdown: {
|
||||
// highlight-start
|
||||
parseFrontMatter: async (params) => {
|
||||
// Reuse the default parser
|
||||
const result = await params.defaultParseFrontMatter(params);
|
||||
|
||||
// Process front matter description placeholders
|
||||
result.frontMatter.description =
|
||||
result.frontMatter.description?.replaceAll('{{MY_VAR}}', 'MY_VALUE');
|
||||
|
||||
// Create your own front matter shortcut
|
||||
if (result.frontMatter.i_do_not_want_docs_pagination) {
|
||||
result.frontMatter.pagination_prev = null;
|
||||
result.frontMatter.pagination_next = null;
|
||||
}
|
||||
|
||||
// Rename an unsupported front matter coming from another system
|
||||
if (result.frontMatter.cms_seo_summary) {
|
||||
result.frontMatter.description = result.frontMatter.cms_seo_summary;
|
||||
delete result.frontMatter.cms_seo_summary;
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
// highlight-end
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
## Quotes {#quotes}
|
||||
|
||||
Markdown quotes are beautifully styled:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue