mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-18 19:46:57 +02:00
feat(content-docs): last_update front matter (#7461)
Co-authored-by: Joshua Chen <sidachen2003@gmail.com> Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
a469ae3d63
commit
4f26a1911a
15 changed files with 499 additions and 36 deletions
packages/docusaurus-plugin-content-docs/src/__tests__
|
@ -57,7 +57,6 @@ ${markdown}
|
|||
return {
|
||||
source,
|
||||
content,
|
||||
lastUpdate: {},
|
||||
contentPath: 'docs',
|
||||
filePath: source,
|
||||
};
|
||||
|
@ -79,7 +78,7 @@ function createTestUtils({
|
|||
env = 'production',
|
||||
}: TestUtilsArg) {
|
||||
async function readDoc(docFileSource: string) {
|
||||
return readDocFile(versionMetadata, docFileSource, options);
|
||||
return readDocFile(versionMetadata, docFileSource);
|
||||
}
|
||||
async function processDocFile(docFileArg: DocFile | string) {
|
||||
const docFile: DocFile =
|
||||
|
@ -119,7 +118,7 @@ function createTestUtils({
|
|||
|
||||
async function testSlug(docFileSource: string, expectedPermalink: string) {
|
||||
const docFile = await readDoc(docFileSource);
|
||||
const metadata = processDocMetadata({
|
||||
const metadata = await processDocMetadata({
|
||||
docFile,
|
||||
versionMetadata,
|
||||
context,
|
||||
|
@ -137,14 +136,16 @@ function createTestUtils({
|
|||
}[];
|
||||
sidebars: Sidebars;
|
||||
}> {
|
||||
const rawDocs = docFiles.map((docFile) =>
|
||||
processDocMetadata({
|
||||
docFile,
|
||||
versionMetadata,
|
||||
context,
|
||||
options,
|
||||
env: 'production',
|
||||
}),
|
||||
const rawDocs = await Promise.all(
|
||||
docFiles.map(async (docFile) =>
|
||||
processDocMetadata({
|
||||
docFile,
|
||||
versionMetadata,
|
||||
context,
|
||||
options,
|
||||
env: 'production',
|
||||
}),
|
||||
),
|
||||
);
|
||||
const sidebars = await loadSidebars(versionMetadata.sidebarFilePath, {
|
||||
sidebarItemsGenerator: ({defaultSidebarItemsGenerator, ...args}) =>
|
||||
|
@ -230,6 +231,9 @@ describe('simple site', () => {
|
|||
'headingAsTitle.md',
|
||||
'doc with space.md',
|
||||
'doc-draft.md',
|
||||
'customLastUpdate.md',
|
||||
'lastUpdateAuthorOnly.md',
|
||||
'lastUpdateDateOnly.md',
|
||||
'foo/bar.md',
|
||||
'foo/baz.md',
|
||||
'slugs/absoluteSlug.md',
|
||||
|
@ -481,6 +485,164 @@ describe('simple site', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('docs with last_update front matter', async () => {
|
||||
const {siteDir, context, options, currentVersion, createTestUtilsPartial} =
|
||||
await loadSite({
|
||||
options: {
|
||||
showLastUpdateAuthor: true,
|
||||
showLastUpdateTime: true,
|
||||
},
|
||||
});
|
||||
|
||||
const testUtilsLocal = createTestUtilsPartial({
|
||||
siteDir,
|
||||
context,
|
||||
options,
|
||||
versionMetadata: currentVersion,
|
||||
});
|
||||
|
||||
await testUtilsLocal.testMeta('customLastUpdate.md', {
|
||||
version: 'current',
|
||||
id: 'customLastUpdate',
|
||||
unversionedId: 'customLastUpdate',
|
||||
sourceDirName: '.',
|
||||
permalink: '/docs/customLastUpdate',
|
||||
slug: '/customLastUpdate',
|
||||
title: 'Custom Last Update',
|
||||
description: 'Custom last update',
|
||||
frontMatter: {
|
||||
last_update: {
|
||||
author: 'Custom Author',
|
||||
date: '1/1/2000',
|
||||
},
|
||||
title: 'Custom Last Update',
|
||||
},
|
||||
lastUpdatedAt: new Date('1/1/2000').getTime() / 1000,
|
||||
formattedLastUpdatedAt: '1/1/2000',
|
||||
lastUpdatedBy: 'Custom Author',
|
||||
sidebarPosition: undefined,
|
||||
tags: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('docs with only last_update author front matter', async () => {
|
||||
const {siteDir, context, options, currentVersion, createTestUtilsPartial} =
|
||||
await loadSite({
|
||||
options: {
|
||||
showLastUpdateAuthor: true,
|
||||
showLastUpdateTime: true,
|
||||
},
|
||||
});
|
||||
|
||||
const testUtilsLocal = createTestUtilsPartial({
|
||||
siteDir,
|
||||
context,
|
||||
options,
|
||||
versionMetadata: currentVersion,
|
||||
});
|
||||
|
||||
await testUtilsLocal.testMeta('lastUpdateAuthorOnly.md', {
|
||||
version: 'current',
|
||||
id: 'lastUpdateAuthorOnly',
|
||||
unversionedId: 'lastUpdateAuthorOnly',
|
||||
sourceDirName: '.',
|
||||
permalink: '/docs/lastUpdateAuthorOnly',
|
||||
slug: '/lastUpdateAuthorOnly',
|
||||
title: 'Last Update Author Only',
|
||||
description: 'Only custom author, so it will still use the date from Git',
|
||||
frontMatter: {
|
||||
last_update: {
|
||||
author: 'Custom Author',
|
||||
},
|
||||
title: 'Last Update Author Only',
|
||||
},
|
||||
lastUpdatedAt: 1539502055,
|
||||
formattedLastUpdatedAt: '10/14/2018',
|
||||
lastUpdatedBy: 'Custom Author',
|
||||
sidebarPosition: undefined,
|
||||
tags: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('docs with only last_update date front matter', async () => {
|
||||
const {siteDir, context, options, currentVersion, createTestUtilsPartial} =
|
||||
await loadSite({
|
||||
options: {
|
||||
showLastUpdateAuthor: true,
|
||||
showLastUpdateTime: true,
|
||||
},
|
||||
});
|
||||
|
||||
const testUtilsLocal = createTestUtilsPartial({
|
||||
siteDir,
|
||||
context,
|
||||
options,
|
||||
versionMetadata: currentVersion,
|
||||
});
|
||||
|
||||
await testUtilsLocal.testMeta('lastUpdateDateOnly.md', {
|
||||
version: 'current',
|
||||
id: 'lastUpdateDateOnly',
|
||||
unversionedId: 'lastUpdateDateOnly',
|
||||
sourceDirName: '.',
|
||||
permalink: '/docs/lastUpdateDateOnly',
|
||||
slug: '/lastUpdateDateOnly',
|
||||
title: 'Last Update Date Only',
|
||||
description: 'Only custom date, so it will still use the author from Git',
|
||||
frontMatter: {
|
||||
last_update: {
|
||||
date: '1/1/2000',
|
||||
},
|
||||
title: 'Last Update Date Only',
|
||||
},
|
||||
lastUpdatedAt: new Date('1/1/2000').getTime() / 1000,
|
||||
formattedLastUpdatedAt: '1/1/2000',
|
||||
lastUpdatedBy: 'Author',
|
||||
sidebarPosition: undefined,
|
||||
tags: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('docs with last_update front matter disabled', async () => {
|
||||
const {siteDir, context, options, currentVersion, createTestUtilsPartial} =
|
||||
await loadSite({
|
||||
options: {
|
||||
showLastUpdateAuthor: false,
|
||||
showLastUpdateTime: false,
|
||||
},
|
||||
});
|
||||
|
||||
const testUtilsLocal = createTestUtilsPartial({
|
||||
siteDir,
|
||||
context,
|
||||
options,
|
||||
versionMetadata: currentVersion,
|
||||
});
|
||||
|
||||
await testUtilsLocal.testMeta('customLastUpdate.md', {
|
||||
version: 'current',
|
||||
id: 'customLastUpdate',
|
||||
unversionedId: 'customLastUpdate',
|
||||
sourceDirName: '.',
|
||||
permalink: '/docs/customLastUpdate',
|
||||
slug: '/customLastUpdate',
|
||||
title: 'Custom Last Update',
|
||||
description: 'Custom last update',
|
||||
frontMatter: {
|
||||
last_update: {
|
||||
author: 'Custom Author',
|
||||
date: '1/1/2000',
|
||||
},
|
||||
title: 'Custom Last Update',
|
||||
},
|
||||
lastUpdatedAt: undefined,
|
||||
formattedLastUpdatedAt: undefined,
|
||||
lastUpdatedBy: undefined,
|
||||
sidebarPosition: undefined,
|
||||
tags: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('docs with slugs', async () => {
|
||||
const {defaultTestUtils} = await loadSite();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue