aboutsummaryrefslogtreecommitdiffstats
path: root/public/prism/prism-n4js.min.js
blob: a1af08cb32f9905f37fab3a62dc4113a0dfa8e98 (plain)
1
2
3
4
5
6
7
8
(Prism.languages.n4js = Prism.languages.extend('javascript', {
  keyword:
    /\b(?:Array|any|boolean|break|case|catch|class|const|constructor|continue|debugger|declare|default|delete|do|else|enum|export|extends|false|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|module|new|null|number|package|private|protected|public|return|set|static|string|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)\b/,
})),
  Prism.languages.insertBefore('n4js', 'constant', {
    annotation: { pattern: /@+\w+/, alias: 'operator' },
  }),
  (Prism.languages.n4jsd = Prism.languages.n4js);
itespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
import {
  type EdgesResponse,
  type GraphQLEdgesInput,
  type PageLink,
  type RawArticle,
  type RawThematic,
  type RawThematicPreview,
  type Slug,
  type Thematic,
  type TotalItems,
} from '../../types';
import {
  getImageFromRawData,
  getPageLinkFromRawData,
  sortPageLinksByName,
} from '../../utils/helpers';
import { fetchAPI } from './api';
import { getArticleFromRawData } from './articles';
import {
  thematicBySlugQuery,
  thematicsListQuery,
  thematicsSlugQuery,
  totalThematicsQuery,
} from './thematics.query';

/**
 * Retrieve the total number of thematics.
 *
 * @returns {Promise<number>} - The thematics total number.
 */
export const getTotalThematics = async (): Promise<number> => {
  const response = await fetchAPI<TotalItems, typeof totalThematicsQuery>({
    query: totalThematicsQuery,
  });

  return response.thematics.pageInfo.total;
};

/**
 * Retrieve the given number of thematics from API.
 *
 * @param {GraphQLEdgesInput} props - An object of GraphQL variables.
 * @returns {Promise<EdgesResponse<RawThematicPreview>>} The thematics data.
 */
export const getThematicsPreview = async (
  props: GraphQLEdgesInput
): Promise<EdgesResponse<RawThematicPreview>> => {
  const response = await fetchAPI<
    RawThematicPreview,
    typeof thematicsListQuery
  >({ query: thematicsListQuery, variables: props });

  return response.thematics;
};

/**
 * Convert raw data to an Thematic object.
 *
 * @param {RawThematic} data - The page raw data.
 * @returns {Thematic} The page data.
 */
export const getThematicFromRawData = (data: RawThematic): Thematic => {
  const {
    acfThematics,
    contentParts,
    databaseId,
    date,
    featuredImage,
    info,
    modified,
    slug,
    title,
    seo,
  } = data;

  /**
   * Retrieve an array of related topics.
   *
   * @param posts - The thematic posts.
   * @returns {PageLink[]} An array of topics links.
   */
  const getRelatedTopics = (posts: RawArticle[]): PageLink[] => {
    const topics: PageLink[] = [];

    posts.forEach((post) => {
      if (post.acfPosts.postsInTopic) {
        post.acfPosts.postsInTopic.forEach((topic) =>
          topics.push(getPageLinkFromRawData(topic, 'topic'))
        );
      }
    });

    const topicsIds = topics.map((topic) => topic.id);
    const uniqueTopics = topics.filter(
      ({ id }, index) => !topicsIds.includes(id, index + 1)
    );

    return uniqueTopics.sort(sortPageLinksByName);
  };

  return {
    content: contentParts.afterMore,
    id: databaseId,
    intro: contentParts.beforeMore,
    meta: {
      articles: acfThematics.postsInThematic.map((post) =>
        getArticleFromRawData(post)
      ),
      cover: featuredImage?.node
        ? getImageFromRawData(featuredImage.node)
        : undefined,
      dates: { publication: date, update: modified },
      seo: {
        description: seo?.metaDesc || '',
        title: seo?.title || '',
      },
      topics: getRelatedTopics(acfThematics.postsInThematic),
      wordsCount: info.wordsCount,
    },
    slug,
    title,
  };
};

/**
 * Retrieve a Thematic object by slug.
 *
 * @param {string} slug - The thematic slug.
 * @returns {Promise<Article>} The requested thematic.
 */
export const getThematicBySlug = async (slug: string): Promise<Thematic> => {
  const response = await fetchAPI<RawThematic, typeof thematicBySlugQuery>({
    query: thematicBySlugQuery,
    variables: { slug },
  });

  return getThematicFromRawData(response.thematic);
};

/**
 * Retrieve all the thematics slugs.
 *
 * @returns {Promise<string[]>} - An array of thematics slugs.
 */
export const getAllThematicsSlugs = async (): Promise<string[]> => {
  const totalThematics = await getTotalThematics();
  const response = await fetchAPI<Slug, typeof thematicsSlugQuery>({
    query: thematicsSlugQuery,
    variables: { first: totalThematics },
  });

  return response.thematics.edges.map((edge) => edge.node.slug);
};