diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-01-03 12:24:04 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-01-03 12:24:04 +0100 |
| commit | 04a1ceb257311a98fffc4b18679f73789b920e09 (patch) | |
| tree | 96bccf0152fcc2c3c49762ded83eaf0e57993bf0 /src/utils | |
| parent | a98b5ea6fe8e8cc98a55e0fd793e6e8660ea31c1 (diff) | |
chore: display subjects list under articles
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/helpers/format.ts | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/utils/helpers/format.ts b/src/utils/helpers/format.ts index 81bae9c..94aa2e7 100644 --- a/src/utils/helpers/format.ts +++ b/src/utils/helpers/format.ts @@ -7,8 +7,10 @@ import { import { Comment, RawComment } from '@ts/types/comments'; import { RawSubject, + RawSubjectPreview, RawThematic, Subject, + SubjectPreview, Thematic, } from '@ts/types/taxonomies'; @@ -185,6 +187,19 @@ export const buildCommentsTree = (comments: Comment[]) => { return commentsTree; }; +export const getFormattedSubjectsPreview = ( + subjects: RawSubjectPreview[] +): SubjectPreview[] => { + const formattedSubjects: SubjectPreview[] = subjects.map((subject) => { + return { + ...subject, + featuredImage: subject.featuredImage ? subject.featuredImage.node : null, + }; + }); + + return formattedSubjects; +}; + /** * Format an article from RawArticle to Article type. * @param rawPost - An article coming from WP GraphQL. @@ -212,6 +227,9 @@ export const getFormattedPost = (rawPost: RawArticle): Article => { const formattedComments = getFormattedComments(comments.nodes); const commentsTree = buildCommentsTree(formattedComments); + const subjects = acfPosts.postsInSubject + ? getFormattedSubjectsPreview(acfPosts.postsInSubject) + : []; const formattedPost: Article = { author: author.node, @@ -223,7 +241,7 @@ export const getFormattedPost = (rawPost: RawArticle): Article => { id, intro: contentParts.beforeMore, seo, - subjects: acfPosts.postsInSubject ? acfPosts.postsInSubject : [], + subjects, thematics: acfPosts.postsInThematic ? acfPosts.postsInThematic : [], title, }; |
