diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-23 19:02:20 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-05-23 19:02:20 +0200 |
| commit | 5ebd7c14f7303a0feb8ec1d902ecd0e287d929c3 (patch) | |
| tree | 4e0e0352ac7598fa4e186230e93bcc4c1ac6b810 /src/pages/recherche/index.tsx | |
| parent | 34e216546151eaf8a0a3cbb0bc8b65dae4c63bf2 (diff) | |
refactor(schema): use helpers function to avoid repeat between pages
Diffstat (limited to 'src/pages/recherche/index.tsx')
| -rw-r--r-- | src/pages/recherche/index.tsx | 49 |
1 files changed, 17 insertions, 32 deletions
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<SearchPageProps> = ({ }, { 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<SearchPageProps> = ({ <Head> <title>{pageTitle}</title> <meta name="description" content={pageDescription} /> - <meta property="og:url" content={`${pageUrl}`} /> + <meta property="og:url" content={`${website.url}${asPath}`} /> <meta property="og:type" content="website" /> <meta property="og:title" content={title} /> <meta property="og:description" content={pageDescription} /> |
