diff options
Diffstat (limited to 'src/utils/helpers/pages.ts')
| -rw-r--r-- | src/utils/helpers/pages.ts | 47 | 
1 files changed, 46 insertions, 1 deletions
| diff --git a/src/utils/helpers/pages.ts b/src/utils/helpers/pages.ts index d757f8c..93582f0 100644 --- a/src/utils/helpers/pages.ts +++ b/src/utils/helpers/pages.ts @@ -1,4 +1,6 @@ -import { type PageLink } from '@ts/types/app'; +import { type Post } from '@components/organisms/layout/posts-list'; +import { type LinksListItems } from '@components/organisms/widgets/links-list-widget'; +import { type Meta, type PageLink } from '@ts/types/app';  import {    type RawThematicPreview,    type RawTopicPreview, @@ -24,3 +26,46 @@ export const getPageLinkFromRawData = (      slug,    };  }; + +/** + * 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/'; + +  return links.map((link) => { +    return { +      name: link.name, +      url: `${baseUrl}${link.slug}`, +    }; +  }); +}; + +/** + * Retrieve the formatted meta. + * + * @param {Meta<'article'>} meta - The article meta. + * @returns {Post['meta']} The formatted meta. + */ +export const getPostMeta = (meta: Meta<'article'>): Post['meta'] => { +  const { commentsCount, dates, thematics, topics, wordsCount } = meta; + +  return { +    commentsCount, +    dates, +    readingTime: { wordsCount: wordsCount || 0, onlyMinutes: true }, +    thematics: thematics?.map((thematic) => { +      return { ...thematic, url: `/thematique/${thematic.slug}` }; +    }), +    topics: topics?.map((topic) => { +      return { ...topic, url: `/sujet/${topic.slug}` }; +    }), +  }; +}; | 
