From 85c4c42bd601270d7be0f34a0767a34bb85e29bb Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 12 Dec 2023 18:50:03 +0100 Subject: refactor(hooks): rewrite useBreadcrumbs hook * use next/router to get the slug instead of using props * handle cases where the current page title is not provided * update JSON-LD schema to match the example in documentation * add tests --- src/pages/cv.tsx | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/pages/cv.tsx') diff --git a/src/pages/cv.tsx b/src/pages/cv.tsx index b77aa8c..d08c121 100644 --- a/src/pages/cv.tsx +++ b/src/pages/cv.tsx @@ -22,14 +22,14 @@ import { mdxComponents } from '../components/mdx'; import CVContent, { data, meta } from '../content/pages/cv.mdx'; import type { NextPageWithLayout } from '../types'; import { CONFIG } from '../utils/config'; -import { PERSONAL_LINKS, ROUTES } from '../utils/constants'; +import { PERSONAL_LINKS } from '../utils/constants'; import { getSchemaJson, getSinglePageSchema, getWebPageSchema, } from '../utils/helpers'; import { loadTranslation } from '../utils/helpers/server'; -import { useBreadcrumb, useHeadingsTree } from '../utils/hooks'; +import { useBreadcrumbs, useHeadingsTree } from '../utils/hooks'; const DownloadLink = (chunks: ReactNode) => ( @@ -44,10 +44,8 @@ const CVPage: NextPageWithLayout = () => { const intl = useIntl(); const { ref, tree } = useHeadingsTree({ fromLevel: 2 }); const { dates, intro, seo, title } = meta; - const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumb({ - title, - url: ROUTES.CV, - }); + const { items: breadcrumbItems, schema: breadcrumbSchema } = + useBreadcrumbs(title); const messages = { image: { caption: intl.formatMessage( @@ -115,7 +113,11 @@ const CVPage: NextPageWithLayout = () => { slug: asPath, title, }); - const schemaJsonLd = getSchemaJson([webpageSchema, cvSchema]); + const schemaJsonLd = getSchemaJson([ + webpageSchema, + cvSchema, + breadcrumbSchema, + ]); const page = { title: `${seo.title} - ${CONFIG.name}`, url: `${CONFIG.url}${asPath}`, @@ -141,12 +143,6 @@ const CVPage: NextPageWithLayout = () => { type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(schemaJsonLd) }} /> -