import { t } from '@lingui/macro'; import { ThematicPreview } from '@ts/types/taxonomies'; import Link from 'next/link'; import { useRouter } from 'next/router'; import styles from './PostMeta.module.scss'; const PostMeta = ({ commentCount, publicationDate, updateDate, thematics, }: { commentCount: number | null; publicationDate: string; updateDate: string; thematics: ThematicPreview[]; }) => { const { locale } = useRouter(); const dateOptions: Intl.DateTimeFormatOptions = { day: 'numeric', month: 'long', year: 'numeric', }; const getThematics = () => { return thematics.map((thematic) => { return (
{thematic.title}
); }); }; const getCommentsCount = () => { switch (commentCount) { case null: case 0: return t`No comments`; case 1: return t`1 comment`; default: return t`${commentCount} comments`; } }; return (
{t`Published on`}
{new Date(publicationDate).toLocaleDateString(locale, dateOptions)}
{publicationDate !== updateDate && (
{t`Updated on`}
{new Date(updateDate).toLocaleDateString(locale, dateOptions)}
)} {thematics.length > 0 && (
{thematics.length > 1 ? t`Thematics` : t`Thematic`}
{getThematics()}
)}
{t`Comments`}
{getCommentsCount()}
); }; export default PostMeta;