{hero.title}
{hero.rawExcerpt}
{post.rawExcerpt}
尚无文章 · No posts yet.
+No posts yet.
)}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 && (
{hero.rawExcerpt}
{post.rawExcerpt}
尚无文章 · No posts yet.
+No posts yet.
)}