mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 10:20:09 +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
|
@ -11,4 +11,16 @@ module.exports = {
|
|||
url: 'https://your-docusaurus-site.example.com',
|
||||
baseUrl: '/',
|
||||
favicon: 'img/favicon.ico',
|
||||
markdown: {
|
||||
parseFrontMatter: async (params) => {
|
||||
// Reuse the default parser
|
||||
const result = await params.defaultParseFrontMatter(params);
|
||||
if (result.frontMatter.last_update?.author) {
|
||||
result.frontMatter.last_update.author =
|
||||
result.frontMatter.last_update.author +
|
||||
' (processed by parseFrontMatter)';
|
||||
}
|
||||
return result;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -463,7 +463,7 @@ exports[`simple website content: data 1`] = `
|
|||
"frontMatter": {
|
||||
"title": "Custom Last Update",
|
||||
"last_update": {
|
||||
"author": "Custom Author",
|
||||
"author": "Custom Author (processed by parseFrontMatter)",
|
||||
"date": "1/1/2000"
|
||||
}
|
||||
}
|
||||
|
@ -686,7 +686,7 @@ exports[`simple website content: data 1`] = `
|
|||
"frontMatter": {
|
||||
"title": "Last Update Author Only",
|
||||
"last_update": {
|
||||
"author": "Custom Author"
|
||||
"author": "Custom Author (processed by parseFrontMatter)"
|
||||
}
|
||||
}
|
||||
}",
|
||||
|
|
|
@ -567,14 +567,14 @@ describe('simple site', () => {
|
|||
description: 'Custom last update',
|
||||
frontMatter: {
|
||||
last_update: {
|
||||
author: 'Custom Author',
|
||||
author: 'Custom Author (processed by parseFrontMatter)',
|
||||
date: '1/1/2000',
|
||||
},
|
||||
title: 'Custom Last Update',
|
||||
},
|
||||
lastUpdatedAt: new Date('1/1/2000').getTime() / 1000,
|
||||
formattedLastUpdatedAt: 'Jan 1, 2000',
|
||||
lastUpdatedBy: 'Custom Author',
|
||||
lastUpdatedBy: 'Custom Author (processed by parseFrontMatter)',
|
||||
sidebarPosition: undefined,
|
||||
tags: [],
|
||||
unlisted: false,
|
||||
|
@ -607,13 +607,13 @@ describe('simple site', () => {
|
|||
description: 'Only custom author, so it will still use the date from Git',
|
||||
frontMatter: {
|
||||
last_update: {
|
||||
author: 'Custom Author',
|
||||
author: 'Custom Author (processed by parseFrontMatter)',
|
||||
},
|
||||
title: 'Last Update Author Only',
|
||||
},
|
||||
lastUpdatedAt: 1539502055,
|
||||
formattedLastUpdatedAt: 'Oct 14, 2018',
|
||||
lastUpdatedBy: 'Custom Author',
|
||||
lastUpdatedBy: 'Custom Author (processed by parseFrontMatter)',
|
||||
sidebarPosition: undefined,
|
||||
tags: [],
|
||||
unlisted: false,
|
||||
|
@ -685,7 +685,7 @@ describe('simple site', () => {
|
|||
description: 'Custom last update',
|
||||
frontMatter: {
|
||||
last_update: {
|
||||
author: 'Custom Author',
|
||||
author: 'Custom Author (processed by parseFrontMatter)',
|
||||
date: '1/1/2000',
|
||||
},
|
||||
title: 'Custom Last Update',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue