From 97dc68e22e754d8e478beee590dbe9868171af50 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 25 Jan 2022 15:33:27 +0100 Subject: chore: add reading time in posts meta --- src/components/PostMeta/PostMeta.tsx | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src/components/PostMeta/PostMeta.tsx') diff --git a/src/components/PostMeta/PostMeta.tsx b/src/components/PostMeta/PostMeta.tsx index 9aa67c7..45f919a 100644 --- a/src/components/PostMeta/PostMeta.tsx +++ b/src/components/PostMeta/PostMeta.tsx @@ -13,8 +13,17 @@ const PostMeta = ({ meta: ArticleMeta; mode?: PostMetaMode; }) => { - const { author, commentCount, dates, results, thematics, topics, website } = - meta; + const { + author, + commentCount, + dates, + readingTime, + results, + thematics, + topics, + website, + wordsCount, + } = meta; const { asPath, locale } = useRouter(); const isThematic = () => asPath.includes('/thematique/'); const isArticle = () => asPath.includes('/article/'); @@ -66,6 +75,16 @@ const PostMeta = ({ } }; + const getReadingTime = () => { + if (!readingTime) return; + if (readingTime < 0) return t`less than 1 minute`; + return plural(readingTime, { + zero: '# minutes', + one: '# minute', + other: '# minutes', + }); + }; + const wrapperClass = styles[`wrapper--${mode}`]; return ( @@ -95,6 +114,17 @@ const PostMeta = ({ )} + {readingTime !== undefined && wordsCount !== undefined && ( +
+
{t`Reading time:`}
+
+ {getReadingTime()} +
+
+ )} {results && (
{t`Total: `}
-- cgit v1.2.3