mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
feat(content-blog): infer blog post date from git history (#6593)
This commit is contained in:
parent
665d164351
commit
6996ed2f2f
7 changed files with 127 additions and 57 deletions
|
@ -27,6 +27,7 @@ import {
|
|||
Globby,
|
||||
normalizeFrontMatterTags,
|
||||
groupTaggedItems,
|
||||
getFileCommitDate,
|
||||
getContentPathList,
|
||||
} from '@docusaurus/utils';
|
||||
import type {LoadContext} from '@docusaurus/types';
|
||||
|
@ -242,8 +243,17 @@ async function processBlogSourceFile(
|
|||
} else if (parsedBlogFileName.date) {
|
||||
return parsedBlogFileName.date;
|
||||
}
|
||||
// Fallback to file create time
|
||||
return (await fs.stat(blogSourceAbsolute)).birthtime;
|
||||
|
||||
try {
|
||||
const result = getFileCommitDate(blogSourceAbsolute, {
|
||||
age: 'oldest',
|
||||
includeAuthor: false,
|
||||
});
|
||||
return result.date;
|
||||
} catch (e) {
|
||||
logger.error(e);
|
||||
return (await fs.stat(blogSourceAbsolute)).birthtime;
|
||||
}
|
||||
}
|
||||
|
||||
const date = await getDate();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue