- {post.title} -
- -{post.rawExcerpt}
+// Extract first cover image directly from the raw markdown body. +// Cheap regex — avoids rendering the full HTML for each card. +function firstImage(body) { + const m = body && body.match(/!\[[^\]]*\]\((\/images\/[^)]+)\)/); + return m ? m[1] : null; +} + +const enriched = posts.map((p) => ({ + ...p, + cover: firstImage(p.body), +})); +const hero = enriched[0]; +const rest = enriched.slice(1); + +const fmt = (d) => new Date(d).toLocaleDateString('en-US', + { year: 'numeric', month: 'long', day: 'numeric' }); +--- +{tag && ( ++ Tagged: {tag} +
+)} + +{enriched.length > 0 && !tag && hero && ( +
+
+
+ )}
+
+
+
+ Top story
+ {hero.title}
+{hero.rawExcerpt}
+ +
+
+
+ )}
+
+
+
{post.title}
+{post.rawExcerpt}
+ +No posts yet.
+{enriched.length === 0 && ( +No posts yet.
)} + + diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index e073901..d84b74f 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -46,21 +46,25 @@ const year = new Date().getFullYear(); - +