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/contact.tsx | |
| parent | 34e216546151eaf8a0a3cbb0bc8b65dae4c63bf2 (diff) | |
refactor(schema): use helpers function to avoid repeat between pages
Diffstat (limited to 'src/pages/contact.tsx')
| -rw-r--r-- | src/pages/contact.tsx | 60 |
1 files changed, 22 insertions, 38 deletions
diff --git a/src/pages/contact.tsx b/src/pages/contact.tsx index c0d6c79..2392fe2 100644 --- a/src/pages/contact.tsx +++ b/src/pages/contact.tsx @@ -6,10 +6,15 @@ import SocialMedia from '@components/organisms/widgets/social-media'; import { getLayout } from '@components/templates/layout/layout'; import PageLayout from '@components/templates/page/page-layout'; import { meta } from '@content/pages/contact.mdx'; -import styles from '@styles/pages/contact.module.scss'; import { sendMail } from '@services/graphql/contact'; +import styles from '@styles/pages/contact.module.scss'; import { type NextPageWithLayout } from '@ts/types/app'; import { loadTranslation } from '@utils/helpers/i18n'; +import { + getSchemaJson, + getSinglePageSchema, + getWebPageSchema, +} from '@utils/helpers/schema-org'; import useBreadcrumb from '@utils/hooks/use-breadcrumb'; import useSettings from '@utils/hooks/use-settings'; import { GetStaticProps } from 'next'; @@ -18,7 +23,6 @@ import { useRouter } from 'next/router'; import Script from 'next/script'; import { useState } from 'react'; import { useIntl } from 'react-intl'; -import { ContactPage as ContactPageSchema, Graph, WebPage } from 'schema-dts'; const ContactPage: NextPageWithLayout = () => { const { dates, intro, seo, title } = meta; @@ -36,43 +40,23 @@ const ContactPage: NextPageWithLayout = () => { 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, - reviewedBy: { '@id': `${website.url}/#branding` }, - url: `${pageUrl}`, - isPartOf: { - '@id': `${website.url}`, - }, - }; - - const contactSchema: ContactPageSchema = { - '@id': `${website.url}/#contact`, - '@type': 'ContactPage', - name: title, + locale: website.locales.default, + slug: asPath, + title: seo.title, + updateDate: dates.update, + }); + const contactSchema = getSinglePageSchema({ + dates, description: intro, - author: { '@id': `${website.url}/#branding` }, - creator: { '@id': `${website.url}/#branding` }, - dateCreated: pagePublicationDate.toISOString(), - dateModified: pageUpdateDate && pageUpdateDate.toISOString(), - datePublished: pagePublicationDate.toISOString(), - 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, contactSchema], - }; + id: 'contact', + kind: 'contact', + locale: website.locales.default, + slug: asPath, + title, + }); + const schemaJsonLd = getSchemaJson([webpageSchema, contactSchema]); const widgets = [ <SocialMedia @@ -134,7 +118,7 @@ const ContactPage: NextPageWithLayout = () => { <Head> <title>{`${seo.title} - ${website.name}`}</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} /> |
