From 70efcfeaa0603415dd992cb662d8efb960e6e49a Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 26 Sep 2023 15:54:28 +0200 Subject: refactor(routes): replace hardcoded routes with constants It makes it easier to change a route if needed and it avoid typo mistakes. I also refactored a bit the concerned files to be complient with the new ESlint config. However, I should rewrite the pages to reduce the number of statements. --- src/pages/blog/page/[number].tsx | 51 ++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 20 deletions(-) (limited to 'src/pages/blog/page') diff --git a/src/pages/blog/page/[number].tsx b/src/pages/blog/page/[number].tsx index 4eaade5..b63fa9b 100644 --- a/src/pages/blog/page/[number].tsx +++ b/src/pages/blog/page/[number].tsx @@ -1,8 +1,9 @@ -import { GetStaticPaths, GetStaticProps } from 'next'; +/* eslint-disable max-statements */ +import type { ParsedUrlQuery } from 'querystring'; +import type { GetStaticPaths, GetStaticProps } from 'next'; import Head from 'next/head'; import { useRouter } from 'next/router'; import Script from 'next/script'; -import { ParsedUrlQuery } from 'querystring'; import { useIntl } from 'react-intl'; import { getLayout, @@ -19,12 +20,12 @@ import { getTotalThematics, getTotalTopics, } from '../../../services/graphql'; -import { - type EdgesResponse, - type NextPageWithLayout, - type RawArticle, - type RawThematicPreview, - type RawTopicPreview, +import type { + EdgesResponse, + NextPageWithLayout, + RawArticle, + RawThematicPreview, + RawTopicPreview, } from '../../../types'; import { settings } from '../../../utils/config'; import { @@ -41,6 +42,7 @@ import { useRedirection, useSettings, } from '../../../utils/hooks'; +import { ROUTES } from 'src/utils/constants'; type BlogPageProps = { articles: EdgesResponse; @@ -63,7 +65,7 @@ const BlogPage: NextPageWithLayout = ({ }) => { useRedirection({ query: { param: 'number', value: '1' }, - redirectTo: '/blog', + redirectTo: ROUTES.BLOG, }); const intl = useIntl(); @@ -85,12 +87,15 @@ const BlogPage: NextPageWithLayout = ({ const pageTitleWithPageNumber = `${title} - ${pageNumberTitle}`; const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumb({ title: pageNumberTitle, - url: `/blog/page/${pageNumber}`, + url: `${ROUTES.BLOG}/page/${pageNumber}`, }); const { website } = useSettings(); const { asPath } = useRouter(); - const pageTitle = `${pageTitleWithPageNumber} - ${website.name}`; + const page = { + title: `${pageTitleWithPageNumber} - ${website.name}`, + url: `${website.url}${asPath}`, + }; const pageDescription = intl.formatMessage( { defaultMessage: @@ -124,20 +129,25 @@ const BlogPage: NextPageWithLayout = ({ description: 'BlogPage: topics list widget title', id: '2D9tB5', }); + const postsListBaseUrl = `${ROUTES.BLOG}/page/`; return ( <> - {pageTitle} + {page.title} + {/*eslint-disable-next-line react/jsx-no-literals -- Name allowed */} - + + {/*eslint-disable-next-line react/jsx-no-literals -- Content allowed */}