aboutsummaryrefslogtreecommitdiffstats
path: root/src/services/graphql/helpers/convert-taxonomy-to-page-link.ts
blob: ca86a1eed1bababd88f5ec38def0db2a01f8f83a (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
import type {
  PageLink,
  WPThematicPreview,
  WPTopicPreview,
} from '../../../types';
import { ROUTES } from '../../../utils/constants';
import { convertWPImgToImg } from './convert-wp-image-to-img';

const convertTaxonomyToPageLink = ({
  databaseId,
  slug,
  title,
  ...props
}: WPThematicPreview | WPTopicPreview): PageLink => {
  return {
    id: databaseId,
    logo:
      'featuredImage' in props && props.featuredImage
        ? convertWPImgToImg(props.featuredImage.node)
        : undefined,
    name: title,
    url: slug,
  };
};

export const convertWPThematicPreviewToPageLink = (
  thematic: WPThematicPreview
): PageLink =>
  convertTaxonomyToPageLink({
    ...thematic,
    slug: `${ROUTES.THEMATICS}/${thematic.slug}`,
  });

export const convertWPTopicPreviewToPageLink = (
  topic: WPTopicPreview
): PageLink =>
  convertTaxonomyToPageLink({
    ...topic,
    slug: `${ROUTES.TOPICS}/${topic.slug}`,
  });