diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/PostFooter/PostFooter.tsx | 25 | ||||
| -rw-r--r-- | src/components/PostMeta/PostMeta.tsx | 20 | ||||
| -rw-r--r-- | src/components/PostPreview/PostPreview.tsx | 2 | ||||
| -rw-r--r-- | src/components/Widgets/RelatedTopics/RelatedTopics.tsx | 18 | ||||
| -rw-r--r-- | src/components/Widgets/TopicsList/TopicsList.tsx | 16 | ||||
| -rw-r--r-- | src/pages/article/[slug].tsx | 4 | ||||
| -rw-r--r-- | src/pages/projet/[slug].tsx | 2 | ||||
| -rw-r--r-- | src/pages/sujet/[slug].tsx | 84 | ||||
| -rw-r--r-- | src/pages/thematique/[slug].tsx | 22 | ||||
| -rw-r--r-- | src/services/graphql/queries.ts | 64 | ||||
| -rw-r--r-- | src/ts/types/app.ts | 16 | ||||
| -rw-r--r-- | src/ts/types/articles.ts | 16 | ||||
| -rw-r--r-- | src/ts/types/taxonomies.ts | 32 | ||||
| -rw-r--r-- | src/utils/helpers/format.ts | 52 | 
14 files changed, 181 insertions, 192 deletions
| diff --git a/src/components/PostFooter/PostFooter.tsx b/src/components/PostFooter/PostFooter.tsx index 06e86bc..ad471eb 100644 --- a/src/components/PostFooter/PostFooter.tsx +++ b/src/components/PostFooter/PostFooter.tsx @@ -1,26 +1,25 @@  import { ButtonLink } from '@components/Buttons';  import { t } from '@lingui/macro'; -import { SubjectPreview } from '@ts/types/taxonomies'; +import { TopicPreview } from '@ts/types/taxonomies';  import Image from 'next/image'; -import Link from 'next/link';  import styles from './PostFooter.module.scss'; -const PostFooter = ({ subjects }: { subjects: SubjectPreview[] }) => { -  const getSubjects = () => { -    return subjects.map((subject) => { +const PostFooter = ({ topics }: { topics: TopicPreview[] }) => { +  const getTopics = () => { +    return topics.map((topic) => {        return ( -        <li className={styles.item} key={subject.id}> -          <ButtonLink target={`/sujet/${subject.slug}`}> -            {subject.featuredImage && ( +        <li className={styles.item} key={topic.id}> +          <ButtonLink target={`/sujet/${topic.slug}`}> +            {topic.featuredImage && (                <Image -                src={subject.featuredImage.sourceUrl} -                alt={subject.featuredImage.altText} +                src={topic.featuredImage.sourceUrl} +                alt={topic.featuredImage.altText}                  layout="intrinsic"                  width="20"                  height="20"                />              )} -            {subject.title} +            {topic.title}            </ButtonLink>          </li>        ); @@ -29,12 +28,12 @@ const PostFooter = ({ subjects }: { subjects: SubjectPreview[] }) => {    return (      <footer> -      {subjects.length > 0 && ( +      {topics.length > 0 && (          <>            <dl className={styles.meta}>              <dt>{t`Read more articles about:`}</dt>              <dd> -              <ul className={styles.list}>{getSubjects()}</ul> +              <ul className={styles.list}>{getTopics()}</ul>              </dd>            </dl>          </> diff --git a/src/components/PostMeta/PostMeta.tsx b/src/components/PostMeta/PostMeta.tsx index 0b68d70..57c2ded 100644 --- a/src/components/PostMeta/PostMeta.tsx +++ b/src/components/PostMeta/PostMeta.tsx @@ -13,7 +13,7 @@ const PostMeta = ({    meta: ArticleMeta;    mode?: PostMetaMode;  }) => { -  const { author, commentCount, dates, subjects, thematics, website } = meta; +  const { author, commentCount, dates, topics, thematics, website } = meta;    const { asPath, locale } = useRouter();    const isThematic = () => asPath.includes('/thematique/');    const isArticle = () => asPath.includes('/article/'); @@ -24,14 +24,14 @@ const PostMeta = ({      year: 'numeric',    }; -  const getSubjects = () => { +  const getTopics = () => {      return ( -      subjects && -      subjects.map((subject) => { +      topics && +      topics.map((topic) => {          return ( -          <dd key={subject.id} className={styles.description}> -            <Link href={`/sujet/${subject.slug}`}> -              <a>{subject.title}</a> +          <dd key={topic.id} className={styles.description}> +            <Link href={`/sujet/${topic.slug}`}> +              <a>{topic.title}</a>              </Link>            </dd>          ); @@ -102,12 +102,12 @@ const PostMeta = ({            {getThematics()}          </div>        )} -      {isThematic() && subjects && subjects.length > 0 && ( +      {isThematic() && topics && topics.length > 0 && (          <div className={styles.item}>            <dt className={styles.term}> -            {subjects.length > 1 ? t`Subjects` : t`Subject`} +            {topics.length > 1 ? t`Topics` : t`Topic`}            </dt> -          {getSubjects()} +          {getTopics()}          </div>        )}        {website && ( diff --git a/src/components/PostPreview/PostPreview.tsx b/src/components/PostPreview/PostPreview.tsx index 47dbe5e..b52d675 100644 --- a/src/components/PostPreview/PostPreview.tsx +++ b/src/components/PostPreview/PostPreview.tsx @@ -23,7 +23,7 @@ const PostPreview = ({    const meta: ArticleMeta = {      commentCount: post.commentCount ? post.commentCount : 0,      dates: post.dates, -    subjects: post.subjects, +    topics: post.topics,      thematics: post.thematics,    }; diff --git a/src/components/Widgets/RelatedTopics/RelatedTopics.tsx b/src/components/Widgets/RelatedTopics/RelatedTopics.tsx index aab8cc1..178e5bc 100644 --- a/src/components/Widgets/RelatedTopics/RelatedTopics.tsx +++ b/src/components/Widgets/RelatedTopics/RelatedTopics.tsx @@ -1,18 +1,18 @@  import { ExpandableWidget, List } from '@components/WidgetParts';  import { t } from '@lingui/macro'; -import { SubjectPreview } from '@ts/types/taxonomies'; +import { TopicPreview } from '@ts/types/taxonomies';  import Link from 'next/link'; -const RelatedTopics = ({ topics }: { topics: SubjectPreview[] }) => { -  const sortedSubjects = [...topics].sort((a, b) => +const RelatedTopics = ({ topics }: { topics: TopicPreview[] }) => { +  const sortedTopics = [...topics].sort((a, b) =>      a.title.localeCompare(b.title)    ); -  const subjects = sortedSubjects.map((subject) => { +  const topicsList = sortedTopics.map((topic) => {      return ( -      <li key={subject.databaseId}> -        <Link href={`/sujet/${subject.slug}`}> -          <a>{subject.title}</a> +      <li key={topic.databaseId}> +        <Link href={`/sujet/${topic.slug}`}> +          <a>{topic.title}</a>          </Link>        </li>      ); @@ -20,10 +20,10 @@ const RelatedTopics = ({ topics }: { topics: SubjectPreview[] }) => {    return (      <ExpandableWidget -      title={topics.length > 1 ? t`Related topics` : t`Related topic`} +      title={topicsList.length > 1 ? t`Related topics` : t`Related topic`}        withBorders={true}      > -      <List items={subjects} /> +      <List items={topicsList} />      </ExpandableWidget>    );  }; diff --git a/src/components/Widgets/TopicsList/TopicsList.tsx b/src/components/Widgets/TopicsList/TopicsList.tsx index c7843b7..5b0c44e 100644 --- a/src/components/Widgets/TopicsList/TopicsList.tsx +++ b/src/components/Widgets/TopicsList/TopicsList.tsx @@ -1,7 +1,7 @@  import Spinner from '@components/Spinner/Spinner';  import { ExpandableWidget, List } from '@components/WidgetParts';  import { t } from '@lingui/macro'; -import { getAllSubjects } from '@services/graphql/queries'; +import { getAllTopics } from '@services/graphql/queries';  import { TitleLevel } from '@ts/types/app';  import Link from 'next/link';  import { useRouter } from 'next/router'; @@ -20,7 +20,7 @@ const TopicsList = ({      ? router.asPath.replace('/sujet/', '')      : ''; -  const { data, error } = useSWR('/api/subjects', getAllSubjects); +  const { data, error } = useSWR('/api/topics', getAllTopics);    const getList = () => {      if (error) return <ul>{t`Failed to load.`}</ul>; @@ -31,11 +31,11 @@ const TopicsList = ({          </ul>        ); -    const subjects = data.map((subject) => { -      return currentTopicSlug !== subject.slug ? ( -        <li key={subject.databaseId}> -          <Link href={`/sujet/${subject.slug}`}> -            <a>{subject.title}</a> +    const topics = data.map((topic) => { +      return currentTopicSlug !== topic.slug ? ( +        <li key={topic.databaseId}> +          <Link href={`/sujet/${topic.slug}`}> +            <a>{topic.title}</a>            </Link>          </li>        ) : ( @@ -43,7 +43,7 @@ const TopicsList = ({        );      }); -    return <List items={subjects} />; +    return <List items={topics} />;    };    return ( diff --git a/src/pages/article/[slug].tsx b/src/pages/article/[slug].tsx index b9c0021..f43c9ee 100644 --- a/src/pages/article/[slug].tsx +++ b/src/pages/article/[slug].tsx @@ -30,7 +30,7 @@ const SingleArticle: NextPageWithLayout<ArticleProps> = ({ post }) => {      featuredImage,      intro,      seo, -    subjects, +    topics,      thematics,      title,    } = post; @@ -137,7 +137,7 @@ const SingleArticle: NextPageWithLayout<ArticleProps> = ({ post }) => {            className={styles.body}            dangerouslySetInnerHTML={{ __html: content }}          ></div> -        <PostFooter subjects={subjects} /> +        <PostFooter topics={topics} />          <Sidebar position="right">            <Sharing title={title} excerpt={intro} />          </Sidebar> diff --git a/src/pages/projet/[slug].tsx b/src/pages/projet/[slug].tsx index e497481..82e2ea3 100644 --- a/src/pages/projet/[slug].tsx +++ b/src/pages/projet/[slug].tsx @@ -57,7 +57,7 @@ const Project: NextPageWithLayout<ProjectProps> = ({    const updateDate = new Date(dates.update);    const articleSchema: Article = { -    '@id': `${config.url}/subject`, +    '@id': `${config.url}/project`,      '@type': 'Article',      name: title,      description: intro, diff --git a/src/pages/sujet/[slug].tsx b/src/pages/sujet/[slug].tsx index 6c72cf9..ba65a27 100644 --- a/src/pages/sujet/[slug].tsx +++ b/src/pages/sujet/[slug].tsx @@ -2,26 +2,23 @@ import { getLayout } from '@components/Layouts/Layout';  import PostPreview from '@components/PostPreview/PostPreview';  import { t } from '@lingui/macro';  import { NextPageWithLayout } from '@ts/types/app'; -import { SubjectProps, ThematicPreview } from '@ts/types/taxonomies'; +import { TopicProps, ThematicPreview } from '@ts/types/taxonomies';  import { loadTranslation } from '@utils/helpers/i18n';  import { GetStaticPaths, GetStaticProps, GetStaticPropsContext } from 'next';  import { ParsedUrlQuery } from 'querystring';  import styles from '@styles/pages/Page.module.scss'; -import { -  getAllSubjectsSlug, -  getSubjectBySlug, -} from '@services/graphql/queries'; +import { getAllTopicsSlug, getTopicBySlug } from '@services/graphql/queries';  import PostHeader from '@components/PostHeader/PostHeader';  import { ArticleMeta } from '@ts/types/articles';  import { RelatedThematics, ToC, TopicsList } from '@components/Widgets';  import { useRef } from 'react';  import Head from 'next/head';  import Sidebar from '@components/Sidebar/Sidebar'; -import { Article as Article, Blog, Graph, WebPage } from 'schema-dts'; +import { Article as Article, Graph, WebPage } from 'schema-dts';  import { config } from '@config/website';  import { useRouter } from 'next/router'; -const Subject: NextPageWithLayout<SubjectProps> = ({ subject }) => { +const Topic: NextPageWithLayout<TopicProps> = ({ topic }) => {    const relatedThematics = useRef<ThematicPreview[]>([]);    const router = useRouter(); @@ -37,7 +34,7 @@ const Subject: NextPageWithLayout<SubjectProps> = ({ subject }) => {    };    const getPostsList = () => { -    return [...subject.posts].reverse().map((post) => { +    return [...topic.posts].reverse().map((post) => {        updateRelatedThematics(post.thematics);        return ( @@ -49,17 +46,17 @@ const Subject: NextPageWithLayout<SubjectProps> = ({ subject }) => {    };    const meta: ArticleMeta = { -    dates: subject.dates, -    website: subject.officialWebsite, +    dates: topic.dates, +    website: topic.officialWebsite,    }; -  const subjectUrl = `${config.url}${router.asPath}`; +  const topicUrl = `${config.url}${router.asPath}`;    const webpageSchema: WebPage = { -    '@id': `${subjectUrl}`, +    '@id': `${topicUrl}`,      '@type': 'WebPage',      breadcrumb: { '@id': `${config.url}/#breadcrumb` }, -    name: subject.seo.title, -    description: subject.seo.metaDesc, +    name: topic.seo.title, +    description: topic.seo.metaDesc,      inLanguage: config.locales.defaultLocale,      reviewedBy: { '@id': `${config.url}/#branding` },      url: `${config.url}`, @@ -68,14 +65,14 @@ const Subject: NextPageWithLayout<SubjectProps> = ({ subject }) => {      },    }; -  const publicationDate = new Date(subject.dates.publication); -  const updateDate = new Date(subject.dates.update); +  const publicationDate = new Date(topic.dates.publication); +  const updateDate = new Date(topic.dates.update);    const articleSchema: Article = { -    '@id': `${config.url}/subject`, +    '@id': `${config.url}/topic`,      '@type': 'Article', -    name: subject.title, -    description: subject.intro, +    name: topic.title, +    description: topic.intro,      author: { '@id': `${config.url}/#branding` },      copyrightYear: publicationDate.getFullYear(),      creator: { '@id': `${config.url}/#branding` }, @@ -83,12 +80,12 @@ const Subject: NextPageWithLayout<SubjectProps> = ({ subject }) => {      dateModified: updateDate.toISOString(),      datePublished: publicationDate.toISOString(),      editor: { '@id': `${config.url}/#branding` }, -    thumbnailUrl: subject.featuredImage?.sourceUrl, -    image: subject.featuredImage?.sourceUrl, +    thumbnailUrl: topic.featuredImage?.sourceUrl, +    image: topic.featuredImage?.sourceUrl,      inLanguage: config.locales.defaultLocale,      isPartOf: { '@id': `${config.url}/blog` },      license: 'https://creativecommons.org/licenses/by-sa/4.0/deed.fr', -    mainEntityOfPage: { '@id': `${subjectUrl}` }, +    mainEntityOfPage: { '@id': `${topicUrl}` },      subjectOf: { '@id': `${config.url}/blog` },    }; @@ -100,40 +97,37 @@ const Subject: NextPageWithLayout<SubjectProps> = ({ subject }) => {    return (      <>        <Head> -        <title>{subject.seo.title}</title> -        <meta name="description" content={subject.seo.metaDesc} /> -        <meta property="og:url" content={`${subjectUrl}`} /> +        <title>{topic.seo.title}</title> +        <meta name="description" content={topic.seo.metaDesc} /> +        <meta property="og:url" content={`${topicUrl}`} />          <meta property="og:type" content="article" /> -        <meta property="og:title" content={subject.title} /> -        <meta property="og:description" content={subject.intro} /> -        <meta property="og:image" content={subject.featuredImage?.sourceUrl} /> -        <meta -          property="og:image:alt" -          content={subject.featuredImage?.altText} -        /> +        <meta property="og:title" content={topic.title} /> +        <meta property="og:description" content={topic.intro} /> +        <meta property="og:image" content={topic.featuredImage?.sourceUrl} /> +        <meta property="og:image:alt" content={topic.featuredImage?.altText} />          <script            type="application/ld+json"            dangerouslySetInnerHTML={{ __html: JSON.stringify(schemaJsonLd) }}          ></script>        </Head>        <article -        id="subject" +        id="topic"          className={`${styles.article} ${styles['article--no-comments']}`}        >          <PostHeader -          cover={subject.featuredImage} -          intro={subject.intro} +          cover={topic.featuredImage} +          intro={topic.intro}            meta={meta} -          title={subject.title} +          title={topic.title}          />          <Sidebar position="left">            <ToC />          </Sidebar>          <div className={styles.body}> -          <div dangerouslySetInnerHTML={{ __html: subject.content }}></div> -          {subject.posts.length > 0 && ( +          <div dangerouslySetInnerHTML={{ __html: topic.content }}></div> +          {topic.posts.length > 0 && (              <section className={styles.section}> -              <h2>{t`All posts in ${subject.title}`}</h2> +              <h2>{t`All posts in ${topic.title}`}</h2>                <ol className={styles.list}>{getPostsList()}</ol>              </section>            )} @@ -147,7 +141,7 @@ const Subject: NextPageWithLayout<SubjectProps> = ({ subject }) => {    );  }; -Subject.getLayout = getLayout; +Topic.getLayout = getLayout;  interface PostParams extends ParsedUrlQuery {    slug: string; @@ -161,20 +155,20 @@ export const getStaticProps: GetStaticProps = async (      process.env.NODE_ENV === 'production'    );    const { slug } = context.params as PostParams; -  const subject = await getSubjectBySlug(slug); -  const breadcrumbTitle = subject.title; +  const topic = await getTopicBySlug(slug); +  const breadcrumbTitle = topic.title;    return {      props: {        breadcrumbTitle, -      subject, +      topic,        translation,      },    };  };  export const getStaticPaths: GetStaticPaths = async () => { -  const allSlugs = await getAllSubjectsSlug(); +  const allSlugs = await getAllTopicsSlug();    return {      paths: allSlugs.map((post) => `/sujet/${post.slug}`), @@ -182,4 +176,4 @@ export const getStaticPaths: GetStaticPaths = async () => {    };  }; -export default Subject; +export default Topic; diff --git a/src/pages/thematique/[slug].tsx b/src/pages/thematique/[slug].tsx index 93b1221..c76831d 100644 --- a/src/pages/thematique/[slug].tsx +++ b/src/pages/thematique/[slug].tsx @@ -2,7 +2,7 @@ import { getLayout } from '@components/Layouts/Layout';  import PostPreview from '@components/PostPreview/PostPreview';  import { t } from '@lingui/macro';  import { NextPageWithLayout } from '@ts/types/app'; -import { SubjectPreview, ThematicProps } from '@ts/types/taxonomies'; +import { TopicPreview, ThematicProps } from '@ts/types/taxonomies';  import { loadTranslation } from '@utils/helpers/i18n';  import { GetStaticPaths, GetStaticProps, GetStaticPropsContext } from 'next';  import { ParsedUrlQuery } from 'querystring'; @@ -17,28 +17,28 @@ import { useRef } from 'react';  import { ArticleMeta } from '@ts/types/articles';  import Head from 'next/head';  import Sidebar from '@components/Sidebar/Sidebar'; -import { Article, Blog, Graph, WebPage } from 'schema-dts'; +import { Article, Graph, WebPage } from 'schema-dts';  import { config } from '@config/website';  import { useRouter } from 'next/router';  const Thematic: NextPageWithLayout<ThematicProps> = ({ thematic }) => { -  const relatedSubjects = useRef<SubjectPreview[]>([]); +  const relatedTopics = useRef<TopicPreview[]>([]);    const router = useRouter(); -  const updateRelatedSubjects = (newSubjects: SubjectPreview[]) => { -    newSubjects.forEach((subject) => { -      const subjectIndex = relatedSubjects.current.findIndex( -        (relatedSubject) => relatedSubject.id === subject.id +  const updateRelatedTopics = (newTopics: TopicPreview[]) => { +    newTopics.forEach((topic) => { +      const topicIndex = relatedTopics.current.findIndex( +        (relatedTopic) => relatedTopic.id === topic.id        ); -      const hasSubject = subjectIndex === -1 ? false : true; +      const hasTopic = topicIndex === -1 ? false : true; -      if (!hasSubject) relatedSubjects.current.push(subject); +      if (!hasTopic) relatedTopics.current.push(topic);      });    };    const getPostsList = () => {      return [...thematic.posts].reverse().map((post) => { -      updateRelatedSubjects(post.subjects); +      updateRelatedTopics(post.topics);        return (          <li key={post.id} className={styles.item}> @@ -123,7 +123,7 @@ const Thematic: NextPageWithLayout<ThematicProps> = ({ thematic }) => {            )}          </div>          <Sidebar position="right"> -          <RelatedTopics topics={relatedSubjects.current} /> +          <RelatedTopics topics={relatedTopics.current} />            <ThematicsList title={t`Other thematics`} />          </Sidebar>        </article> diff --git a/src/services/graphql/queries.ts b/src/services/graphql/queries.ts index 5aaa188..7bd6401 100644 --- a/src/services/graphql/queries.ts +++ b/src/services/graphql/queries.ts @@ -2,13 +2,13 @@ import { Slug } from '@ts/types/app';  import { Article, PostBy } from '@ts/types/articles';  import { AllPostsSlug, PostsList, RawPostsList } from '@ts/types/blog';  import { -  AllSubjects, -  AllSubjectsSlug, +  AllTopics, +  AllTopicsSlug,    AllThematics,    AllThematicsSlug, -  Subject, -  SubjectBy, -  SubjectPreview, +  Topic, +  TopicBy, +  TopicPreview,    Thematic,    ThematicBy,    ThematicPreview, @@ -16,7 +16,7 @@ import {  import {    getFormattedPost,    getFormattedPostPreview, -  getFormattedSubject, +  getFormattedTopic,    getFormattedThematic,  } from '@utils/helpers/format';  import { gql } from 'graphql-request'; @@ -50,8 +50,8 @@ export const getPublishedPosts = async ({            cursor            node {              acfPosts { -              postsInSubject { -                ... on Subject { +              postsInTopic { +                ... on Topic {                    databaseId                    featuredImage {                      node { @@ -138,8 +138,8 @@ export const getPostBySlug = async (slug: string): Promise<Article> => {      query PostBySlug($slug: String!) {        postBy(slug: $slug) {          acfPosts { -          postsInSubject { -            ... on Subject { +          postsInTopic { +            ... on Topic {                id                featuredImage {                  node { @@ -231,20 +231,20 @@ export const getPostBySlug = async (slug: string): Promise<Article> => {  };  //============================================================================== -// Subject query +// Topic query  //============================================================================== -export const getSubjectBySlug = async (slug: string): Promise<Subject> => { +export const getTopicBySlug = async (slug: string): Promise<Topic> => {    const query = gql` -    query SubjectBySlug($slug: String!) { -      subjectBy(slug: $slug) { -        acfSubjects { +    query TopicBySlug($slug: String!) { +      topicBy(slug: $slug) { +        acfTopics {            officialWebsite -          postsInSubject { +          postsInTopic {              ... on Post {                acfPosts { -                postsInSubject { -                  ... on Subject { +                postsInTopic { +                  ... on Topic {                      databaseId                      featuredImage {                        node { @@ -326,31 +326,31 @@ export const getSubjectBySlug = async (slug: string): Promise<Subject> => {      }    `;    const variables = { slug }; -  const response = await fetchApi<SubjectBy>(query, variables); +  const response = await fetchApi<TopicBy>(query, variables); -  return getFormattedSubject(response.subjectBy); +  return getFormattedTopic(response.topicBy);  }; -export const getAllSubjectsSlug = async (): Promise<Slug[]> => { +export const getAllTopicsSlug = async (): Promise<Slug[]> => {    // 10 000 is an arbitrary number that I use for small websites.    const query = gql` -    query AllSubjectsSlug { -      subjects(first: 10000) { +    query AllTopicsSlug { +      topics(first: 10000) {          nodes {            slug          }        }      }    `; -  const response = await fetchApi<AllSubjectsSlug>(query, null); -  return response.subjects.nodes; +  const response = await fetchApi<AllTopicsSlug>(query, null); +  return response.topics.nodes;  }; -export const getAllSubjects = async (): Promise<SubjectPreview[]> => { +export const getAllTopics = async (): Promise<TopicPreview[]> => {    // 10 000 is an arbitrary number that I use for small websites.    const query = gql` -    query AllSubjects { -      subjects(first: 10000, where: { orderby: { field: TITLE, order: ASC } }) { +    query AllTopics { +      topics(first: 10000, where: { orderby: { field: TITLE, order: ASC } }) {          nodes {            databaseId            slug @@ -360,8 +360,8 @@ export const getAllSubjects = async (): Promise<SubjectPreview[]> => {      }    `; -  const response = await fetchApi<AllSubjects>(query, null); -  return response.subjects.nodes; +  const response = await fetchApi<AllTopics>(query, null); +  return response.topics.nodes;  };  //============================================================================== @@ -376,8 +376,8 @@ export const getThematicBySlug = async (slug: string): Promise<Thematic> => {            postsInThematic {              ... on Post {                acfPosts { -                postsInSubject { -                  ... on Subject { +                postsInTopic { +                  ... on Topic {                      databaseId                      featuredImage {                        node { diff --git a/src/ts/types/app.ts b/src/ts/types/app.ts index b2a5cd6..60dd4b8 100644 --- a/src/ts/types/app.ts +++ b/src/ts/types/app.ts @@ -1,16 +1,16 @@  import { NextPage } from 'next';  import { AppProps } from 'next/app'; -import { ComponentType, ReactElement, ReactNode } from 'react'; +import { ReactElement, ReactNode } from 'react';  import { PostBy } from './articles';  import { AllPostsSlug, RawPostsList } from './blog';  import { CommentData, CreateComment } from './comments';  import { ContactData, SendEmail } from './contact';  import { -  AllSubjects, -  AllSubjectsSlug, +  AllTopics, +  AllTopicsSlug,    AllThematics,    AllThematicsSlug, -  SubjectBy, +  TopicBy,    ThematicBy,  } from './taxonomies'; @@ -30,7 +30,7 @@ export type AppPropsWithLayout = AppProps & {  // API  //============================================================================== -export type VariablesType<T> = T extends PostBy | SubjectBy | ThematicBy +export type VariablesType<T> = T extends PostBy | TopicBy | ThematicBy    ? Slug    : T extends RawPostsList    ? CursorPagination @@ -42,13 +42,13 @@ export type VariablesType<T> = T extends PostBy | SubjectBy | ThematicBy  export type RequestType =    | AllPostsSlug -  | AllSubjects -  | AllSubjectsSlug +  | AllTopics +  | AllTopicsSlug    | AllThematics    | AllThematicsSlug    | CreateComment    | PostBy -  | SubjectBy +  | TopicBy    | ThematicBy    | RawPostsList    | SendEmail; diff --git a/src/ts/types/articles.ts b/src/ts/types/articles.ts index 1fb3ec5..da86e10 100644 --- a/src/ts/types/articles.ts +++ b/src/ts/types/articles.ts @@ -2,11 +2,7 @@ import { ContentParts, Dates } from './app';  import { Comment, CommentsNode } from './comments';  import { Cover, RawCover } from './cover';  import { SEO } from './seo'; -import { -  RawSubjectPreview, -  SubjectPreview, -  ThematicPreview, -} from './taxonomies'; +import { RawTopicPreview, TopicPreview, ThematicPreview } from './taxonomies';  export type ArticleAuthor = {    firstName: string; @@ -15,12 +11,12 @@ export type ArticleAuthor = {  };  export type RawACFPosts = { -  postsInSubject: RawSubjectPreview[] | null; +  postsInTopic: RawTopicPreview[] | null;    postsInThematic: ThematicPreview[] | null;  };  export type ACFPosts = { -  postsInSubject: SubjectPreview[] | null; +  postsInTopic: TopicPreview[] | null;    postsInThematic: ThematicPreview[] | null;  }; @@ -28,7 +24,7 @@ export type ArticleMeta = {    author?: ArticleAuthor;    commentCount?: number;    dates?: Dates; -  subjects?: SubjectPreview[]; +  topics?: TopicPreview[];    thematics?: ThematicPreview[];    website?: string;  }; @@ -44,7 +40,7 @@ export type Article = {    id: string;    intro: string;    seo: SEO; -  subjects: SubjectPreview[] | []; +  topics: TopicPreview[] | [];    thematics: ThematicPreview[] | [];    title: string;  }; @@ -64,7 +60,7 @@ export type RawArticle = Pick<  export type ArticlePreview = Pick<    Article, -  'commentCount' | 'dates' | 'id' | 'intro' | 'subjects' | 'thematics' | 'title' +  'commentCount' | 'dates' | 'id' | 'intro' | 'topics' | 'thematics' | 'title'  > & { featuredImage: Cover; slug: string };  export type RawArticlePreview = Pick< diff --git a/src/ts/types/taxonomies.ts b/src/ts/types/taxonomies.ts index a0aaa5e..7d4ad3b 100644 --- a/src/ts/types/taxonomies.ts +++ b/src/ts/types/taxonomies.ts @@ -23,32 +23,32 @@ type TaxonomyPreview = Pick<Taxonomy, 'databaseId' | 'id' | 'seo' | 'title'> & {  };  //============================================================================== -// Subjects +// Topics  //============================================================================== -export type Subject = Taxonomy & { +export type Topic = Taxonomy & {    featuredImage: Cover;    officialWebsite: string;  }; -export type RawSubjectPreview = TaxonomyPreview & { +export type RawTopicPreview = TaxonomyPreview & {    featuredImage: RawCover;  }; -export type SubjectPreview = TaxonomyPreview & { +export type TopicPreview = TaxonomyPreview & {    featuredImage: Cover;  }; -export type AllSubjects = { -  subjects: { -    nodes: SubjectPreview[]; +export type AllTopics = { +  topics: { +    nodes: TopicPreview[];    };  }; -export type RawSubject = SubjectPreview & { -  acfSubjects: { +export type RawTopic = TopicPreview & { +  acfTopics: {      officialWebsite: string; -    postsInSubject: RawArticlePreview[]; +    postsInTopic: RawArticlePreview[];    };    contentParts: ContentParts;    date: string; @@ -56,18 +56,18 @@ export type RawSubject = SubjectPreview & {    modified: string;  }; -export type SubjectBy = { -  subjectBy: RawSubject; +export type TopicBy = { +  topicBy: RawTopic;  }; -export type AllSubjectsSlug = { -  subjects: { +export type AllTopicsSlug = { +  topics: {      nodes: Slug[];    };  }; -export type SubjectProps = { -  subject: Subject; +export type TopicProps = { +  topic: Topic;  };  //============================================================================== diff --git a/src/utils/helpers/format.ts b/src/utils/helpers/format.ts index 374df76..0ed1ab5 100644 --- a/src/utils/helpers/format.ts +++ b/src/utils/helpers/format.ts @@ -6,11 +6,11 @@ import {  } from '@ts/types/articles';  import { Comment, RawComment } from '@ts/types/comments';  import { -  RawSubject, -  RawSubjectPreview, +  RawTopic, +  RawTopicPreview,    RawThematic, -  Subject, -  SubjectPreview, +  Topic, +  TopicPreview,    Thematic,  } from '@ts/types/taxonomies'; @@ -37,7 +37,7 @@ export const getFormattedPostPreview = (rawPost: RawArticlePreview) => {      update: modified,    }; -  const subjects = acfPosts.postsInSubject ? acfPosts.postsInSubject : []; +  const topics = acfPosts.postsInTopic ? acfPosts.postsInTopic : [];    const thematics = acfPosts.postsInThematic ? acfPosts.postsInThematic : [];    const formattedPost: ArticlePreview = { @@ -47,7 +47,7 @@ export const getFormattedPostPreview = (rawPost: RawArticlePreview) => {      id,      intro: contentParts.beforeMore,      slug, -    subjects, +    topics,      thematics,      title,    }; @@ -71,13 +71,13 @@ export const getFormattedPostsList = (  };  /** - * Format a subject from RawSubject to Subject type. - * @param rawSubject - A subject coming from WP GraphQL. - * @returns A formatted subject. + * Format a topic from RawTopic to Topic type. + * @param rawTopic - A topic coming from WP GraphQL. + * @returns A formatted topic.   */ -export const getFormattedSubject = (rawSubject: RawSubject): Subject => { +export const getFormattedTopic = (rawTopic: RawTopic): Topic => {    const { -    acfSubjects, +    acfTopics,      contentParts,      databaseId,      date, @@ -86,29 +86,29 @@ export const getFormattedSubject = (rawSubject: RawSubject): Subject => {      modified,      seo,      title, -  } = rawSubject; +  } = rawTopic;    const dates = {      publication: date,      update: modified,    }; -  const posts = getFormattedPostsList(acfSubjects.postsInSubject); +  const posts = getFormattedPostsList(acfTopics.postsInTopic); -  const formattedSubject: Subject = { +  const formattedTopic: Topic = {      content: contentParts.afterMore,      databaseId,      dates,      featuredImage: featuredImage ? featuredImage.node : null,      id,      intro: contentParts.beforeMore, -    officialWebsite: acfSubjects.officialWebsite, +    officialWebsite: acfTopics.officialWebsite,      posts,      seo,      title,    }; -  return formattedSubject; +  return formattedTopic;  };  /** @@ -196,17 +196,17 @@ export const buildCommentsTree = (comments: Comment[]) => {    return commentsTree;  }; -export const getFormattedSubjectsPreview = ( -  subjects: RawSubjectPreview[] -): SubjectPreview[] => { -  const formattedSubjects: SubjectPreview[] = subjects.map((subject) => { +export const getFormattedTopicsPreview = ( +  topics: RawTopicPreview[] +): TopicPreview[] => { +  const formattedTopics: TopicPreview[] = topics.map((topic) => {      return { -      ...subject, -      featuredImage: subject.featuredImage ? subject.featuredImage.node : null, +      ...topic, +      featuredImage: topic.featuredImage ? topic.featuredImage.node : null,      };    }); -  return formattedSubjects; +  return formattedTopics;  };  /** @@ -237,8 +237,8 @@ export const getFormattedPost = (rawPost: RawArticle): Article => {    const formattedComments = getFormattedComments(comments.nodes);    const commentsTree = buildCommentsTree(formattedComments); -  const subjects = acfPosts.postsInSubject -    ? getFormattedSubjectsPreview(acfPosts.postsInSubject) +  const topics = acfPosts.postsInTopic +    ? getFormattedTopicsPreview(acfPosts.postsInTopic)      : [];    const formattedPost: Article = { @@ -252,7 +252,7 @@ export const getFormattedPost = (rawPost: RawArticle): Article => {      id,      intro: contentParts.beforeMore,      seo, -    subjects, +    topics,      thematics: acfPosts.postsInThematic ? acfPosts.postsInThematic : [],      title,    }; | 
