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/article/[slug].tsx | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'src/pages/article') diff --git a/src/pages/article/[slug].tsx b/src/pages/article/[slug].tsx index bd102a9..6333056 100644 --- a/src/pages/article/[slug].tsx +++ b/src/pages/article/[slug].tsx @@ -46,7 +46,7 @@ import { import { loadTranslation, type Messages } from '../../utils/helpers/server'; import { useArticle, - useBreadcrumb, + useBreadcrumbs, useComments, useHeadingsTree, usePrism, @@ -74,10 +74,9 @@ const ArticlePage: NextPageWithLayout = ({ data }) => { contentId: article.id, }, }); - const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumb({ - title: data.post.title, - url: data.post.slug, - }); + const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumbs( + article.title + ); const { ref, tree } = useHeadingsTree({ fromLevel: 2 }); const { attributes, className: prismClassName } = usePrism({ attributes: { @@ -172,6 +171,7 @@ const ArticlePage: NextPageWithLayout = ({ data }) => { webpageSchema, blogSchema, blogPostSchema, + breadcrumbSchema, ...getCommentsSchema(comments), ]); @@ -208,12 +208,6 @@ const ArticlePage: NextPageWithLayout = ({ data }) => { // eslint-disable-next-line react/no-danger -- Necessary for schema dangerouslySetInnerHTML={{ __html: JSON.stringify(schemaJsonLd) }} /> -