From 368fbbf83b913b90cef9dfbe4288e148d589d033 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Sun, 23 Jan 2022 00:20:08 +0100 Subject: refactor: rename all subject occurrences into topic I change the name in graphql endpoint, so I decided to repercute this change here. --- src/pages/article/[slug].tsx | 4 +- src/pages/projet/[slug].tsx | 2 +- src/pages/sujet/[slug].tsx | 84 +++++++++++++++++++---------------------- src/pages/thematique/[slug].tsx | 22 +++++------ 4 files changed, 53 insertions(+), 59 deletions(-) (limited to 'src/pages') 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 = ({ post }) => { featuredImage, intro, seo, - subjects, + topics, thematics, title, } = post; @@ -137,7 +137,7 @@ const SingleArticle: NextPageWithLayout = ({ post }) => { className={styles.body} dangerouslySetInnerHTML={{ __html: content }} > - + 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 = ({ 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 = ({ subject }) => { +const Topic: NextPageWithLayout = ({ topic }) => { const relatedThematics = useRef([]); const router = useRouter(); @@ -37,7 +34,7 @@ const Subject: NextPageWithLayout = ({ 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 = ({ 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 = ({ 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 = ({ 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 = ({ subject }) => { return ( <> - {subject.seo.title} - - + {topic.seo.title} + + - - - - + + + +
-
- {subject.posts.length > 0 && ( +
+ {topic.posts.length > 0 && (
-

{t`All posts in ${subject.title}`}

+

{t`All posts in ${topic.title}`}

    {getPostsList()}
)} @@ -147,7 +141,7 @@ const Subject: NextPageWithLayout = ({ 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 = ({ thematic }) => { - const relatedSubjects = useRef([]); + const relatedTopics = useRef([]); 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 (
  • @@ -123,7 +123,7 @@ const Thematic: NextPageWithLayout = ({ thematic }) => { )}
  • - +
    -- cgit v1.2.3