summaryrefslogtreecommitdiffstats
path: root/src/pages/sujet
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-05-23 14:07:02 +0200
committerArmand Philippot <git@armandphilippot.com>2022-05-23 16:00:13 +0200
commit34e216546151eaf8a0a3cbb0bc8b65dae4c63bf2 (patch)
treebff34f8a1dc65f0559ddf851433f242edb092824 /src/pages/sujet
parent0f8f963ba3eccd7fd94785bf7fb216b6287cec57 (diff)
refactor: reduce the number of data transformation
Diffstat (limited to 'src/pages/sujet')
-rw-r--r--src/pages/sujet/[slug].tsx28
1 files changed, 3 insertions, 25 deletions
diff --git a/src/pages/sujet/[slug].tsx b/src/pages/sujet/[slug].tsx
index b4845eb..95843cd 100644
--- a/src/pages/sujet/[slug].tsx
+++ b/src/pages/sujet/[slug].tsx
@@ -1,6 +1,6 @@
import Heading from '@components/atoms/headings/heading';
import ResponsiveImage from '@components/molecules/images/responsive-image';
-import PostsList, { type Post } from '@components/organisms/layout/posts-list';
+import PostsList from '@components/organisms/layout/posts-list';
import LinksListWidget from '@components/organisms/widgets/links-list-widget';
import { getLayout } from '@components/templates/layout/layout';
import PageLayout, {
@@ -14,7 +14,6 @@ import {
} from '@services/graphql/topics';
import styles from '@styles/pages/topic.module.scss';
import {
- type Article,
type NextPageWithLayout,
type PageLink,
type Topic,
@@ -23,7 +22,7 @@ import { loadTranslation, type Messages } from '@utils/helpers/i18n';
import {
getLinksListItems,
getPageLinkFromRawData,
- getPostMeta,
+ getPostsWithUrl,
} from '@utils/helpers/pages';
import useBreadcrumb from '@utils/hooks/use-breadcrumb';
import useSettings from '@utils/hooks/use-settings';
@@ -109,27 +108,6 @@ const TopicPage: NextPageWithLayout<TopicPageProps> = ({
'@graph': [webpageSchema, articleSchema],
};
- const getPosts = (array: Article[]): Post[] => {
- return array.map((article) => {
- const {
- intro: articleIntro,
- meta: articleMeta,
- slug: articleSlug,
- ...remainingData
- } = article;
-
- const { cover: articleCover, ...remainingMeta } = articleMeta;
-
- return {
- cover: articleCover,
- excerpt: articleIntro,
- meta: getPostMeta(remainingMeta),
- url: `/article/${articleSlug}`,
- ...remainingData,
- };
- });
- };
-
const topicsListTitle = intl.formatMessage({
defaultMessage: 'Other topics',
description: 'TopicPage: other topics list widget title',
@@ -206,7 +184,7 @@ const TopicPage: NextPageWithLayout<TopicPageProps> = ({
</Heading>
<PostsList
baseUrl="/sujet/page/"
- posts={getPosts(articles)}
+ posts={getPostsWithUrl(articles)}
total={articles.length}
titleLevel={3}
byYear={true}