From a26b775b7bbf1abd3e99c8bf9ce4c7522d3a0adc Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Wed, 19 Jan 2022 13:56:34 +0100 Subject: chore: add structured data using schema.org and JSON-LD I also added the featured image on single article. --- src/pages/contact.tsx | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/pages/contact.tsx') 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 ( <> {seo.contact.title} +
-- cgit v1.2.3