diff --git a/src/components/PostList.astro b/src/components/PostList.astro index e31c84e..70d82a3 100644 --- a/src/components/PostList.astro +++ b/src/components/PostList.astro @@ -1,15 +1,17 @@ --- -import { getVisibleTags, renderMarkdown, extractFirstImage } from '../lib/markdown.js'; const { posts, tag } = Astro.props; -const visible = getVisibleTags(); -// Pre-compute first cover image per post (from rendered body) so the listing -// can show a real photo on the left without re-parsing inside the template. +// 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: extractFirstImage(renderMarkdown(p.body)), + cover: firstImage(p.body), })); - const hero = enriched[0]; const rest = enriched.slice(1); @@ -18,12 +20,11 @@ const fmt = (d) => new Date(d).toLocaleDateString('en-US', --- {tag && (

- 栏目 Tagged: {tag}

)} -{enriched.length > 0 && !tag && ( +{enriched.length > 0 && !tag && hero && (
{hero.cover && ( @@ -32,13 +33,13 @@ const fmt = (d) => new Date(d).toLocaleDateString('en-US', )}
-
头条 · TOP STORY
+
Top story

{hero.title}

{hero.rawExcerpt}

{fmt(hero.date)} - {hero.tags.filter((t) => visible.has(t)).slice(0, 4).map((t) => ( - {t} + {hero.tags.slice(0, 4).map((t) => ( + {t} ))}
@@ -47,7 +48,7 @@ const fmt = (d) => new Date(d).toLocaleDateString('en-US', )} {(tag ? enriched : rest).map((post, i) => ( -
+
{post.cover && (
@@ -59,8 +60,8 @@ const fmt = (d) => new Date(d).toLocaleDateString('en-US',

{post.rawExcerpt}

- {post.tags.filter((t) => visible.has(t)).slice(0, 3).map((t) => ( - {t} + {post.tags.slice(0, 3).map((t) => ( + {t} ))}
@@ -69,11 +70,10 @@ const fmt = (d) => new Date(d).toLocaleDateString('en-US', ))} {enriched.length === 0 && ( -

尚无文章 · No posts yet.

+

No posts yet.

)}