import type { FC, ReactNode } from 'react'; import { useIntl } from 'react-intl'; import type { Article, Meta as MetaType } from '../../../types'; import { useReadingTime } from '../../../utils/hooks'; import { ButtonLink, Heading, type HeadingLevel, Icon, Link, } from '../../atoms'; import { Meta, type MetaData, ResponsiveImage, type ResponsiveImageProps, } from '../../molecules'; import styles from './summary.module.scss'; export type Cover = Pick< ResponsiveImageProps, 'alt' | 'src' | 'width' | 'height' >; export type SummaryMeta = Pick< MetaType<'article'>, | 'author' | 'commentsCount' | 'cover' | 'dates' | 'thematics' | 'topics' | 'wordsCount' >; export type SummaryProps = Pick & { /** * The post metadata. */ meta: SummaryMeta; /** * The heading level (hn). */ titleLevel?: HeadingLevel; /** * The post url. */ url: string; }; /** * Summary component * * Render a page summary. */ export const Summary: FC = ({ intro, 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) => ( // eslint-disable-next-line react/jsx-no-literals -- SR class allowed {chunks} ), } ); const { author, commentsCount, cover, dates, thematics, topics, wordsCount } = meta; const readingTime = useReadingTime(wordsCount, true); const getMeta = (): MetaData => { return { author: author?.name, 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: { about: title, count: commentsCount ?? 0, target: `${url}#comments`, }, }; }; return (
{cover ? : null}
{title}
{/* eslint-disable-next-line react/no-danger -- Not safe but intro can * contains links or formatting so we need it. */}
<> {readMore}
); };