Skip to content

Instantly share code, notes, and snippets.

@debpu06
Created August 3, 2023 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debpu06/f8805c3ad008ef60bb3072d724d9912b to your computer and use it in GitHub Desktop.
Save debpu06/f8805c3ad008ef60bb3072d724d9912b to your computer and use it in GitHub Desktop.
Example of adding schema markup to blog post.
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