mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
feat: allow setting calendar for i18n date formatting (#6430)
* feat: allow setting calendar for i18n date formatting * fix TS * add test
This commit is contained in:
parent
3e110054d7
commit
7941a46be3
9 changed files with 54 additions and 12 deletions
|
@ -151,13 +151,18 @@ export function parseBlogFileName(
|
|||
return {date: undefined, text, slug};
|
||||
}
|
||||
|
||||
function formatBlogPostDate(locale: string, date: Date): string {
|
||||
function formatBlogPostDate(
|
||||
locale: string,
|
||||
date: Date,
|
||||
calendar: string,
|
||||
): string {
|
||||
try {
|
||||
return new Intl.DateTimeFormat(locale, {
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
timeZone: 'UTC',
|
||||
calendar,
|
||||
}).format(date);
|
||||
} catch (err) {
|
||||
logger.error`Can't format blog post date "${String(date)}"`;
|
||||
|
@ -253,7 +258,11 @@ async function processBlogSourceFile(
|
|||
}
|
||||
|
||||
const date = await getDate();
|
||||
const formattedDate = formatBlogPostDate(i18n.currentLocale, date);
|
||||
const formattedDate = formatBlogPostDate(
|
||||
i18n.currentLocale,
|
||||
date,
|
||||
i18n.localeConfigs[i18n.currentLocale]!.calendar,
|
||||
);
|
||||
|
||||
const title = frontMatter.title ?? contentTitle ?? parsedBlogFileName.text;
|
||||
const description = frontMatter.description ?? excerpt ?? '';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue