From 5ebd7c14f7303a0feb8ec1d902ecd0e287d929c3 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Mon, 23 May 2022 19:02:20 +0200 Subject: refactor(schema): use helpers function to avoid repeat between pages --- src/pages/recherche/index.tsx | 49 +++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) (limited to 'src/pages/recherche/index.tsx') diff --git a/src/pages/recherche/index.tsx b/src/pages/recherche/index.tsx index c69d931..ab619fb 100644 --- a/src/pages/recherche/index.tsx +++ b/src/pages/recherche/index.tsx @@ -22,6 +22,11 @@ import { getPageLinkFromRawData, getPostsList, } from '@utils/helpers/pages'; +import { + getBlogSchema, + getSchemaJson, + getWebPageSchema, +} from '@utils/helpers/schema-org'; import useBreadcrumb from '@utils/hooks/use-breadcrumb'; import useDataFromAPI from '@utils/hooks/use-data-from-api'; import usePagination from '@utils/hooks/use-pagination'; @@ -31,7 +36,6 @@ import Head from 'next/head'; import { useRouter } from 'next/router'; import Script from 'next/script'; import { useIntl } from 'react-intl'; -import { Blog, Graph, WebPage } from 'schema-dts'; type SearchPageProps = { thematicsList: RawThematicPreview[]; @@ -87,37 +91,18 @@ const SearchPage: NextPageWithLayout = ({ }, { websiteName: website.name } ); - const pageUrl = `${website.url}${asPath}`; - - const webpageSchema: WebPage = { - '@id': `${pageUrl}`, - '@type': 'WebPage', - breadcrumb: { '@id': `${website.url}/#breadcrumb` }, - name: pageTitle, + const webpageSchema = getWebPageSchema({ description: pageDescription, - inLanguage: website.locales.default, - reviewedBy: { '@id': `${website.url}/#branding` }, - url: `${website.url}`, - isPartOf: { - '@id': `${website.url}`, - }, - }; - - const blogSchema: Blog = { - '@id': `${website.url}/#blog`, - '@type': 'Blog', - author: { '@id': `${website.url}/#branding` }, - creator: { '@id': `${website.url}/#branding` }, - editor: { '@id': `${website.url}/#branding` }, - inLanguage: website.locales.default, - license: 'https://creativecommons.org/licenses/by-sa/4.0/deed.fr', - mainEntityOfPage: { '@id': `${pageUrl}` }, - }; - - const schemaJsonLd: Graph = { - '@context': 'https://schema.org', - '@graph': [webpageSchema, blogSchema], - }; + locale: website.locales.default, + slug: asPath, + title: pageTitle, + }); + const blogSchema = getBlogSchema({ + isSinglePage: false, + locale: website.locales.default, + slug: asPath, + }); + const schemaJsonLd = getSchemaJson([webpageSchema, blogSchema]); const { data, @@ -161,7 +146,7 @@ const SearchPage: NextPageWithLayout = ({ {pageTitle} - + -- cgit v1.2.3