import ButtonLink from '@components/atoms/buttons/button-link'; import Heading, { type HeadingLevel } from '@components/atoms/headings/heading'; import Arrow from '@components/atoms/icons/arrow'; import Link from '@components/atoms/links/link'; import ResponsiveImage, { type ResponsiveImageProps, } from '@components/molecules/images/responsive-image'; import Meta, { type MetaData } from '@components/molecules/layout/meta'; import { type Dates } from '@ts/types/app'; import useReadingTime from '@utils/hooks/use-reading-time'; import { FC, ReactNode } from 'react'; import { useIntl } from 'react-intl'; import styles from './summary.module.scss'; export type Cover = Pick< ResponsiveImageProps, 'alt' | 'src' | 'width' | 'height' >; export type SummaryMetaLink = { id: number | string; name: string; url: string; }; export type SummaryMetaReadingTime = { wordsCount: number; onlyMinutes?: boolean; }; export type SummaryMeta = { author?: string; commentsCount?: number; dates: Dates; readingTime: SummaryMetaReadingTime; thematics?: SummaryMetaLink[]; topics?: SummaryMetaLink[]; }; export type SummaryProps = { /** * The post cover. */ cover?: Cover; /** * The post excerpt. */ excerpt: string; /** * The post meta. */ meta: SummaryMeta; /** * The post title. */ title: string; /** * The heading level (hn). */ titleLevel?: HeadingLevel; /** * The post url. */ url: string; }; /** * Summary component * * Render a page summary. */ const Summary: FC = ({ cover, excerpt, meta, title, titleLevel = 2, url, }) => { const intl = useIntl(); const readMore = intl.formatMessage( { defaultMessage: 'Read more about {title}', description: 'Summary: read more link', id: 'Zpgv+f', }, { title, a11y: (chunks: ReactNode) => ( {chunks} ), } ); const { wordsCount, onlyMinutes } = meta.readingTime; const readingTime = useReadingTime(wordsCount, onlyMinutes); const getMeta = (data: SummaryMeta): MetaData => { const { author, commentsCount, dates, thematics, topics } = data; return { author, publication: { date: dates.publication }, update: dates.update && dates.publication !== dates.update ? { date: dates.update } : undefined, readingTime, thematics: thematics?.map((thematic) => ( {thematic.name} )), topics: topics?.map((topic) => ( {topic.name} )), comments: { count: commentsCount || 0, target: `${url}#comments`, }, }; }; return (
{cover && }
{title}
{typeof excerpt === 'string' ? (
) : ( excerpt )} <> {readMore}
); }; export default Summary;