mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-05 12:22:45 +02:00
refactor(theme): dates should be formatted on the client-side instead of in nodejs code (#9868)
Co-authored-by: OzakIOne <OzakIOne@users.noreply.github.com> Co-authored-by: sebastien <lorber.sebastien@gmail.com>
This commit is contained in:
parent
6bf21d215c
commit
0279c329ad
15 changed files with 83 additions and 162 deletions
|
@ -52,7 +52,6 @@ exports[`simple website content 1`] = `
|
|||
"description": "Images",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {
|
||||
"id": "baz",
|
||||
"pagination_label": "baz pagination_label",
|
||||
|
@ -105,7 +104,6 @@ exports[`simple website content 2`] = `
|
|||
"description": "Hi, Endilie here :)",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {
|
||||
"id": "hello",
|
||||
"sidebar_label": "Hello sidebar_label",
|
||||
|
@ -151,7 +149,6 @@ exports[`simple website content 3`] = `
|
|||
"description": "This is custom description",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {
|
||||
"description": "This is custom description",
|
||||
"id": "bar",
|
||||
|
@ -1971,7 +1968,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
|
|||
"description": "Getting started text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {},
|
||||
"id": "getting-started",
|
||||
"lastUpdatedAt": undefined,
|
||||
|
@ -1999,7 +1995,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
|
|||
"description": "Installation text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {},
|
||||
"id": "installation",
|
||||
"lastUpdatedAt": undefined,
|
||||
|
@ -2030,7 +2025,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
|
|||
"description": "Guide 1 text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {
|
||||
"id": "guide1",
|
||||
"sidebar_position": 1,
|
||||
|
@ -2064,7 +2058,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
|
|||
"description": "Guide 2 text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {
|
||||
"id": "guide2",
|
||||
},
|
||||
|
@ -2097,7 +2090,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
|
|||
"description": "Guide 2.5 text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {
|
||||
"id": "guide2.5",
|
||||
"sidebar_position": 2.5,
|
||||
|
@ -2131,7 +2123,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
|
|||
"description": "Guide 3 text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {
|
||||
"id": "guide3",
|
||||
"sidebar_position": 3,
|
||||
|
@ -2165,7 +2156,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
|
|||
"description": "Guide 4 text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {
|
||||
"id": "guide4",
|
||||
},
|
||||
|
@ -2198,7 +2188,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
|
|||
"description": "Guide 5 text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {
|
||||
"id": "guide5",
|
||||
},
|
||||
|
@ -2231,7 +2220,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
|
|||
"description": "API Overview text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {},
|
||||
"id": "API/api-overview",
|
||||
"lastUpdatedAt": undefined,
|
||||
|
@ -2262,7 +2250,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
|
|||
"description": "Client API text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {},
|
||||
"id": "API/Core APIs/Client API",
|
||||
"lastUpdatedAt": undefined,
|
||||
|
@ -2293,7 +2280,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
|
|||
"description": "Server API text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {},
|
||||
"id": "API/Core APIs/Server API",
|
||||
"lastUpdatedAt": undefined,
|
||||
|
@ -2324,7 +2310,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
|
|||
"description": "Plugin API text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {},
|
||||
"id": "API/Extension APIs/Plugin API",
|
||||
"lastUpdatedAt": undefined,
|
||||
|
@ -2355,7 +2340,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
|
|||
"description": "Theme API text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {},
|
||||
"id": "API/Extension APIs/Theme API",
|
||||
"lastUpdatedAt": undefined,
|
||||
|
@ -2386,7 +2370,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha
|
|||
"description": "API End text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {},
|
||||
"id": "API/api-end",
|
||||
"lastUpdatedAt": undefined,
|
||||
|
@ -2566,7 +2549,6 @@ exports[`site with partial autogenerated sidebars docs in partially generated si
|
|||
"description": "API End text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {},
|
||||
"id": "API/api-end",
|
||||
"lastUpdatedAt": undefined,
|
||||
|
@ -2594,7 +2576,6 @@ exports[`site with partial autogenerated sidebars docs in partially generated si
|
|||
"description": "API Overview text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {},
|
||||
"id": "API/api-overview",
|
||||
"lastUpdatedAt": undefined,
|
||||
|
@ -2625,7 +2606,6 @@ exports[`site with partial autogenerated sidebars docs in partially generated si
|
|||
"description": "Plugin API text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {},
|
||||
"id": "API/Extension APIs/Plugin API",
|
||||
"lastUpdatedAt": undefined,
|
||||
|
@ -2656,7 +2636,6 @@ exports[`site with partial autogenerated sidebars docs in partially generated si
|
|||
"description": "Theme API text",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {},
|
||||
"id": "API/Extension APIs/Theme API",
|
||||
"lastUpdatedAt": undefined,
|
||||
|
@ -2716,7 +2695,6 @@ exports[`versioned website (community) content 1`] = `
|
|||
"description": "Team current version (translated)",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {
|
||||
"title": "Team title translated",
|
||||
},
|
||||
|
@ -2743,7 +2721,6 @@ exports[`versioned website (community) content 2`] = `
|
|||
"description": "Team 1.0.0",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {},
|
||||
"id": "team",
|
||||
"lastUpdatedAt": undefined,
|
||||
|
@ -3023,7 +3000,6 @@ exports[`versioned website content 1`] = `
|
|||
"description": "This is next version of bar.",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {
|
||||
"slug": "barSlug",
|
||||
"tags": [
|
||||
|
@ -3074,7 +3050,6 @@ exports[`versioned website content 2`] = `
|
|||
"description": "Bar 1.0.1 !",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {},
|
||||
"id": "foo/bar",
|
||||
"lastUpdatedAt": undefined,
|
||||
|
@ -3102,7 +3077,6 @@ exports[`versioned website content 3`] = `
|
|||
"description": "Hello next !",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {
|
||||
"slug": "/",
|
||||
},
|
||||
|
@ -3132,7 +3106,6 @@ exports[`versioned website content 4`] = `
|
|||
"description": "Hello 1.0.1 !",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {
|
||||
"slug": "/",
|
||||
},
|
||||
|
@ -3162,7 +3135,6 @@ exports[`versioned website content 5`] = `
|
|||
"description": "Baz 1.0.0 ! This will be deleted in next subsequent versions.",
|
||||
"draft": false,
|
||||
"editUrl": undefined,
|
||||
"formattedLastUpdatedAt": undefined,
|
||||
"frontMatter": {},
|
||||
"id": "foo/baz",
|
||||
"lastUpdatedAt": undefined,
|
||||
|
|
|
@ -475,7 +475,6 @@ describe('simple site', () => {
|
|||
unrelated_front_matter: "won't be part of metadata",
|
||||
},
|
||||
lastUpdatedAt: 1539502055,
|
||||
formattedLastUpdatedAt: 'Oct 14, 2018',
|
||||
lastUpdatedBy: 'Author',
|
||||
tags: [],
|
||||
unlisted: false,
|
||||
|
@ -573,7 +572,6 @@ describe('simple site', () => {
|
|||
title: 'Custom Last Update',
|
||||
},
|
||||
lastUpdatedAt: new Date('1/1/2000').getTime() / 1000,
|
||||
formattedLastUpdatedAt: 'Jan 1, 2000',
|
||||
lastUpdatedBy: 'Custom Author (processed by parseFrontMatter)',
|
||||
sidebarPosition: undefined,
|
||||
tags: [],
|
||||
|
@ -612,7 +610,6 @@ describe('simple site', () => {
|
|||
title: 'Last Update Author Only',
|
||||
},
|
||||
lastUpdatedAt: 1539502055,
|
||||
formattedLastUpdatedAt: 'Oct 14, 2018',
|
||||
lastUpdatedBy: 'Custom Author (processed by parseFrontMatter)',
|
||||
sidebarPosition: undefined,
|
||||
tags: [],
|
||||
|
@ -651,7 +648,6 @@ describe('simple site', () => {
|
|||
title: 'Last Update Date Only',
|
||||
},
|
||||
lastUpdatedAt: new Date('1/1/2000').getTime() / 1000,
|
||||
formattedLastUpdatedAt: 'Jan 1, 2000',
|
||||
lastUpdatedBy: 'Author',
|
||||
sidebarPosition: undefined,
|
||||
tags: [],
|
||||
|
@ -691,7 +687,6 @@ describe('simple site', () => {
|
|||
title: 'Custom Last Update',
|
||||
},
|
||||
lastUpdatedAt: undefined,
|
||||
formattedLastUpdatedAt: undefined,
|
||||
lastUpdatedBy: undefined,
|
||||
sidebarPosition: undefined,
|
||||
tags: [],
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import _ from 'lodash';
|
||||
import logger from '@docusaurus/logger';
|
||||
import {
|
||||
aliasedSitePath,
|
||||
getEditUrl,
|
||||
|
@ -142,7 +141,6 @@ async function doProcessDocMetadata({
|
|||
const {source, content, contentPath, filePath} = docFile;
|
||||
const {
|
||||
siteDir,
|
||||
i18n,
|
||||
siteConfig: {
|
||||
markdown: {parseFrontMatter},
|
||||
},
|
||||
|
@ -257,21 +255,6 @@ async function doProcessDocMetadata({
|
|||
const draft = isDraft({env, frontMatter});
|
||||
const unlisted = isUnlisted({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
|
||||
// NodeJS optimization.
|
||||
// Adding properties to object after instantiation will cause hidden
|
||||
|
@ -291,13 +274,6 @@ async function doProcessDocMetadata({
|
|||
version: versionMetadata.versionName,
|
||||
lastUpdatedBy: lastUpdate.lastUpdatedBy,
|
||||
lastUpdatedAt: lastUpdate.lastUpdatedAt,
|
||||
formattedLastUpdatedAt: lastUpdate.lastUpdatedAt
|
||||
? formatDate(
|
||||
i18n.currentLocale,
|
||||
new Date(lastUpdate.lastUpdatedAt * 1000),
|
||||
i18n.localeConfigs[i18n.currentLocale]!.calendar,
|
||||
)
|
||||
: undefined,
|
||||
sidebarPosition,
|
||||
frontMatter,
|
||||
};
|
||||
|
|
|
@ -407,8 +407,6 @@ declare module '@docusaurus/plugin-content-docs' {
|
|||
export type LastUpdateData = {
|
||||
/** A timestamp in **seconds**, directly acquired from `git log`. */
|
||||
lastUpdatedAt?: number;
|
||||
/** `lastUpdatedAt` formatted as a date according to the current locale. */
|
||||
formattedLastUpdatedAt?: string;
|
||||
/** The author's name directly acquired from `git log`. */
|
||||
lastUpdatedBy?: string;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue