Today I learned that Pagefind, by default, indexes the entire body
of every page in your dist/ output. That includes your header, your
footer, your “Skip to content” accessibility link, and any
sticky-on-every-page promo bar.
So if you search “newsletter” on a Pagefind-indexed site, every page shows up as a match — because every page has the footer newsletter signup.
The fix is one HTML attribute: data-pagefind-body on the <main> (or
<article>) element. Pagefind then ONLY indexes content inside that
element.
<main data-pagefind-body>
<!-- the page content -->
</main>
While you’re at it:
data-pagefind-meta="author"to surface the author in result snippets.data-pagefind-filter="category"to enable category filtering in search.data-pagefind-ignoreon anything you want to exclude (callouts, ads, etc.)
Time-to-correct-results dropped from “everywhere” to “exactly where the phrase actually appears in body content.” Worth the 20 minutes.