From c51b5d9a5f217f8aa59c4bdcb04eb3c87f5129b3 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Mon, 23 May 2022 19:32:42 +0200 Subject: fix: ensure all topics/thematics have the base url --- src/utils/helpers/pages.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/utils') diff --git a/src/utils/helpers/pages.ts b/src/utils/helpers/pages.ts index 1a388e1..773d454 100644 --- a/src/utils/helpers/pages.ts +++ b/src/utils/helpers/pages.ts @@ -21,15 +21,17 @@ import { getImageFromRawData } from './images'; * @returns {PageLink} The link data (id, slug and title). */ export const getPageLinkFromRawData = ( - data: RawThematicPreview | RawTopicPreview + data: RawThematicPreview | RawTopicPreview, + kind: 'thematic' | 'topic' ): PageLink => { const { databaseId, featuredImage, slug, title } = data; + const baseUrl = kind === 'thematic' ? '/thematique/' : '/sujet/'; return { id: databaseId, logo: featuredImage ? getImageFromRawData(featuredImage?.node) : undefined, name: title, - slug, + url: `${baseUrl}${slug}`, }; }; @@ -37,19 +39,13 @@ export const getPageLinkFromRawData = ( * Convert page link data to an array of links items. * * @param {PageLink[]} links - An array of page links. - * @param {'thematic'|'topic'} kind - The page links kind. * @returns {LinksListItem[]} An array of links items. */ -export const getLinksListItems = ( - links: PageLink[], - kind: 'thematic' | 'topic' -): LinksListItems[] => { - const baseUrl = kind === 'thematic' ? '/thematique/' : '/sujet/'; - +export const getLinksListItems = (links: PageLink[]): LinksListItems[] => { return links.map((link) => { return { name: link.name, - url: `${baseUrl}${link.slug}`, + url: link.url, }; }); }; -- cgit v1.2.3