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:
Alexey Pyltsyn 2021-03-04 21:11:31 +03:00 committed by GitHub
parent a4b409c93b
commit 1dd400db7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 87 additions and 214 deletions

View file

@ -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