import { Slug } from '@ts/types/app'; import { Article, PostBy } from '@ts/types/articles'; import { AllPostsSlug, PostsList, RawPostsList } from '@ts/types/blog'; import { AllSubjects, AllSubjectsSlug, AllThematics, AllThematicsSlug, Subject, SubjectBy, SubjectPreview, Thematic, ThematicBy, ThematicPreview, } from '@ts/types/taxonomies'; import { getFormattedPost, getFormattedPostPreview, getFormattedSubject, getFormattedThematic, } from '@utils/helpers/format'; import { gql } from 'graphql-request'; import { fetchApi } from './api'; //============================================================================== // Posts list queries //============================================================================== export const getPublishedPosts = async ({ first = 10, after = '', searchQuery = '', }: { first: number; after?: string; searchQuery?: string; }): Promise => { const query = gql` query AllPublishedPosts($first: Int, $after: String, $searchQuery: String) { posts( after: $after first: $first where: { status: PUBLISH orderby: { field: DATE, order: DESC } search: $searchQuery } ) { edges { cursor node { acfPosts { postsInSubject { ... on Subject { databaseId featuredImage { node { altText sourceUrl title } } id slug title } } postsInThematic { ... on Thematic { databaseId id slug title } } } commentCount contentParts { beforeMore } date featuredImage { node { altText sourceUrl title } } id databaseId modified slug title } } pageInfo { endCursor hasNextPage } } } `; const variables = { first, after, searchQuery }; const response = await fetchApi(query, variables); const formattedPosts = response.posts.edges.map((post) => { return getFormattedPostPreview(post.node); }); return { posts: formattedPosts, pageInfo: response.posts.pageInfo, }; }; export const getAllPostsSlug = async (): Promise => { // 10 000 is an arbitrary number that I use for small websites. const query = gql` query AllPostsSlug { posts(first: 10000) { nodes { slug } } } `; const response = await fetchApi(query, null); return response.posts.nodes; }; //============================================================================== // Single Post query //============================================================================== export const getPostBySlug = async (slug: string): Promise
=> { const query = gql` query PostBySlug($slug: String!) { postBy(slug: $slug) { acfPosts { postsInSubject { ... on Subject { id featuredImage { node { altText sourceUrl title } } slug title } } postsInThematic { ... on Thematic { id slug title } } } author { node { firstName lastName name } } commentCount comments(where: { order: ASC, orderby: COMMENT_DATE }) { nodes { approved author { node { gravatarUrl name url } } commentId content date id parentDatabaseId parentId } } contentParts { afterMore beforeMore } databaseId date featuredImage { node { altText sourceUrl title } } id modified seo { title metaDesc opengraphAuthor opengraphDescription opengraphImage { altText sourceUrl srcSet } opengraphModifiedTime opengraphPublishedTime opengraphPublisher opengraphSiteName opengraphTitle opengraphType opengraphUrl rea
(Prism.languages.chaiscript = Prism.languages.extend('clike', {
  string: {
    pattern: /(^|[^\\])'(?:[^'\\]|\\[\s\S])*'/,
    lookbehind: !0,
    greedy: !0,
  },
  'class-name': [
    { pattern: /(\bclass\s+)\w+/, lookbehind: !0 },
    { pattern: /(\b(?:attr|def)\s+)\w+(?=\s*::)/, lookbehind: !0 },
  ],
  keyword:
    /\b(?:attr|auto|break|case|catch|class|continue|def|default|else|finally|for|fun|global|if|return|switch|this|try|var|while)\b/,
  number: [Prism.languages.cpp.number, /\b(?:Infinity|NaN)\b/],
  operator:
    />>=?|<<=?|\|\||&&|:[:=]?|--|\+\+|[=!<>+\-*/%|&^]=?|[?~]|`[^`\r\n]{1,4}`/,
})),
  Prism.languages.insertBefore('chaiscript', 'operator', {
    'parameter-type': {
      pattern: /([,(]\s*)\w+(?=\s+\w)/,
      lookbehind: !0,
      alias: 'class-name',
    },
  }),
  Prism.languages.insertBefore('chaiscript', 'string', {
    'string-interpolation': {
      pattern:
        /(^|[^\\])"(?:[^"$\\]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\})*"/,
      lookbehind: !0,
      greedy: !0,
      inside: {
        interpolation: {
          pattern:
            /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\}/,
          lookbehind: !0,
          inside: {
            'interpolation-expression': {
              pattern: /(^\$\{)[\s\S]+(?=\}$)/,
              lookbehind: !0,
              inside: Prism.languages.chaiscript,
            },
            'interpolation-punctuation': {
              pattern: /^\$\{|\}$/,
              alias: 'punctuation',
            },
          },
        },
        string: /[\s\S]+/,
      },
    },
  });