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/blog/index.tsx | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/pages/blog') diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx index 48fab1c..765a93b 100644 --- a/src/pages/blog/index.tsx +++ b/src/pages/blog/index.tsx @@ -17,9 +17,12 @@ import Sidebar from '@components/Sidebar/Sidebar'; import styles from '@styles/pages/Page.module.scss'; import { useRef } from 'react'; import Spinner from '@components/Spinner/Spinner'; +import { Blog as BlogSchema, Graph, WebPage } from 'schema-dts'; +import { useRouter } from 'next/router'; const Blog: NextPageWithLayout = ({ fallback }) => { const lastPostRef = useRef(null); + const router = useRouter(); const getKey = (pageIndex: number, previousData: PostsListData) => { if (previousData && !previousData.posts) return null; @@ -59,13 +62,48 @@ const Blog: NextPageWithLayout = ({ fallback }) => { return ; }; + const webpageSchema: WebPage = { + '@id': `${config.url}${router.asPath}`, + '@type': 'WebPage', + breadcrumb: { '@id': `${config.url}/#breadcrumb` }, + name: seo.blog.title, + description: seo.blog.description, + inLanguage: config.defaultLocale, + reviewedBy: { '@id': `${config.url}/#branding` }, + url: `${config.url}`, + isPartOf: { + '@id': `${config.url}`, + }, + }; + + const blogSchema: BlogSchema = { + '@id': `${config.url}/#blog`, + '@type': 'Blog', + 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, blogSchema], + }; + return ( <> {seo.blog.title} +
-- cgit v1.2.3