feat(content-blog): infer blog post date from git history (#6593)

This commit is contained in:
Felipe Santos 2022-02-09 13:18:32 -03:00 committed by GitHub
parent 665d164351
commit 6996ed2f2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 127 additions and 57 deletions

View file

@ -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();