mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 00:27:21 +02:00
fix(content-docs): format last update date as "Jun 19, 2020" (#7673)
* consistent date formatting betweeen docs and blog * update error message * use short month names Co-authored-by: Joe Harrison <jharrison@drwuk.com>
This commit is contained in:
parent
2910f99bbc
commit
825211f41d
2 changed files with 24 additions and 7 deletions
|
@ -457,7 +457,7 @@ describe('simple site', () => {
|
||||||
unrelated_front_matter: "won't be part of metadata",
|
unrelated_front_matter: "won't be part of metadata",
|
||||||
},
|
},
|
||||||
lastUpdatedAt: 1539502055,
|
lastUpdatedAt: 1539502055,
|
||||||
formattedLastUpdatedAt: '10/14/2018',
|
formattedLastUpdatedAt: 'Oct 14, 2018',
|
||||||
lastUpdatedBy: 'Author',
|
lastUpdatedBy: 'Author',
|
||||||
tags: [],
|
tags: [],
|
||||||
});
|
});
|
||||||
|
@ -518,7 +518,7 @@ describe('simple site', () => {
|
||||||
title: 'Custom Last Update',
|
title: 'Custom Last Update',
|
||||||
},
|
},
|
||||||
lastUpdatedAt: new Date('1/1/2000').getTime() / 1000,
|
lastUpdatedAt: new Date('1/1/2000').getTime() / 1000,
|
||||||
formattedLastUpdatedAt: '1/1/2000',
|
formattedLastUpdatedAt: 'Jan 1, 2000',
|
||||||
lastUpdatedBy: 'Custom Author',
|
lastUpdatedBy: 'Custom Author',
|
||||||
sidebarPosition: undefined,
|
sidebarPosition: undefined,
|
||||||
tags: [],
|
tags: [],
|
||||||
|
@ -557,7 +557,7 @@ describe('simple site', () => {
|
||||||
title: 'Last Update Author Only',
|
title: 'Last Update Author Only',
|
||||||
},
|
},
|
||||||
lastUpdatedAt: 1539502055,
|
lastUpdatedAt: 1539502055,
|
||||||
formattedLastUpdatedAt: '10/14/2018',
|
formattedLastUpdatedAt: 'Oct 14, 2018',
|
||||||
lastUpdatedBy: 'Custom Author',
|
lastUpdatedBy: 'Custom Author',
|
||||||
sidebarPosition: undefined,
|
sidebarPosition: undefined,
|
||||||
tags: [],
|
tags: [],
|
||||||
|
@ -596,7 +596,7 @@ describe('simple site', () => {
|
||||||
title: 'Last Update Date Only',
|
title: 'Last Update Date Only',
|
||||||
},
|
},
|
||||||
lastUpdatedAt: new Date('1/1/2000').getTime() / 1000,
|
lastUpdatedAt: new Date('1/1/2000').getTime() / 1000,
|
||||||
formattedLastUpdatedAt: '1/1/2000',
|
formattedLastUpdatedAt: 'Jan 1, 2000',
|
||||||
lastUpdatedBy: 'Author',
|
lastUpdatedBy: 'Author',
|
||||||
sidebarPosition: undefined,
|
sidebarPosition: undefined,
|
||||||
tags: [],
|
tags: [],
|
||||||
|
|
|
@ -270,6 +270,21 @@ async function doProcessDocMetadata({
|
||||||
|
|
||||||
const draft = isDraftForEnvironment({env, frontMatter});
|
const draft = isDraftForEnvironment({env, frontMatter});
|
||||||
|
|
||||||
|
const formatDate = (locale: string, date: Date, calendar: string): string => {
|
||||||
|
try {
|
||||||
|
return new Intl.DateTimeFormat(locale, {
|
||||||
|
day: 'numeric',
|
||||||
|
month: 'short',
|
||||||
|
year: 'numeric',
|
||||||
|
timeZone: 'UTC',
|
||||||
|
calendar,
|
||||||
|
}).format(date);
|
||||||
|
} catch (err) {
|
||||||
|
logger.error`Can't format docs lastUpdatedAt date "${String(date)}"`;
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Assign all of object properties during instantiation (if possible) for
|
// Assign all of object properties during instantiation (if possible) for
|
||||||
// NodeJS optimization.
|
// NodeJS optimization.
|
||||||
// Adding properties to object after instantiation will cause hidden
|
// Adding properties to object after instantiation will cause hidden
|
||||||
|
@ -290,9 +305,11 @@ async function doProcessDocMetadata({
|
||||||
lastUpdatedBy: lastUpdate.lastUpdatedBy,
|
lastUpdatedBy: lastUpdate.lastUpdatedBy,
|
||||||
lastUpdatedAt: lastUpdate.lastUpdatedAt,
|
lastUpdatedAt: lastUpdate.lastUpdatedAt,
|
||||||
formattedLastUpdatedAt: lastUpdate.lastUpdatedAt
|
formattedLastUpdatedAt: lastUpdate.lastUpdatedAt
|
||||||
? new Intl.DateTimeFormat(i18n.currentLocale, {
|
? formatDate(
|
||||||
calendar: i18n.localeConfigs[i18n.currentLocale]!.calendar,
|
i18n.currentLocale,
|
||||||
}).format(lastUpdate.lastUpdatedAt * 1000)
|
new Date(lastUpdate.lastUpdatedAt * 1000),
|
||||||
|
i18n.localeConfigs[i18n.currentLocale]!.calendar,
|
||||||
|
)
|
||||||
: undefined,
|
: undefined,
|
||||||
sidebarPosition,
|
sidebarPosition,
|
||||||
frontMatter,
|
frontMatter,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue