summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-05-23 19:32:42 +0200
committerArmand Philippot <git@armandphilippot.com>2022-05-23 20:53:58 +0200
commitc51b5d9a5f217f8aa59c4bdcb04eb3c87f5129b3 (patch)
treea4ce7f77c2b1742119eebf818d9b97db7ed1e310 /src/utils
parent5ebd7c14f7303a0feb8ec1d902ecd0e287d929c3 (diff)
fix: ensure all topics/thematics have the base url
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/helpers/pages.ts16
1 files changed, 6 insertions, 10 deletions
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,
};
});
};