From 7063b199b4748a9c354ed37e64cdc84c512f2c0c Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Thu, 14 Dec 2023 15:30:34 +0100 Subject: refactor(pages): rewrite helpers to output schema in json-ld format * make sure url are absolutes * nest breadcrumb schema in webpage schema * trim HTML tags from content/description * use a regular script instead of next/script (with the latter the schema is not updated on route change) * place the script in document head * add keywords, wordCount and readingTime keys in BlogPosting schema * fix breadcrumbs in search page (without query) * add tests (a `MatchInlineSnapshot` will be better but Prettier 3 is not supported yet) --- src/pages/404.tsx | 27 +++++++---- src/pages/article/[slug].tsx | 100 ++++++++++++++++++++++----------------- src/pages/blog/index.tsx | 58 ++++++++++++----------- src/pages/blog/page/[number].tsx | 57 +++++++++++----------- src/pages/contact.tsx | 47 ++++++------------ src/pages/cv.tsx | 57 ++++++++-------------- src/pages/index.tsx | 44 +++++++++++------ src/pages/mentions-legales.tsx | 47 ++++++------------ src/pages/projets/[slug].tsx | 50 +++++++------------- src/pages/projets/index.tsx | 50 +++++++------------- src/pages/recherche/index.tsx | 57 ++++++++++------------ src/pages/sujet/[slug].tsx | 50 +++++++------------- src/pages/thematique/[slug].tsx | 48 +++++++------------ 13 files changed, 309 insertions(+), 383 deletions(-) (limited to 'src/pages') diff --git a/src/pages/404.tsx b/src/pages/404.tsx index 450859c..72c252e 100644 --- a/src/pages/404.tsx +++ b/src/pages/404.tsx @@ -1,7 +1,6 @@ import type { GetStaticProps } from 'next'; import Head from 'next/head'; import { useRouter } from 'next/router'; -import Script from 'next/script'; import { useCallback, type ReactNode } from 'react'; import { useIntl } from 'react-intl'; import { @@ -34,7 +33,11 @@ import type { } from '../types'; import { CONFIG } from '../utils/config'; import { ROUTES } from '../utils/constants'; -import { getLinksItemData } from '../utils/helpers'; +import { + getLinksItemData, + getSchemaFrom, + getWebPageGraph, +} from '../utils/helpers'; import { loadTranslation, type Messages } from '../utils/helpers/server'; import { useBreadcrumbs, @@ -118,6 +121,15 @@ const Error404Page: NextPageWithLayout = ({ data }) => { messages.page.title ); + const jsonLd = getSchemaFrom([ + getWebPageGraph({ + breadcrumb: breadcrumbSchema, + description: messages.seo.metaDesc, + slug: ROUTES.NOT_FOUND, + title: messages.page.title, + }), + ]); + const searchSubmitHandler: SearchFormSubmit = useCallback( async ({ query }) => { if (!query) @@ -145,13 +157,12 @@ const Error404Page: NextPageWithLayout = ({ data }) => { {messages.seo.title} {/*eslint-disable-next-line react/jsx-no-literals -- Name allowed */} +