Created
August 3, 2023 14:38
-
-
Save debpu06/f8805c3ad008ef60bb3072d724d9912b to your computer and use it in GitHub Desktop.
Example of adding schema markup to blog post.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SITE_OWNER_GITHUB, SITE_OWNER_LINKEDIN, SITE_OWNER_TWITTER, SITE_OWNER, SITE_URL } from '../../lib/constants' | |
export default function PostSchema({ post }) { | |
const url = post.canonicalUrl !== undefined && post.canonicalUrl !== null ? post.canonicalUrl : `${SITE_URL}/blog/${post.slug}`; | |
return ( | |
<script | |
defer | |
type="application/ld+json" | |
className="yoast-schema-graph yoast-schema-graph--main" | |
> | |
{` | |
{ | |
"@context": "https://schema.org", | |
"@type": "BlogPosting", | |
"mainEntityOfPage": { | |
"@type": "WebPage", | |
"@id": "${url}" | |
}, | |
"headline": "${post.title}", | |
"image": [ | |
"${post.metaImage != null ? post.metaImage.url : null}" | |
], | |
"datePublished": "${post.publishDate}", | |
"dateModified": "${post.updatedAt}", | |
"author": { | |
"@type": "Person", | |
"name": "${post.author.name}", | |
"url": "${SITE_URL}/author/${post.author.slug}", | |
"@id":"${SITE_URL}/author/${post.author.slug}#person", | |
"sameAs": | |
[ | |
"${post.author.twitter}", | |
"${post.author.github}", | |
"${post.author.linkedin}" | |
] | |
}, | |
"publisher": { | |
"@type": "Person", | |
"name": "${SITE_OWNER}", | |
"sameAs": | |
[ | |
"https://twitter.com/${SITE_OWNER_TWITTER}", | |
"https://github.com/${SITE_OWNER_GITHUB}", | |
"https://www.linkedin.com/in/${SITE_OWNER_LINKEDIN}/", | |
"${SITE_URL}/about" | |
] | |
} | |
} | |
`} | |
</script> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment