Skip to content

Commit bf5e208

Browse files
authored
feat: add structured data schema for blog posts to enhance SEO and rich snippets
1 parent 3d7b637 commit bf5e208

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

src/pages/blog/[...slug].astro

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,44 @@ const ogImage =
9696
post.data.image?.src ??
9797
new URL("/og-ai-growth-engineer.png", siteUrl).toString();
9898
99+
const blogPostingSchema: Record<string, unknown> = {
100+
"@context": "https://schema.org",
101+
"@type": "BlogPosting",
102+
headline: post.data.title,
103+
description: post.data.description,
104+
url: postUrl,
105+
datePublished: post.data.publishDate.toISOString(),
106+
dateModified: (post.data.updatedDate ?? post.data.publishDate).toISOString(),
107+
author: {
108+
"@type": "Person",
109+
name: post.data.author,
110+
url: siteUrl,
111+
sameAs: ["https://twitter.com/itsmeAvaab", "https://github.com/AR10Dev"],
112+
},
113+
publisher: {
114+
"@type": "Person",
115+
name: "Avaab Razzaq",
116+
url: siteUrl,
117+
},
118+
mainEntityOfPage: {
119+
"@type": "WebPage",
120+
"@id": postUrl,
121+
},
122+
keywords: post.data.tags.join(", "),
123+
articleSection: post.data.category,
124+
inLanguage: "en-US",
125+
...(post.data.readingTime && {
126+
timeRequired: `PT${post.data.readingTime}M`,
127+
}),
128+
...(post.data.image?.src && {
129+
image: {
130+
"@type": "ImageObject",
131+
url: new URL(post.data.image.src, siteUrl).toString(),
132+
description: post.data.image.alt,
133+
},
134+
}),
135+
};
136+
99137
// Format date helper
100138
function formatDate(date: Date): string {
101139
return new Intl.DateTimeFormat("en-US", {
@@ -112,6 +150,10 @@ const readingTimeString = `${readingTimeMinutes} ${readingTimeMinutes === 1 ? "m
112150
113151
// Build the structured data graph
114152
const structuredDataGraph: Record<string, unknown>[] = [
153+
{
154+
...blogPostingSchema,
155+
"@context": undefined,
156+
},
115157
{
116158
"@type": "WebSite",
117159
"@id": `${siteUrl}/#website`,

0 commit comments

Comments
 (0)