From f6e0e444820f67f212e362c54816df5d0e4d4cf0 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 25 Jan 2022 15:53:43 +0100 Subject: chore: wrap dates with time tag --- src/components/PostMeta/PostMeta.tsx | 61 +++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 28 deletions(-) (limited to 'src/components/PostMeta/PostMeta.tsx') diff --git a/src/components/PostMeta/PostMeta.tsx b/src/components/PostMeta/PostMeta.tsx index 45f919a..f95707a 100644 --- a/src/components/PostMeta/PostMeta.tsx +++ b/src/components/PostMeta/PostMeta.tsx @@ -1,5 +1,7 @@ +import { config } from '@config/website'; import { plural, t } from '@lingui/macro'; import { ArticleMeta } from '@ts/types/articles'; +import { getFormattedDate } from '@utils/helpers/format'; import Link from 'next/link'; import { useRouter } from 'next/router'; import styles from './PostMeta.module.scss'; @@ -24,15 +26,10 @@ const PostMeta = ({ website, wordsCount, } = meta; - const { asPath, locale } = useRouter(); - const isThematic = () => asPath.includes('/thematique/'); - const isArticle = () => asPath.includes('/article/'); - - const dateOptions: Intl.DateTimeFormatOptions = { - day: 'numeric', - month: 'long', - year: 'numeric', - }; + const router = useRouter(); + const locale = router.locale ? router.locale : config.locales.defaultLocale; + const isThematic = () => router.asPath.includes('/thematique/'); + const isArticle = () => router.asPath.includes('/article/'); const getTopics = () => { return ( @@ -85,6 +82,32 @@ const PostMeta = ({ }); }; + const getDates = () => { + if (!dates) return <>; + + const publicationDate = getFormattedDate(dates.publication, locale); + const updateDate = getFormattedDate(dates.update, locale); + + return ( + <> +
+
{t`Published on:`}
+
+ +
+
+ {publicationDate !== updateDate && ( +
+
{t`Updated on:`}
+
+ +
+
+ )} + + ); + }; + const wrapperClass = styles[`wrapper--${mode}`]; return ( @@ -95,25 +118,7 @@ const PostMeta = ({
{author.name}
)} - {dates && ( -
-
{t`Published on:`}
-
- {new Date(dates.publication).toLocaleDateString( - locale, - dateOptions - )} -
-
- )} - {dates && dates.publication !== dates.update && ( -
-
{t`Updated on:`}
-
- {new Date(dates.update).toLocaleDateString(locale, dateOptions)} -
-
- )} + {getDates()} {readingTime !== undefined && wordsCount !== undefined && (
{t`Reading time:`}
-- cgit v1.2.3