aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages/thematique
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-05-23 19:02:20 +0200
committerArmand Philippot <git@armandphilippot.com>2022-05-23 19:02:20 +0200
commit5ebd7c14f7303a0feb8ec1d902ecd0e287d929c3 (patch)
tree4e0e0352ac7598fa4e186230e93bcc4c1ac6b810 /src/pages/thematique
parent34e216546151eaf8a0a3cbb0bc8b65dae4c63bf2 (diff)
refactor(schema): use helpers function to avoid repeat between pages
Diffstat (limited to 'src/pages/thematique')
-rw-r--r--src/pages/thematique/[slug].tsx60
1 files changed, 21 insertions, 39 deletions
diff --git a/src/pages/thematique/[slug].tsx b/src/pages/thematique/[slug].tsx
index a91483e..84ab134 100644
--- a/src/pages/thematique/[slug].tsx
+++ b/src/pages/thematique/[slug].tsx
@@ -22,6 +22,11 @@ import {
getPageLinkFromRawData,
getPostsWithUrl,
} from '@utils/helpers/pages';
+import {
+ getSchemaJson,
+ getSinglePageSchema,
+ getWebPageSchema,
+} from '@utils/helpers/schema-org';
import useBreadcrumb from '@utils/hooks/use-breadcrumb';
import useSettings from '@utils/hooks/use-settings';
import { GetStaticPaths, GetStaticProps } from 'next';
@@ -30,7 +35,6 @@ import { useRouter } from 'next/router';
import Script from 'next/script';
import { ParsedUrlQuery } from 'querystring';
import { useIntl } from 'react-intl';
-import { Article as ArticleSchema, Graph, WebPage } from 'schema-dts';
export type ThematicPageProps = {
currentThematic: Thematic;
@@ -58,45 +62,23 @@ const ThematicPage: NextPageWithLayout<ThematicPageProps> = ({
const { website } = useSettings();
const { asPath } = useRouter();
- const pageUrl = `${website.url}${asPath}`;
- const pagePublicationDate = new Date(dates.publication);
- const pageUpdateDate = dates.update ? new Date(dates.update) : undefined;
-
- const webpageSchema: WebPage = {
- '@id': `${pageUrl}`,
- '@type': 'WebPage',
- breadcrumb: { '@id': `${website.url}/#breadcrumb` },
- name: seo.title,
+ const webpageSchema = getWebPageSchema({
description: seo.description,
- inLanguage: website.locales.default,
- reviewedBy: { '@id': `${website.url}/#branding` },
- url: `${website.url}`,
- };
-
- const articleSchema: ArticleSchema = {
- '@id': `${website.url}/#thematic`,
- '@type': 'Article',
- name: title,
+ locale: website.locales.default,
+ slug: asPath,
+ title: seo.title,
+ updateDate: dates.update,
+ });
+ const articleSchema = getSinglePageSchema({
+ dates,
description: intro,
- author: { '@id': `${website.url}/#branding` },
- copyrightYear: pagePublicationDate.getFullYear(),
- creator: { '@id': `${website.url}/#branding` },
- dateCreated: pagePublicationDate.toISOString(),
- dateModified: pageUpdateDate && pageUpdateDate.toISOString(),
- datePublished: pagePublicationDate.toISOString(),
- editor: { '@id': `${website.url}/#branding` },
- headline: title,
- inLanguage: website.locales.default,
- isPartOf: { '@id': `${website.url}/blog` },
- license: 'https://creativecommons.org/licenses/by-sa/4.0/deed.fr',
- mainEntityOfPage: { '@id': `${pageUrl}` },
- subjectOf: { '@id': `${website.url}/blog` },
- };
-
- const schemaJsonLd: Graph = {
- '@context': 'https://schema.org',
- '@graph': [webpageSchema, articleSchema],
- };
+ id: 'thematic',
+ kind: 'page',
+ locale: website.locales.default,
+ slug: asPath,
+ title,
+ });
+ const schemaJsonLd = getSchemaJson([webpageSchema, articleSchema]);
const thematicsListTitle = intl.formatMessage({
defaultMessage: 'Other thematics',
@@ -115,7 +97,7 @@ const ThematicPage: NextPageWithLayout<ThematicPageProps> = ({
<Head>
<title>{seo.title}</title>
<meta name="description" content={seo.description} />
- <meta property="og:url" content={`${pageUrl}`} />
+ <meta property="og:url" content={`${website.url}${asPath}`} />
<meta property="og:type" content="article" />
<meta property="og:title" content={title} />
<meta property="og:description" content={intro} />