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/projets/index.tsx | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'src/pages/projets/index.tsx') diff --git a/src/pages/projets/index.tsx b/src/pages/projets/index.tsx index a145401..97963dd 100644 --- a/src/pages/projets/index.tsx +++ b/src/pages/projets/index.tsx @@ -1,5 +1,5 @@ -import { MDXComponents } from 'mdx/types'; -import { GetStaticProps } from 'next'; +import type { MDXComponents } from 'mdx/types'; +import type { GetStaticProps } from 'next'; import Head from 'next/head'; import { useRouter } from 'next/router'; import Script from 'next/script'; @@ -12,12 +12,13 @@ import { } from '../../components'; import PageContent, { meta } from '../../content/pages/projects.mdx'; import styles from '../../styles/pages/projects.module.scss'; -import { type NextPageWithLayout, type ProjectCard } from '../../types'; +import type { NextPageWithLayout, ProjectCard } from '../../types'; +import { ROUTES } from '../../utils/constants'; import { getSchemaJson, getSinglePageSchema, getWebPageSchema, -} from '../../utils/helpers/'; +} from '../../utils/helpers'; import { getProjectsCard, loadTranslation, @@ -25,6 +26,10 @@ import { } from '../../utils/helpers/server'; import { useBreadcrumb, useSettings } from '../../utils/hooks'; +const components: MDXComponents = { + Link, +}; + type ProjectsPageProps = { projects: ProjectCard[]; translation?: Messages; @@ -37,7 +42,7 @@ const ProjectsPage: NextPageWithLayout = ({ projects }) => { const { dates, seo, title } = meta; const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumb({ title, - url: `/projets`, + url: ROUTES.PROJECTS, }); const items: CardsListItem[] = projects.map( @@ -47,18 +52,14 @@ const ProjectsPage: NextPageWithLayout = ({ projects }) => { return { cover, id: id as string, - meta: { technologies: technologies }, + meta: { technologies }, tagline, title: projectTitle, - url: `/projets/${slug}`, + url: `${ROUTES.PROJECTS}/${slug}`, }; } ); - const components: MDXComponents = { - Link, - }; - const { website } = useSettings(); const { asPath } = useRouter(); const webpageSchema = getWebPageSchema({ @@ -78,20 +79,28 @@ const ProjectsPage: NextPageWithLayout = ({ projects }) => { title, }); const schemaJsonLd = getSchemaJson([webpageSchema, articleSchema]); + const page = { + title: `${seo.title} - ${website.name}`, + url: `${website.url}${asPath}`, + }; return ( <> - {`${seo.title} - ${website.name}`} + {page.title} + {/*eslint-disable-next-line react/jsx-no-literals -- Name allowed */} - + + {/*eslint-disable-next-line react/jsx-no-literals -- Content allowed */} - +