diff options
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/PostFooter/PostFooter.module.scss | 5 | ||||
| -rw-r--r-- | src/components/PostFooter/PostFooter.tsx | 35 | ||||
| -rw-r--r-- | src/components/PostHeader/PostHeader.module.scss | 7 | ||||
| -rw-r--r-- | src/components/PostHeader/PostHeader.tsx | 72 |
4 files changed, 119 insertions, 0 deletions
diff --git a/src/components/PostFooter/PostFooter.module.scss b/src/components/PostFooter/PostFooter.module.scss new file mode 100644 index 0000000..e80f5ed --- /dev/null +++ b/src/components/PostFooter/PostFooter.module.scss @@ -0,0 +1,5 @@ +@use "@styles/abstracts/placeholders"; + +.list { + @extend %flex-list; +} diff --git a/src/components/PostFooter/PostFooter.tsx b/src/components/PostFooter/PostFooter.tsx new file mode 100644 index 0000000..8c09d69 --- /dev/null +++ b/src/components/PostFooter/PostFooter.tsx @@ -0,0 +1,35 @@ +import { t } from '@lingui/macro'; +import { SubjectPreview } from '@ts/types/taxonomies'; +import Link from 'next/link'; +import styles from './PostFooter.module.scss'; + +const PostFooter = ({ subjects }: { subjects: SubjectPreview[] }) => { + const getSubjects = () => { + return subjects.map((subject) => { + return ( + <li key={subject.id}> + <Link href={`/sujet/${subject.slug}`}> + <a>{subject.title}</a> + </Link> + </li> + ); + }); + }; + + return ( + <footer> + {subjects.length > 0 && ( + <> + <dl className={styles.meta}> + <dt>{t`Subjects:`}</dt> + <dd> + <ul className={styles.list}>{getSubjects()}</ul> + </dd> + </dl> + </> + )} + </footer> + ); +}; + +export default PostFooter; diff --git a/src/components/PostHeader/PostHeader.module.scss b/src/components/PostHeader/PostHeader.module.scss new file mode 100644 index 0000000..f013651 --- /dev/null +++ b/src/components/PostHeader/PostHeader.module.scss @@ -0,0 +1,7 @@ +.meta { + font-size: var(--font-size-sm); +} + +.label { + font-weight: inherit; +} diff --git a/src/components/PostHeader/PostHeader.tsx b/src/components/PostHeader/PostHeader.tsx new file mode 100644 index 0000000..5c5aff4 --- /dev/null +++ b/src/components/PostHeader/PostHeader.tsx @@ -0,0 +1,72 @@ +import { t } from '@lingui/macro'; +import { ArticleAuthor, ArticleDates } from '@ts/types/articles'; +import { ThematicPreview } from '@ts/types/taxonomies'; +import Link from 'next/link'; +import { useRouter } from 'next/router'; +import styles from './PostHeader.module.scss'; + +const PostHeader = ({ + author, + date, + intro, + title, + thematics, +}: { + author: ArticleAuthor; + date: ArticleDates; + intro: string; + title: string; + thematics: ThematicPreview[]; +}) => { + const { locale } = useRouter(); + + const getAuthor = () => { + return author.firstName + ? `${author.firstName} ${author.lastName}` + : author.name; + }; + + const getLocaleDate = (date: string) => { + const dateOptions: Intl.DateTimeFormatOptions = { + day: 'numeric', + month: 'long', + year: 'numeric', + }; + return new Date(date).toLocaleDateString(locale, dateOptions); + }; + + const getThematics = () => { + return thematics.map((thematic) => { + return ( + <dd key={thematic.id}> + <Link href={`/thematique/${thematic.slug}`}> + <a>{thematic.title}</a> + </Link> + </dd> + ); + }); + }; + + return ( + <header> + <h1>{title}</h1> + <ul className={styles.meta}> + <li>{t`Written by ${getAuthor()} on ${getLocaleDate( + date.publication + )}.`}</li> + <li>{t`Last update on ${getLocaleDate(date.update)}.`}</li> + {thematics.length > 0 && ( + <li> + <dl> + <dt className={styles.label}>{t`Posted in:`}</dt> + {getThematics()} + </dl> + </li> + )} + </ul> + <div dangerouslySetInnerHTML={{ __html: intro }}></div> + </header> + ); +}; + +export default PostHeader; |
