diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-01-19 13:56:34 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-01-19 14:22:28 +0100 |
| commit | a26b775b7bbf1abd3e99c8bf9ce4c7522d3a0adc (patch) | |
| tree | 7f041845fa64d00f20f949d1cba14fec3eca3435 /src/pages/contact.tsx | |
| parent | 813084fc23113ae2f594bf6ef1cf53bd003c9479 (diff) | |
chore: add structured data using schema.org and JSON-LD
I also added the featured image on single article.
Diffstat (limited to 'src/pages/contact.tsx')
| -rw-r--r-- | src/pages/contact.tsx | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/pages/contact.tsx b/src/pages/contact.tsx index bafa5e9..ba462c0 100644 --- a/src/pages/contact.tsx +++ b/src/pages/contact.tsx @@ -13,6 +13,9 @@ import PostHeader from '@components/PostHeader/PostHeader'; import styles from '@styles/pages/Page.module.scss'; import { SocialMedia } from '@components/Widgets'; import Sidebar from '@components/Sidebar/Sidebar'; +import { ContactPage as ContactPageSchema, Graph, WebPage } from 'schema-dts'; +import { config } from '@config/website'; +import { useRouter } from 'next/router'; const ContactPage: NextPageWithLayout = () => { const [name, setName] = useState(''); @@ -20,6 +23,7 @@ const ContactPage: NextPageWithLayout = () => { const [subject, setSubject] = useState(''); const [message, setMessage] = useState(''); const [status, setStatus] = useState(''); + const router = useRouter(); const resetForm = () => { setName(''); @@ -55,13 +59,49 @@ const ContactPage: NextPageWithLayout = () => { const title = t`Contact`; const intro = t`Please fill the form to contact me.`; + const webpageSchema: WebPage = { + '@id': `${config.url}${router.asPath}`, + '@type': 'WebPage', + breadcrumb: { '@id': `${config.url}/#breadcrumb` }, + name: seo.contact.title, + description: seo.contact.description, + reviewedBy: { '@id': `${config.url}/#branding` }, + url: `${config.url}${router.asPath}`, + isPartOf: { + '@id': `${config.url}`, + }, + }; + + const contactSchema: ContactPageSchema = { + '@id': `${config.url}/#contact`, + '@type': 'ContactPage', + name: title, + description: intro, + author: { '@id': `${config.url}/#branding` }, + creator: { '@id': `${config.url}/#branding` }, + editor: { '@id': `${config.url}/#branding` }, + inLanguage: config.defaultLocale, + license: 'https://creativecommons.org/licenses/by-sa/4.0/deed.fr', + mainEntityOfPage: { '@id': `${config.url}${router.asPath}` }, + }; + + const schemaJsonLd: Graph = { + '@context': 'https://schema.org', + '@graph': [webpageSchema, contactSchema], + }; + return ( <> <Head> <title>{seo.contact.title}</title> <meta name="description" content={seo.contact.description} /> + <script + type="application/ld+json" + dangerouslySetInnerHTML={{ __html: JSON.stringify(schemaJsonLd) }} + ></script> </Head> <article + id="contact" className={`${styles.article} ${styles['article--no-comments']}`} > <PostHeader title={title} intro={intro} /> |
