Skip to content

Commit 646ab80

Browse files
authored
feat: add article metadata for improved SEO and structured data compliance
1 parent 76321ca commit 646ab80

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

src/layouts/BaseLayout.astro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ const currentPath = Astro.url.pathname;
8686
structuredData={structuredData}
8787
/>
8888

89+
<slot name="head" />
90+
8991
{publishedTime && <meta property="article:published_time" content={publishedTime} />}
9092
{publishedTime && <meta property="article:author" content={author} />}
9193
{modifiedTime && <meta property="article:modified_time" content={modifiedTime} />}

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ const wordCount = (post.body ?? "").split(/\s+/).filter(Boolean).length;
148148
const readingTimeMinutes = post.data.readingTime || Math.ceil(wordCount / 200);
149149
const readingTimeString = `${readingTimeMinutes} ${readingTimeMinutes === 1 ? "minute" : "minutes"}`;
150150
151+
const publishedTimeISO = post.data.publishDate
152+
? new Date(post.data.publishDate).toISOString()
153+
: null;
154+
155+
const modifiedTimeISO = post.data.updatedDate
156+
? new Date(post.data.updatedDate).toISOString()
157+
: publishedTimeISO;
158+
159+
const articleAuthorUrl = "https://avaabrazzaq.com/about/";
160+
const articleSection = post.data.category ?? "AI & Technology";
161+
151162
// Build the structured data graph
152163
const structuredDataGraph: Record<string, unknown>[] = [
153164
{
@@ -283,12 +294,14 @@ const structuredData = {
283294
canonicalUrl={canonicalUrl}
284295
ogImage={ogImage}
285296
ogType="article"
286-
publishedTime={post.data.publishDate.toISOString()}
287-
modifiedTime={post.data.updatedDate?.toISOString()}
288-
author={post.data.author}
297+
publishedTime={publishedTimeISO ?? undefined}
298+
modifiedTime={modifiedTimeISO ?? undefined}
299+
author={articleAuthorUrl}
289300
readingTime={readingTimeString}
290301
structuredData={structuredData}
291302
>
303+
<meta slot="head" property="article:section" content={articleSection} />
304+
292305
<article class="min-h-screen py-12">
293306
<div class={CONTAINER_CLASSES.section}>
294307
<div class="mx-auto max-w-3xl">
@@ -319,15 +332,6 @@ const structuredData = {
319332
</div>
320333

321334
<!-- Title -->
322-
<h1 class={`${TYPOGRAPHY_CLASSES.heroTitle} mb-6`}>
323-
{post.data.title}
324-
</h1>
325-
326-
<!-- Description -->
327-
<p class={`${TYPOGRAPHY_CLASSES.subheading} mb-8`}>
328-
{post.data.description}
329-
</p>
330-
331335
<!-- Meta Info -->
332336
<div class="flex flex-wrap items-center gap-4 text-sm text-[var(--text-base)] border-t border-b border-[var(--border-base)] py-4">
333337
<div class="flex items-center gap-2">

0 commit comments

Comments
 (0)