--- export const prerender = false; import { getEmDashCollection } from "emdash"; import Base from "../layouts/Base.astro"; import PostCard from "../components/PostCard.astro"; import { getReadingTime, extractText } from "../utils/reading-time"; const query = Astro.url.searchParams.get("q")?.trim() || ""; const { entries: allPosts } = await getEmDashCollection("posts"); // Simple search: match query against title, excerpt, and content function matchesQuery(post: (typeof allPosts)[0], q: string): boolean { if (!q) return false; const lower = q.toLowerCase(); const title = (post.data.title || "").toLowerCase(); const excerpt = (post.data.excerpt || "").toLowerCase(); // Extract plain text from portable text blocks (avoids matching on _type, _key, etc.) const content = extractText(post.data.content).toLowerCase(); return ( title.includes(lower) || excerpt.includes(lower) || content.includes(lower) ); } const results = query ? allPosts.filter((p) => matchesQuery(p, query)) : []; ---

Search

{ query && (

{results.length === 0 ? `No results for "${query}"` : `${results.length} result${results.length === 1 ? "" : "s"} for "${query}"`}

) } { results.length > 0 && (
{results.map((post) => ( ))}
) } {!query &&

Enter a search term to find posts.

}