blob: 776d912217b7f2252b0e83b675c660745d64eba9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
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 (
<dd key={thematic.id}>
<Link href={`/thematique/${thematic.slug}`}>
<a>{thematic.title}</a>
</Link>
</dd>
);
});
};
const getCommentsCount = () => {
switch (commentCount) {
case null:
case 0:
return t`No comments`;
case 1:
return t`1 comment`;
default:
return t`${commentCount} comments`;
}
};
return (
<dl className={styles.wrapper}>
<div>
<dt>{t`Published on`}</dt>
<dd>
{new Date(publicationDate).toLocaleDateString(locale, dateOptions)}
</dd>
</div>
{publicationDate !== updateDate && (
<div>
<dt>{t`Updated on`}</dt>
<dd>
{new Date(updateDate).toLocaleDateString(locale, dateOptions)}
</dd>
</div>
)}
{thematics.length > 0 && (
<div>
<dt>{thematics.length > 1 ? t`Thematics` : t`Thematic`}</dt>
{getThematics()}
</div>
)}
<div>
<dt>{t`Comments`}</dt>
{getCommentsCount()}
</div>
</dl>
);
};
export default PostMeta;
|