|
| 1 | +--- |
| 2 | +import { getCollection, type CollectionEntry } from 'astro:content'; |
| 3 | +import Layout from '@layouts/Layout.astro'; |
| 4 | +import { TYPOGRAPHY_CLASSES } from '@lib/constants'; |
| 5 | +
|
| 6 | +export async function getStaticPaths() { |
| 7 | + const blogPosts = await getCollection('blog', ({ data }) => { |
| 8 | + return data.draft !== true; |
| 9 | + }); |
| 10 | + |
| 11 | + return blogPosts.map(post => ({ |
| 12 | + params: { slug: post.id }, |
| 13 | + props: { post }, |
| 14 | + })); |
| 15 | +} |
| 16 | +
|
| 17 | +interface Props { |
| 18 | + post: CollectionEntry<'blog'>; |
| 19 | +} |
| 20 | +
|
| 21 | +const { post } = Astro.props; |
| 22 | +const { Content, headings } = await post.render(); |
| 23 | +
|
| 24 | +const title = `${post.data.title} | Avaab Razzaq`; |
| 25 | +const description = post.data.description; |
| 26 | +const canonicalUrl = new URL(Astro.url.pathname, Astro.site).toString(); |
| 27 | +
|
| 28 | +// Format date helper |
| 29 | +function formatDate(date: Date): string { |
| 30 | + return new Intl.DateTimeFormat('en-US', { |
| 31 | + year: 'numeric', |
| 32 | + month: 'long', |
| 33 | + day: 'numeric' |
| 34 | + }).format(date); |
| 35 | +} |
| 36 | +
|
| 37 | +// Calculate reading time if not in frontmatter |
| 38 | +const readingTime = post.data.readingTime || (() => { |
| 39 | + const wordsPerMinute = 200; |
| 40 | + const content = post.body; |
| 41 | + const wordCount = content.split(/\s+/).length; |
| 42 | + return Math.ceil(wordCount / wordsPerMinute); |
| 43 | +})(); |
| 44 | +
|
| 45 | +// Structured data for blog post |
| 46 | +const structuredData = { |
| 47 | + "@context": "https://schema.org", |
| 48 | + "@type": "BlogPosting", |
| 49 | + "headline": post.data.title, |
| 50 | + "description": post.data.description, |
| 51 | + "author": { |
| 52 | + "@type": "Person", |
| 53 | + "name": post.data.author, |
| 54 | + "url": "https://ar10dev.github.io" |
| 55 | + }, |
| 56 | + "datePublished": post.data.publishDate.toISOString(), |
| 57 | + ...(post.data.updatedDate && { "dateModified": post.data.updatedDate.toISOString() }), |
| 58 | + ...(post.data.image && { |
| 59 | + "image": { |
| 60 | + "@type": "ImageObject", |
| 61 | + "url": post.data.image.src, |
| 62 | + "caption": post.data.image.alt |
| 63 | + } |
| 64 | + }), |
| 65 | + "publisher": { |
| 66 | + "@type": "Person", |
| 67 | + "name": "Avaab Razzaq" |
| 68 | + }, |
| 69 | + "mainEntityOfPage": { |
| 70 | + "@type": "WebPage", |
| 71 | + "@id": canonicalUrl |
| 72 | + }, |
| 73 | + "keywords": post.data.tags.join(", "), |
| 74 | + "articleSection": post.data.category |
| 75 | +}; |
| 76 | +--- |
| 77 | + |
| 78 | +<Layout |
| 79 | + title={title} |
| 80 | + description={description} |
| 81 | + canonicalUrl={canonicalUrl} |
| 82 | + ogType="article" |
| 83 | + ogImage={post.data.image?.src} |
| 84 | +> |
| 85 | + <article class="min-h-screen bg-[var(--bg-canvas)] py-20 px-6"> |
| 86 | + <div class="mx-auto max-w-3xl"> |
| 87 | + |
| 88 | + <!-- Back to Blog Link --> |
| 89 | + <a |
| 90 | + href="/blog/" |
| 91 | + class="inline-flex items-center gap-2 text-[var(--accent-strong)] hover:underline mb-8 group" |
| 92 | + > |
| 93 | + <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="group-hover:-translate-x-1 transition-transform"> |
| 94 | + <path d="M19 12H5M12 19l-7-7 7-7"/> |
| 95 | + </svg> |
| 96 | + Back to Blog |
| 97 | + </a> |
| 98 | + |
| 99 | + <!-- Article Header --> |
| 100 | + <header class="mb-12"> |
| 101 | + <!-- Category Badge --> |
| 102 | + <div class="mb-4"> |
| 103 | + <span class="inline-block px-3 py-1 text-sm font-semibold rounded-full bg-[var(--accent-alpha)] text-[var(--accent-strong)] border border-[var(--accent-strong)]"> |
| 104 | + {post.data.category} |
| 105 | + </span> |
| 106 | + </div> |
| 107 | + |
| 108 | + <!-- Title --> |
| 109 | + <h1 class={`${TYPOGRAPHY_CLASSES.heroTitle} mb-6`}> |
| 110 | + {post.data.title} |
| 111 | + </h1> |
| 112 | + |
| 113 | + <!-- Description --> |
| 114 | + <p class={`${TYPOGRAPHY_CLASSES.subheading} mb-8`}> |
| 115 | + {post.data.description} |
| 116 | + </p> |
| 117 | + |
| 118 | + <!-- Meta Info --> |
| 119 | + <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"> |
| 120 | + <div class="flex items-center gap-2"> |
| 121 | + <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> |
| 122 | + <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path> |
| 123 | + <circle cx="12" cy="7" r="4"></circle> |
| 124 | + </svg> |
| 125 | + <span>{post.data.author}</span> |
| 126 | + </div> |
| 127 | + |
| 128 | + <div class="flex items-center gap-2"> |
| 129 | + <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> |
| 130 | + <rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect> |
| 131 | + <line x1="16" y1="2" x2="16" y2="6"></line> |
| 132 | + <line x1="8" y1="2" x2="8" y2="6"></line> |
| 133 | + <line x1="3" y1="10" x2="21" y2="10"></line> |
| 134 | + </svg> |
| 135 | + <time datetime={post.data.publishDate.toISOString()}> |
| 136 | + {formatDate(post.data.publishDate)} |
| 137 | + </time> |
| 138 | + </div> |
| 139 | + |
| 140 | + {post.data.updatedDate && ( |
| 141 | + <div class="flex items-center gap-2"> |
| 142 | + <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> |
| 143 | + <polyline points="23 4 23 10 17 10"></polyline> |
| 144 | + <path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"></path> |
| 145 | + </svg> |
| 146 | + <span>Updated {formatDate(post.data.updatedDate)}</span> |
| 147 | + </div> |
| 148 | + )} |
| 149 | + |
| 150 | + <div class="flex items-center gap-2"> |
| 151 | + <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> |
| 152 | + <circle cx="12" cy="12" r="10"></circle> |
| 153 | + <polyline points="12 6 12 12 16 14"></polyline> |
| 154 | + </svg> |
| 155 | + <span>{readingTime} min read</span> |
| 156 | + </div> |
| 157 | + </div> |
| 158 | + |
| 159 | + <!-- Featured Image --> |
| 160 | + {post.data.image && ( |
| 161 | + <div class="mt-8 overflow-hidden rounded-lg aspect-video bg-[var(--surface-strong)]"> |
| 162 | + <img |
| 163 | + src={post.data.image.src} |
| 164 | + alt={post.data.image.alt} |
| 165 | + class="w-full h-full object-cover" |
| 166 | + loading="eager" |
| 167 | + /> |
| 168 | + </div> |
| 169 | + )} |
| 170 | + </header> |
| 171 | + |
| 172 | + <!-- Table of Contents (if headings exist) --> |
| 173 | + {headings.length > 0 && ( |
| 174 | + <aside class="mb-12 p-6 rounded-lg bg-[var(--surface-panel)] border border-[var(--border-base)]"> |
| 175 | + <h2 class="text-lg font-bold text-[var(--text-strong)] mb-4">Table of Contents</h2> |
| 176 | + <nav> |
| 177 | + <ul class="space-y-2"> |
| 178 | + {headings.map((heading) => ( |
| 179 | + <li style={`margin-left: ${(heading.depth - 1) * 1}rem`}> |
| 180 | + <a |
| 181 | + href={`#${heading.slug}`} |
| 182 | + class="text-[var(--text-base)] hover:text-[var(--accent-strong)] transition-colors" |
| 183 | + > |
| 184 | + {heading.text} |
| 185 | + </a> |
| 186 | + </li> |
| 187 | + ))} |
| 188 | + </ul> |
| 189 | + </nav> |
| 190 | + </aside> |
| 191 | + )} |
| 192 | + |
| 193 | + <!-- Article Content --> |
| 194 | + <div class="prose prose-invert prose-lg max-w-none |
| 195 | + prose-headings:text-[var(--text-strong)] prose-headings:font-bold prose-headings:scroll-mt-20 |
| 196 | + prose-h2:text-3xl prose-h2:mt-12 prose-h2:mb-6 |
| 197 | + prose-h3:text-2xl prose-h3:mt-8 prose-h3:mb-4 |
| 198 | + prose-p:text-[var(--text-base)] prose-p:leading-relaxed prose-p:mb-6 |
| 199 | + prose-a:text-[var(--accent-strong)] prose-a:no-underline hover:prose-a:underline |
| 200 | + prose-strong:text-[var(--text-strong)] prose-strong:font-semibold |
| 201 | + prose-code:text-[var(--accent-strong)] prose-code:bg-[var(--surface-strong)] prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-code:before:content-[''] prose-code:after:content-[''] |
| 202 | + prose-pre:bg-[var(--surface-strong)] prose-pre:border prose-pre:border-[var(--border-base)] prose-pre:rounded-lg |
| 203 | + prose-ul:text-[var(--text-base)] prose-ul:mb-6 |
| 204 | + prose-ol:text-[var(--text-base)] prose-ol:mb-6 |
| 205 | + prose-li:mb-2 |
| 206 | + prose-blockquote:border-l-4 prose-blockquote:border-[var(--accent-strong)] prose-blockquote:pl-6 prose-blockquote:italic prose-blockquote:text-[var(--text-base)] |
| 207 | + prose-img:rounded-lg prose-img:shadow-lg |
| 208 | + "> |
| 209 | + <Content /> |
| 210 | + </div> |
| 211 | + |
| 212 | + <!-- Tags --> |
| 213 | + {post.data.tags.length > 0 && ( |
| 214 | + <div class="mt-12 pt-8 border-t border-[var(--border-base)]"> |
| 215 | + <h3 class="text-sm font-semibold text-[var(--text-base)] mb-4">Tags:</h3> |
| 216 | + <div class="flex flex-wrap gap-2"> |
| 217 | + {post.data.tags.map(tag => ( |
| 218 | + <span class="px-3 py-1 text-sm rounded-full bg-[var(--surface-panel)] text-[var(--text-base)] border border-[var(--border-base)]"> |
| 219 | + #{tag} |
| 220 | + </span> |
| 221 | + ))} |
| 222 | + </div> |
| 223 | + </div> |
| 224 | + )} |
| 225 | + |
| 226 | + <!-- Share & CTA Section --> |
| 227 | + <div class="mt-16 p-8 rounded-lg bg-[var(--surface-panel)] border border-[var(--border-base)] text-center"> |
| 228 | + <h3 class={`${TYPOGRAPHY_CLASSES.sectionTitle} mb-4`}> |
| 229 | + Found this helpful? |
| 230 | + </h3> |
| 231 | + <p class={`${TYPOGRAPHY_CLASSES.body} mb-6`}> |
| 232 | + Let's work together on your next project. I specialize in AI automation, growth engineering, and full-stack development. |
| 233 | + </p> |
| 234 | + <a |
| 235 | + href="/#contact" |
| 236 | + class="inline-block px-6 py-3 rounded-lg bg-[var(--accent-strong)] text-white font-semibold hover:bg-[var(--accent-base)] transition-colors" |
| 237 | + > |
| 238 | + Get in Touch |
| 239 | + </a> |
| 240 | + </div> |
| 241 | + |
| 242 | + </div> |
| 243 | + </article> |
| 244 | + |
| 245 | + <!-- Structured Data --> |
| 246 | + <script type="application/ld+json" is:inline set:html={JSON.stringify(structuredData)} /> |
| 247 | +</Layout> |
0 commit comments