aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages/thematique
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-12-12 18:50:03 +0100
committerArmand Philippot <git@armandphilippot.com>2023-12-12 18:50:03 +0100
commit85c4c42bd601270d7be0f34a0767a34bb85e29bb (patch)
tree16a07a89cf209139672592fd6988f0c028acb7e9 /src/pages/thematique
parent93f87c10783e3d76f1dec667779aedffcae33a39 (diff)
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
Diffstat (limited to 'src/pages/thematique')
-rw-r--r--src/pages/thematique/[slug].tsx22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/pages/thematique/[slug].tsx b/src/pages/thematique/[slug].tsx
index 6ab349d..f019341 100644
--- a/src/pages/thematique/[slug].tsx
+++ b/src/pages/thematique/[slug].tsx
@@ -33,7 +33,6 @@ import type {
WPThematicPreview,
} from '../../types';
import { CONFIG } from '../../utils/config';
-import { ROUTES } from '../../utils/constants';
import {
getLinksItemData,
getPostsWithUrl,
@@ -44,7 +43,7 @@ import {
} from '../../utils/helpers';
import { loadTranslation, type Messages } from '../../utils/helpers/server';
import {
- useBreadcrumb,
+ useBreadcrumbs,
useHeadingsTree,
useThematic,
useThematicsList,
@@ -70,10 +69,9 @@ const ThematicPage: NextPageWithLayout<ThematicPageProps> = ({ data }) => {
fallback: data.otherThematics,
input: { first: data.totalThematics, where: { notIn: [thematic.id] } },
});
- const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumb({
- title: data.currentThematic.title,
- url: `${ROUTES.THEMATICS}/${data.currentThematic.slug}`,
- });
+ const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumbs(
+ thematic.title
+ );
const { ref, tree } = useHeadingsTree<HTMLDivElement>({ fromLevel: 2 });
if (isFallback || isLoading) return <LoadingPage />;
@@ -97,7 +95,11 @@ const ThematicPage: NextPageWithLayout<ThematicPageProps> = ({ data }) => {
slug,
title,
});
- const schemaJsonLd = getSchemaJson([webpageSchema, articleSchema]);
+ const schemaJsonLd = getSchemaJson([
+ webpageSchema,
+ articleSchema,
+ breadcrumbSchema,
+ ]);
const messages = {
widgets: {
@@ -154,12 +156,6 @@ const ThematicPage: NextPageWithLayout<ThematicPageProps> = ({ data }) => {
// eslint-disable-next-line react/no-danger -- Necessary for schema
dangerouslySetInnerHTML={{ __html: JSON.stringify(schemaJsonLd) }}
/>
- <Script
- dangerouslySetInnerHTML={{ __html: JSON.stringify(breadcrumbSchema) }}
- // eslint-disable-next-line react/jsx-no-literals -- Id allowed
- id="schema-breadcrumb"
- type="application/ld+json"
- />
<PageHeader
heading={title}
intro={intro}