mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-21 13:06:58 +02:00
refactor(v2): format last updated date using Intl (#4352)
This commit is contained in:
parent
4f419801da
commit
6be0bd41b0
6 changed files with 38 additions and 13 deletions
|
@ -352,6 +352,7 @@ describe('simple site', () => {
|
|||
editUrl: 'https://github.com/customUrl/docs/lorem.md',
|
||||
description: 'Lorem ipsum.',
|
||||
lastUpdatedAt: 1539502055,
|
||||
formattedLastUpdatedAt: '10/14/2018',
|
||||
lastUpdatedBy: 'Author',
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
normalizeUrl,
|
||||
parseMarkdownString,
|
||||
posixPath,
|
||||
getDateTimeFormat,
|
||||
} from '@docusaurus/utils';
|
||||
import {LoadContext} from '@docusaurus/types';
|
||||
|
||||
|
@ -113,7 +114,7 @@ export function processDocMetadata({
|
|||
}): DocMetadataBase {
|
||||
const {source, content, lastUpdate, docsDirPath, filePath} = docFile;
|
||||
const {homePageId} = options;
|
||||
const {siteDir} = context;
|
||||
const {siteDir, i18n} = context;
|
||||
|
||||
// ex: api/myDoc -> api
|
||||
// ex: myDoc -> .
|
||||
|
@ -210,6 +211,11 @@ export function processDocMetadata({
|
|||
version: versionMetadata.versionName,
|
||||
lastUpdatedBy: lastUpdate.lastUpdatedBy,
|
||||
lastUpdatedAt: lastUpdate.lastUpdatedAt,
|
||||
formattedLastUpdatedAt: lastUpdate.lastUpdatedAt
|
||||
? getDateTimeFormat(i18n.currentLocale)(i18n.currentLocale).format(
|
||||
lastUpdate.lastUpdatedAt * 1000,
|
||||
)
|
||||
: undefined,
|
||||
sidebar_label,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -69,6 +69,7 @@ declare module '@theme/DocItem' {
|
|||
readonly permalink?: string;
|
||||
readonly editUrl?: string;
|
||||
readonly lastUpdatedAt?: number;
|
||||
readonly formattedLastUpdatedAt?: string;
|
||||
readonly lastUpdatedBy?: string;
|
||||
readonly version?: string;
|
||||
readonly previous?: {readonly permalink: string; readonly title: string};
|
||||
|
|
|
@ -128,6 +128,7 @@ export type OrderMetadata = {
|
|||
|
||||
export type LastUpdateData = {
|
||||
lastUpdatedAt?: number;
|
||||
formattedLastUpdatedAt?: string;
|
||||
lastUpdatedBy?: string;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue