Skip to content

Commit

Permalink
refactor(v2): format post date using Intl
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 committed Mar 3, 2021
1 parent 43c53df commit 3d49a04
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 206 deletions.
10 changes: 10 additions & 0 deletions packages/docusaurus-plugin-content-blog/src/blogUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
getEditUrl,
getFolderContainingFile,
posixPath,
getDateTimeFormat,
} from '@docusaurus/utils';
import {LoadContext} from '@docusaurus/types';
import {keyBy} from 'lodash';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -214,6 +223,7 @@ export async function generateBlogPosts(
source: aliasedSource,
description: frontMatter.description || excerpt,
date,
formattedDate,
tags: frontMatter.tags,
title: frontMatter.title,
readingTime: showReadingTime
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-content-blog/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export interface MetaData {
source: string;
description: string;
date: Date;
formattedDate: string;
tags: (Tag | string)[];
title: string;
readingTime?: number;
Expand Down
14 changes: 0 additions & 14 deletions packages/docusaurus-theme-classic/codeTranslations/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"theme.blog.paginator.navAriaLabel": "التنقل في صفحة قائمة المدونة",
"theme.blog.paginator.newerEntries": "إدخالات أحدث",
"theme.blog.paginator.olderEntries": "إدخالات أقدم",
"theme.blog.post.date": "{day} {month} {year}",
"theme.blog.post.nPosts": "{count} مقالات",
"theme.blog.post.onePost": "مقاله واحده",
"theme.blog.post.paginator.navAriaLabel": "التنقل في صفحة مقالات المدونة",
Expand All @@ -33,18 +32,6 @@
"theme.blog.tagTitle": "{nPosts} موسومة ب \"{tagName}\"",
"theme.common.editThisPage": "تعديل هذه الصفحة",
"theme.common.headingLinkTitle": "ارتباط مباشر بالعنوان",
"theme.common.month.april": "أبريل",
"theme.common.month.august": "أغسطس",
"theme.common.month.december": "ديسمبر",
"theme.common.month.february": "فبراير",
"theme.common.month.january": "يناير",
"theme.common.month.july": "يوليو",
"theme.common.month.june": "يونيو",
"theme.common.month.march": "مارس",
"theme.common.month.may": "مايو",
"theme.common.month.november": "نوفمبر",
"theme.common.month.october": "اكتوبر",
"theme.common.month.september": "سبتمبر",
"theme.common.skipToMainContent": "انتقل إلى المحتوى الرئيسي",
"theme.docs.paginator.navAriaLabel": "التنقل بين صفحات المستندات",
"theme.docs.paginator.next": "التالى",
Expand All @@ -66,4 +53,3 @@
"theme.tags.tagsPageLink": "عرض كل الوسوم",
"theme.tags.tagsPageTitle": "الوسوم"
}

26 changes: 0 additions & 26 deletions packages/docusaurus-theme-classic/codeTranslations/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
"theme.blog.paginator.newerEntries___DESCRIPTION": "The label used to navigate to the newer blog posts page (previous page)",
"theme.blog.paginator.olderEntries": "Older Entries",
"theme.blog.paginator.olderEntries___DESCRIPTION": "The label used to navigate to the older blog posts page (next page)",
"theme.blog.post.date": "{month} {day}, {year}",
"theme.blog.post.date___DESCRIPTION": "The label to display the blog post date",
"theme.blog.post.paginator.navAriaLabel": "Blog post page navigation",
"theme.blog.post.paginator.navAriaLabel___DESCRIPTION": "The ARIA label for the blog posts pagination",
"theme.blog.post.paginator.newerPost": "Newer Post",
Expand All @@ -67,30 +65,6 @@
"theme.common.editThisPage___DESCRIPTION": "The link label to edit the current page",
"theme.common.headingLinkTitle": "Direct link to heading",
"theme.common.headingLinkTitle___DESCRIPTION": "Title for link to heading",
"theme.common.month.april": "April",
"theme.common.month.april___DESCRIPTION": "April month translation",
"theme.common.month.august": "August",
"theme.common.month.august___DESCRIPTION": "August month translation",
"theme.common.month.december": "December",
"theme.common.month.december___DESCRIPTION": "December month translation",
"theme.common.month.february": "February",
"theme.common.month.february___DESCRIPTION": "February month translation",
"theme.common.month.january": "January",
"theme.common.month.january___DESCRIPTION": "January month translation",
"theme.common.month.july": "July",
"theme.common.month.july___DESCRIPTION": "July month translation",
"theme.common.month.june": "June",
"theme.common.month.june___DESCRIPTION": "June month translation",
"theme.common.month.march": "March",
"theme.common.month.march___DESCRIPTION": "March month translation",
"theme.common.month.may": "May",
"theme.common.month.may___DESCRIPTION": "May month translation",
"theme.common.month.november": "November",
"theme.common.month.november___DESCRIPTION": "November month translation",
"theme.common.month.october": "October",
"theme.common.month.october___DESCRIPTION": "October month translation",
"theme.common.month.september": "September",
"theme.common.month.september___DESCRIPTION": "September month translation",
"theme.common.skipToMainContent": "Skip to main content",
"theme.common.skipToMainContent___DESCRIPTION": "The skip to content label used for accessibility, allowing to rapidly navigate to main content with keyboard tab/enter navigation",
"theme.docs.paginator.navAriaLabel": "Docs pages navigation",
Expand Down
13 changes: 0 additions & 13 deletions packages/docusaurus-theme-classic/codeTranslations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"theme.blog.paginator.navAriaLabel": "Navigation der Blog-Listenseite",
"theme.blog.paginator.newerEntries": "Neuere Einträge",
"theme.blog.paginator.olderEntries": "Ältere Einträge",
"theme.blog.post.date": "{month} {day}, {year}",
"theme.blog.post.paginator.navAriaLabel": "Blog Post Seiten Navigation",
"theme.blog.post.paginator.newerPost": "Neuer Post",
"theme.blog.post.paginator.olderPost": "Älterer Post",
Expand All @@ -33,18 +32,6 @@
"theme.blog.tagTitle": "{nPosts} tagged with \"{tagName}\"",
"theme.common.editThisPage": "Diese Seite bearbeiten",
"theme.common.headingLinkTitle": "Direkter Link zur Überschrift",
"theme.common.month.april": "April",
"theme.common.month.august": "August",
"theme.common.month.december": "December",
"theme.common.month.february": "February",
"theme.common.month.january": "January",
"theme.common.month.july": "July",
"theme.common.month.june": "June",
"theme.common.month.march": "March",
"theme.common.month.may": "May",
"theme.common.month.november": "November",
"theme.common.month.october": "October",
"theme.common.month.september": "September",
"theme.common.skipToMainContent": "Zum Hauptinhalt springen",
"theme.docs.paginator.navAriaLabel": "Dokumentation Seiten Navigation",
"theme.docs.paginator.next": "Weiter",
Expand Down
13 changes: 0 additions & 13 deletions packages/docusaurus-theme-classic/codeTranslations/fa.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"theme.blog.paginator.navAriaLabel": "کنترل لیست صفحه وبسایت",
"theme.blog.paginator.newerEntries": "مطالب جدیدتر",
"theme.blog.paginator.olderEntries": "مطالب قدیمی تر",
"theme.blog.post.date": "{month} {day}, {year}",
"theme.blog.post.paginator.navAriaLabel": "کنترل پست های صفحه وبلاگ",
"theme.blog.post.paginator.newerPost": "پست های جدید تر",
"theme.blog.post.paginator.olderPost": "پست های قدیمی تر",
Expand All @@ -33,18 +32,6 @@
"theme.blog.tagTitle": "{nPosts} با برچسب \"{tagName}\"",
"theme.common.editThisPage": "ویرایش صفحه",
"theme.common.headingLinkTitle": "لینک مستقیم به عنوان",
"theme.common.month.april": "آوریل",
"theme.common.month.august": "آگوست",
"theme.common.month.december": "دسامبر",
"theme.common.month.february": "فوریه",
"theme.common.month.january": "ژانویه",
"theme.common.month.july": "ژوئیه",
"theme.common.month.june": "جوئن",
"theme.common.month.march": "مارس",
"theme.common.month.may": "مه",
"theme.common.month.november": "نوامبر",
"theme.common.month.october": "اکتبر",
"theme.common.month.september": "سپتامبر",
"theme.common.skipToMainContent": "رفتن به مطلب اصلی",
"theme.docs.paginator.navAriaLabel": "کنترل صفحه اسناد",
"theme.docs.paginator.next": "بعدی",
Expand Down
13 changes: 0 additions & 13 deletions packages/docusaurus-theme-classic/codeTranslations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"theme.blog.paginator.navAriaLabel": "Pagination de la liste des posts du blog",
"theme.blog.paginator.newerEntries": "Nouvelles entrées",
"theme.blog.paginator.olderEntries": "Anciennes entrées",
"theme.blog.post.date": "{day} {month} {year}",
"theme.blog.post.paginator.navAriaLabel": "Pagination des blog posts",
"theme.blog.post.paginator.newerPost": "Article plus récent",
"theme.blog.post.paginator.olderPost": "Article plus ancien",
Expand All @@ -33,18 +32,6 @@
"theme.blog.tagTitle": "{nPosts} taggés avec \"{tagName}\"",
"theme.common.editThisPage": "Éditer cette page",
"theme.common.headingLinkTitle": "Lien direct vers le titre",
"theme.common.month.april": "Avril",
"theme.common.month.august": "Août",
"theme.common.month.december": "Décembre",
"theme.common.month.february": "Février",
"theme.common.month.january": "Janvier",
"theme.common.month.july": "Juillet",
"theme.common.month.june": "Juin",
"theme.common.month.march": "Mars",
"theme.common.month.may": "Mai",
"theme.common.month.november": "Novembre",
"theme.common.month.october": "Octobre",
"theme.common.month.september": "Septembre",
"theme.common.skipToMainContent": "Aller au contenu principal",
"theme.docs.paginator.navAriaLabel": "Pagination des documents",
"theme.docs.paginator.next": "Suivant",
Expand Down
13 changes: 0 additions & 13 deletions packages/docusaurus-theme-classic/codeTranslations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"theme.blog.paginator.navAriaLabel": "ブログ記事一覧のナビゲーション",
"theme.blog.paginator.newerEntries": "新しい記事",
"theme.blog.paginator.olderEntries": "過去の記事",
"theme.blog.post.date": "{year}年{month}{day}日",
"theme.blog.post.paginator.navAriaLabel": "ブログ記事のナビゲーション",
"theme.blog.post.paginator.newerPost": "新しい記事",
"theme.blog.post.paginator.olderPost": "過去の記事",
Expand All @@ -33,18 +32,6 @@
"theme.blog.tagTitle": "「{tagName}」タグの記事が{nPosts}あります",
"theme.common.editThisPage": "このページを編集",
"theme.common.headingLinkTitle": "見出しへの直接リンク",
"theme.common.month.april": "4月",
"theme.common.month.august": "8月",
"theme.common.month.december": "12月",
"theme.common.month.february": "2月",
"theme.common.month.january": "1月",
"theme.common.month.july": "7月",
"theme.common.month.june": "6月",
"theme.common.month.march": "3月",
"theme.common.month.may": "5月",
"theme.common.month.november": "11月",
"theme.common.month.october": "10月",
"theme.common.month.september": "9月",
"theme.common.skipToMainContent": "メインコンテンツまでスキップ",
"theme.docs.paginator.navAriaLabel": "ドキュメントのナビゲーション",
"theme.docs.paginator.next": "次へ",
Expand Down
13 changes: 0 additions & 13 deletions packages/docusaurus-theme-classic/codeTranslations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"theme.blog.paginator.navAriaLabel": "Nawigacja na stronie listy wpisów na blogu",
"theme.blog.paginator.newerEntries": "Nowsze wpisy",
"theme.blog.paginator.olderEntries": "Starsze wpisy",
"theme.blog.post.date": "{day} {month} {year}",
"theme.blog.post.nPosts": "{count} posty",
"theme.blog.post.onePost": "Jeden post",
"theme.blog.post.paginator.navAriaLabel": "Nawigacja na stronie postu na blogu",
Expand All @@ -33,18 +32,6 @@
"theme.blog.tagTitle": "{nPosts} z tagiem \"{tagName}\"",
"theme.common.editThisPage": "Edytuj tą stronę",
"theme.common.headingLinkTitle": "Bezpośredni link do nagłówka",
"theme.common.month.april": "kwiecień",
"theme.common.month.august": "sierpień",
"theme.common.month.december": "grudzień",
"theme.common.month.february": "luty",
"theme.common.month.january": "styczeń",
"theme.common.month.july": "lipiec",
"theme.common.month.june": "czerwiec",
"theme.common.month.march": "marzec",
"theme.common.month.may": "maj",
"theme.common.month.november": "listopad",
"theme.common.month.october": "październik",
"theme.common.month.september": "wrzesień",
"theme.common.skipToMainContent": "Przejdź do głównej zawartości",
"theme.docs.paginator.navAriaLabel": "Nawigacja na stronie dokumentacji",
"theme.docs.paginator.next": "Następna strona",
Expand Down
13 changes: 0 additions & 13 deletions packages/docusaurus-theme-classic/codeTranslations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"theme.blog.paginator.navAriaLabel": "Навигация по странице списка блогов",
"theme.blog.paginator.newerEntries": "Следующие записи",
"theme.blog.paginator.olderEntries": "Предыдущие записи",
"theme.blog.post.date": "{month} {day}, {year}",
"theme.blog.post.paginator.navAriaLabel": "Навигация по странице поста блога",
"theme.blog.post.paginator.newerPost": "Следующий пост",
"theme.blog.post.paginator.olderPost": "Предыдущий пост",
Expand All @@ -33,18 +32,6 @@
"theme.blog.tagTitle": "{nPosts} tagged with \"{tagName}\"",
"theme.common.editThisPage": "Отредактировать эту страницу",
"theme.common.headingLinkTitle": "Прямая ссылка на этот заголовок",
"theme.common.month.april": "April",
"theme.common.month.august": "August",
"theme.common.month.december": "December",
"theme.common.month.february": "February",
"theme.common.month.january": "January",
"theme.common.month.july": "July",
"theme.common.month.june": "June",
"theme.common.month.march": "March",
"theme.common.month.may": "May",
"theme.common.month.november": "November",
"theme.common.month.october": "October",
"theme.common.month.september": "September",
"theme.common.skipToMainContent": "Перейти к основному содержимому",
"theme.docs.paginator.navAriaLabel": "Навигация по странице документации",
"theme.docs.paginator.next": "Следующая страница",
Expand Down
13 changes: 0 additions & 13 deletions packages/docusaurus-theme-classic/codeTranslations/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"theme.blog.paginator.navAriaLabel": "Blog gönderi sayfası navigasyonu",
"theme.blog.paginator.newerEntries": "Yeni Girdiler",
"theme.blog.paginator.olderEntries": "Eski Girdiler",
"theme.blog.post.date": "{day} {month} {year}",
"theme.blog.post.paginator.navAriaLabel": "Blog gönderi sayfası navigasyonu",
"theme.blog.post.paginator.newerPost": "Daha Yeni Gönderi",
"theme.blog.post.paginator.olderPost": "Daha Eski Gönderi",
Expand All @@ -33,18 +32,6 @@
"theme.blog.tagTitle": "\"{tagName}\" ile etiketlenmiş {nPosts}",
"theme.common.editThisPage": "Bu sayfayı düzenle",
"theme.common.headingLinkTitle": "Başlığa doğrudan bağlantı",
"theme.common.month.april": "Nisan",
"theme.common.month.august": "Ağustos",
"theme.common.month.december": "Aralık",
"theme.common.month.february": "Şubat",
"theme.common.month.january": "Ocak",
"theme.common.month.july": "Temmuz",
"theme.common.month.june": "Haziran",
"theme.common.month.march": "Mart",
"theme.common.month.may": "Mayıs",
"theme.common.month.november": "Kasım",
"theme.common.month.october": "Ekim",
"theme.common.month.september": "Eylül",
"theme.common.skipToMainContent": "Ana içeriğe geç",
"theme.docs.paginator.navAriaLabel": "Dokümanlar sayfası navigasyonu",
"theme.docs.paginator.next": "Sonraki",
Expand Down
Loading

0 comments on commit 3d49a04

Please sign in to comment.