aboutsummaryrefslogtreecommitdiffstats
path: root/src/services/graphql/helpers/convert-post-to-article.ts
blob: b540a7790fc62104f7fb6df9d7e8758affd3ae1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import type { Article, WPPost } from '../../../types';
import { updateContentTree } from '../../../utils/helpers';
import { convertTaxonomyToPageLink } from './convert-taxonomy-to-page-link';
import { convertWPImgToImg } from './convert-wp-image-to-img';

export const convertPostToArticle = async ({
  acfPosts,
  author,
  commentCount,
  contentParts,
  databaseId,
  date,
  featuredImage,
  info,
  modified,
  seo,
  slug,
  title,
}: WPPost): Promise<Article> => {
  return {
    content: await updateContentTree(contentParts.afterMore),
    id: databaseId,
    intro: contentParts.beforeMore,
    meta: {
      author: author.node.name,
      commentsCount: commentCount ?? 0,
      cover: featuredImage ? convertWPImgToImg(featuredImage.node) : undefined,
      dates: {
        publication: date,
        update: modified,
      },
      seo: {
        description: seo.metaDesc,
        title: seo.title,
      },
      thematics: acfPosts?.postsInThematic?.map(convertTaxonomyToPageLink),
      topics: acfPosts?.postsInTopic?.map(convertTaxonomyToPageLink),
      wordsCount: info.wordsCount,
    },
    slug,
    title,
  };
};