fix(content-blog): always convert front matter date as UTC (#6244)

This commit is contained in:
Joshua Chen 2022-01-02 12:47:23 +08:00 committed by GitHub
parent 51d391a072
commit 9f0809ae28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -160,7 +160,12 @@ async function processBlogSourceFile(
async function getDate(): Promise<Date> {
// Prefer user-defined date.
if (frontMatter.date) {
return new Date(frontMatter.date);
if (typeof frontMatter.date === 'string') {
// Always treat dates as UTC by adding the `Z`
return new Date(`${frontMatter.date}Z`);
}
// YAML only converts YYYY-MM-DD to dates and leaves others as strings.
return frontMatter.date;
} else if (parsedBlogFileName.date) {
return parsedBlogFileName.date;
}