mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-04 01:09:20 +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
|
@ -33,7 +33,14 @@ function DocItem(props: Props): JSX.Element {
|
|||
hide_table_of_contents: hideTableOfContents,
|
||||
},
|
||||
} = DocContent;
|
||||
const {description, title, editUrl, lastUpdatedAt, lastUpdatedBy} = metadata;
|
||||
const {
|
||||
description,
|
||||
title,
|
||||
editUrl,
|
||||
lastUpdatedAt,
|
||||
formattedLastUpdatedAt,
|
||||
lastUpdatedBy,
|
||||
} = metadata;
|
||||
|
||||
const {pluginId} = useActivePlugin({failfast: true});
|
||||
const versions = useVersions(pluginId);
|
||||
|
@ -81,6 +88,7 @@ function DocItem(props: Props): JSX.Element {
|
|||
{(lastUpdatedAt || lastUpdatedBy) && (
|
||||
<LastUpdated
|
||||
lastUpdatedAt={lastUpdatedAt}
|
||||
formattedLastUpdatedAt={formattedLastUpdatedAt}
|
||||
lastUpdatedBy={lastUpdatedBy}
|
||||
/>
|
||||
)}
|
||||
|
|
|
@ -9,21 +9,23 @@ import React from 'react';
|
|||
import styles from './styles.module.css';
|
||||
import Translate from '@docusaurus/Translate';
|
||||
|
||||
function LastUpdatedAtDate({lastUpdatedAt}: {lastUpdatedAt: number}) {
|
||||
function LastUpdatedAtDate({
|
||||
lastUpdatedAt,
|
||||
formattedLastUpdatedAt,
|
||||
}: {
|
||||
lastUpdatedAt: number;
|
||||
formattedLastUpdatedAt: string;
|
||||
}) {
|
||||
return (
|
||||
<Translate
|
||||
id="theme.lastUpdated.atDate"
|
||||
description="The words used to describe on which date a page has been last updated"
|
||||
values={{
|
||||
// TODO localize this date
|
||||
// If it's the only place we need this, we'd rather keep it simple
|
||||
// Day.js may be a good lightweight option?
|
||||
// https://www.skypack.dev/blog/2021/02/the-best-javascript-date-libraries/
|
||||
date: (
|
||||
<time
|
||||
dateTime={new Date(lastUpdatedAt * 1000).toISOString()}
|
||||
className={styles.lastUpdatedDate}>
|
||||
{new Date(lastUpdatedAt * 1000).toLocaleDateString()}
|
||||
{formattedLastUpdatedAt}
|
||||
</time>
|
||||
),
|
||||
}}>
|
||||
|
@ -47,9 +49,11 @@ function LastUpdatedByUser({lastUpdatedBy}: {lastUpdatedBy: string}) {
|
|||
|
||||
export default function LastUpdated({
|
||||
lastUpdatedAt,
|
||||
formattedLastUpdatedAt,
|
||||
lastUpdatedBy,
|
||||
}: {
|
||||
lastUpdatedAt: number | undefined;
|
||||
formattedLastUpdatedAt: string | undefined;
|
||||
lastUpdatedBy: string | undefined;
|
||||
}) {
|
||||
return (
|
||||
|
@ -60,11 +64,15 @@ export default function LastUpdated({
|
|||
id="theme.lastUpdated.lastUpdatedAtBy"
|
||||
description="The sentence used to display when a page has been last updated, and by who"
|
||||
values={{
|
||||
atDate: lastUpdatedAt ? (
|
||||
<LastUpdatedAtDate lastUpdatedAt={lastUpdatedAt} />
|
||||
) : (
|
||||
''
|
||||
),
|
||||
atDate:
|
||||
lastUpdatedAt && formattedLastUpdatedAt ? (
|
||||
<LastUpdatedAtDate
|
||||
lastUpdatedAt={lastUpdatedAt}
|
||||
formattedLastUpdatedAt={formattedLastUpdatedAt}
|
||||
/>
|
||||
) : (
|
||||
''
|
||||
),
|
||||
byUser: lastUpdatedBy ? (
|
||||
<LastUpdatedByUser lastUpdatedBy={lastUpdatedBy} />
|
||||
) : (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue