diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-13 19:29:41 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-05-13 22:35:55 +0200 |
| commit | 5f3799ee75b3ac5cffe726023d8e5df129b919dd (patch) | |
| tree | 573fddbe37e2257d67d81693ed0be5c46f049f2a /src/utils | |
| parent | 06ea295857e508a830669cb402d2156204309b1e (diff) | |
chore: add Thematic page
Diffstat (limited to 'src/utils')
| -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}` }; + }), + }; +}; |
