--- export const prerender = false; import { search } from "emdash"; import Base from "../layouts/Base.astro"; const query = Astro.url.searchParams.get("q")?.trim() || ""; // Use the FTS-backed search() API instead of loading every post and // filtering in JS. FTS scales as the post count grows, returns ranked // results, and handles tokenization/stemming. Templates that grep all // post bodies in JS quickly become unusable past a few hundred posts. const { items: results } = query ? await search(query, { collections: ["posts"], limit: 30 }) : { items: [] }; ---

Search

{ query && (

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

) } { results.length > 0 && (
    {results.map((result) => (
  1. {result.title ?? "Untitled"}

    {result.snippet && (

    )}

  2. ))}
) } {!query &&

Enter a search term to find posts.

}