aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages/projets
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/projets
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/projets')
-rw-r--r--src/pages/projets/[slug].tsx20
-rw-r--r--src/pages/projets/index.tsx20
2 files changed, 16 insertions, 24 deletions
diff --git a/src/pages/projets/[slug].tsx b/src/pages/projets/[slug].tsx
index 0c750f9..8985f47 100644
--- a/src/pages/projets/[slug].tsx
+++ b/src/pages/projets/[slug].tsx
@@ -49,7 +49,7 @@ import {
loadTranslation,
} from '../../utils/helpers/server';
import {
- useBreadcrumb,
+ useBreadcrumbs,
useGithubRepoMeta,
useHeadingsTree,
} from '../../utils/hooks';
@@ -183,10 +183,8 @@ type ProjectPageProps = {
const ProjectPage: NextPageWithLayout<ProjectPageProps> = ({ data }) => {
const { id, intro, meta, slug, title } = data.project;
const intl = useIntl();
- const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumb({
- title,
- url: slug,
- });
+ const { items: breadcrumbItems, schema: breadcrumbSchema } =
+ useBreadcrumbs(title);
const { ref, tree } = useHeadingsTree<HTMLDivElement>({ fromLevel: 2 });
const page = {
@@ -211,7 +209,11 @@ const ProjectPage: NextPageWithLayout<ProjectPageProps> = ({ data }) => {
slug,
title,
});
- const schemaJsonLd = getSchemaJson([webpageSchema, articleSchema]);
+ const schemaJsonLd = getSchemaJson([
+ webpageSchema,
+ articleSchema,
+ breadcrumbSchema,
+ ]);
const messages = {
repos: {
@@ -262,12 +264,6 @@ const ProjectPage: NextPageWithLayout<ProjectPageProps> = ({ 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}
diff --git a/src/pages/projets/index.tsx b/src/pages/projets/index.tsx
index 843374a..401c68c 100644
--- a/src/pages/projets/index.tsx
+++ b/src/pages/projets/index.tsx
@@ -35,7 +35,7 @@ import {
loadTranslation,
type Messages,
} from '../../utils/helpers/server';
-import { useBreadcrumb } from '../../utils/hooks';
+import { useBreadcrumbs } from '../../utils/hooks';
type ProjectsPageProps = {
data: {
@@ -49,10 +49,8 @@ type ProjectsPageProps = {
*/
const ProjectsPage: NextPageWithLayout<ProjectsPageProps> = ({ data }) => {
const { dates, seo, title } = meta;
- const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumb({
- title,
- url: ROUTES.PROJECTS,
- });
+ const { items: breadcrumbItems, schema: breadcrumbSchema } =
+ useBreadcrumbs(title);
const intl = useIntl();
const webpageSchema = getWebPageSchema({
description: seo.description,
@@ -70,7 +68,11 @@ const ProjectsPage: NextPageWithLayout<ProjectsPageProps> = ({ data }) => {
slug: ROUTES.PROJECTS,
title,
});
- const schemaJsonLd = getSchemaJson([webpageSchema, articleSchema]);
+ const schemaJsonLd = getSchemaJson([
+ webpageSchema,
+ articleSchema,
+ breadcrumbSchema,
+ ]);
const page = {
title: `${seo.title} - ${CONFIG.name}`,
url: `${CONFIG.url}${ROUTES.PROJECTS}`,
@@ -95,12 +97,6 @@ const ProjectsPage: NextPageWithLayout<ProjectsPageProps> = ({ 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={<PageContent components={mdxComponents} />}