mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-18 03:26:57 +02:00
refactor(v2): format post date using Intl (#4344)
* refactor(v2): format post date using Intl * Fix test * Blog: add localized blog post date test Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
a4b409c93b
commit
1dd400db7e
18 changed files with 87 additions and 214 deletions
|
@ -27,6 +27,7 @@ import {
|
|||
getEditUrl,
|
||||
getFolderContainingFile,
|
||||
posixPath,
|
||||
getDateTimeFormat,
|
||||
} from '@docusaurus/utils';
|
||||
import {LoadContext} from '@docusaurus/types';
|
||||
import {keyBy} from 'lodash';
|
||||
|
@ -168,6 +169,14 @@ export async function generateBlogPosts(
|
|||
|
||||
// Use file create time for blog.
|
||||
date = date || (await fs.stat(source)).birthtime;
|
||||
const formattedDate = getDateTimeFormat(i18n.currentLocale)(
|
||||
i18n.currentLocale,
|
||||
{
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
},
|
||||
).format(date);
|
||||
|
||||
const slug =
|
||||
frontMatter.slug || (match ? toUrl({date, link: linkName}) : linkName);
|
||||
|
@ -214,6 +223,7 @@ export async function generateBlogPosts(
|
|||
source: aliasedSource,
|
||||
description: frontMatter.description || excerpt,
|
||||
date,
|
||||
formattedDate,
|
||||
tags: frontMatter.tags,
|
||||
title: frontMatter.title,
|
||||
readingTime: showReadingTime
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue