feat: siteConfig.markdown.parseFrontMatter hook (#9624)

This commit is contained in:
Sébastien Lorber 2023-12-16 02:50:26 +01:00 committed by GitHub
parent 28e7298211
commit affca7a9a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 486 additions and 133 deletions

View file

@ -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: