summaryrefslogtreecommitdiffstats
path: root/src/components/organisms/layout/summary.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/organisms/layout/summary.tsx')
-rw-r--r--src/components/organisms/layout/summary.tsx73
1 files changed, 23 insertions, 50 deletions
diff --git a/src/components/organisms/layout/summary.tsx b/src/components/organisms/layout/summary.tsx
index 3831c0c..ca51cd6 100644
--- a/src/components/organisms/layout/summary.tsx
+++ b/src/components/organisms/layout/summary.tsx
@@ -6,7 +6,7 @@ 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 { type Article, type Meta as MetaType } from '@ts/types/app';
import useReadingTime from '@utils/hooks/use-reading-time';
import { FC, ReactNode } from 'react';
import { useIntl } from 'react-intl';
@@ -17,44 +17,23 @@ export type Cover = Pick<
'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 SummaryMeta = Pick<
+ MetaType<'article'>,
+ | 'author'
+ | 'commentsCount'
+ | 'cover'
+ | 'dates'
+ | 'thematics'
+ | 'topics'
+ | 'wordsCount'
+>;
-export type SummaryProps = {
+export type SummaryProps = Pick<Article, 'intro' | 'title'> & {
/**
- * The post cover.
- */
- cover?: Cover;
- /**
- * The post excerpt.
- */
- excerpt: string;
- /**
- * The post meta.
+ * The post metadata.
*/
meta: SummaryMeta;
/**
- * The post title.
- */
- title: string;
- /**
* The heading level (hn).
*/
titleLevel?: HeadingLevel;
@@ -70,8 +49,7 @@ export type SummaryProps = {
* Render a page summary.
*/
const Summary: FC<SummaryProps> = ({
- cover,
- excerpt,
+ intro,
meta,
title,
titleLevel = 2,
@@ -91,14 +69,13 @@ const Summary: FC<SummaryProps> = ({
),
}
);
- const { wordsCount, onlyMinutes } = meta.readingTime;
- const readingTime = useReadingTime(wordsCount, onlyMinutes);
-
- const getMeta = (data: SummaryMeta): MetaData => {
- const { author, commentsCount, dates, thematics, topics } = data;
+ const { author, commentsCount, cover, dates, thematics, topics, wordsCount } =
+ meta;
+ const readingTime = useReadingTime(wordsCount, true);
+ const getMeta = (): MetaData => {
return {
- author,
+ author: author?.name,
publication: { date: dates.publication },
update:
dates.update && dates.publication !== dates.update
@@ -106,12 +83,12 @@ const Summary: FC<SummaryProps> = ({
: undefined,
readingTime,
thematics: thematics?.map((thematic) => (
- <Link key={thematic.id} href={thematic.url}>
+ <Link key={thematic.id} href={thematic.slug}>
{thematic.name}
</Link>
)),
topics: topics?.map((topic) => (
- <Link key={topic.id} href={topic.url}>
+ <Link key={topic.id} href={topic.slug}>
{topic.name}
</Link>
)),
@@ -134,11 +111,7 @@ const Summary: FC<SummaryProps> = ({
</Link>
</header>
<div className={styles.body}>
- {typeof excerpt === 'string' ? (
- <div dangerouslySetInnerHTML={{ __html: excerpt }} />
- ) : (
- excerpt
- )}
+ <div dangerouslySetInnerHTML={{ __html: intro }} />
<ButtonLink target={url} className={styles['read-more']}>
<>
{readMore}
@@ -148,7 +121,7 @@ const Summary: FC<SummaryProps> = ({
</div>
<footer className={styles.footer}>
<Meta
- data={getMeta(meta)}
+ data={getMeta()}
layout="column"
itemsLayout="stacked"
withSeparator={false}