Add JSON-LD with Article structured data support

This commit is contained in:
Ahmad Al Maaz 2021-06-24 19:38:56 +03:00
parent cbaade5c7e
commit 9c1299dcfe
3 changed files with 32 additions and 1 deletions

View File

@ -24,7 +24,7 @@ export const PageSeo = ({ title, description }) => {
)
}
export const BlogSeo = ({ title, summary, date, lastmod, images = [] }) => {
export const BlogSeo = ({ title, summary, date, lastmod, url, images = [] }) => {
const router = useRouter()
const publishedAt = new Date(date).toISOString()
const modifiedAt = new Date(lastmod || date).toISOString()
@ -42,6 +42,32 @@ export const BlogSeo = ({ title, summary, date, lastmod, images = [] }) => {
}
})
const structuredData = {
'@context': 'https://schema.org',
'@type': 'Article',
mainEntityOfPage: {
'@type': 'WebPage',
'@id': url,
},
headline: title,
image: featuredImages,
datePublished: publishedAt,
dateModified: modifiedAt,
author: {
'@type': 'Person',
name: siteMetadata.author,
},
publisher: {
'@type': 'Organization',
name: siteMetadata.author,
logo: {
'@type': 'ImageObject',
url: `${siteMetadata.siteUrl}${siteMetadata.siteLogo}`,
},
},
description: summary,
}
return (
<>
<Head>
@ -64,6 +90,10 @@ export const BlogSeo = ({ title, summary, date, lastmod, images = [] }) => {
{date && <meta property="article:published_time" content={publishedAt} />}
{lastmod && <meta property="article:modified_time" content={modifiedAt} />}
<link rel="canonical" href={`${siteMetadata.siteUrl}${router.asPath}`} />
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(structuredData, null, 2) }}
/>
</Head>
</>
)

View File

@ -6,6 +6,7 @@
"language": "en-us",
"siteUrl": "https://tailwind-nextjs-starter-blog.vercel.app",
"siteRepo": "https://github.com/timlrx/tailwind-nextjs-starter-blog",
"siteLogo": "/static/images/logo.png",
"image": "/static/images/avatar.png",
"socialBanner": "/static/images/twitter-card.png",
"email": "address@yoursite.com",

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB