Static Search with Pagefind
Integrating Pagefind for full-text search on a static site with no backend.
Tags
Context
Lessons Hub is a fully static site deployed to GitHub Pages. Users need to search lessons by title and body text. No backend is available.
Decision
Used Pagefind — a static search library that indexes the built HTML and generates a client-side search index. The integration is minimal:
- Install:
npm install --save-dev pagefind - Index:
npx pagefind --site dist(runs after Astro build) - UI: Include Pagefind's CSS/JS and initialize
PagefindUIin a component - Scope: Add
data-pagefind-bodyto lesson detail pages so only lesson content is indexed (not navigation, footers, etc.)
Outcome
Pagefind indexed 90 pages with 5091 words in under 0.5 seconds. The search UI is functional with zero backend infrastructure. The index is regenerated on every build, so new lessons are immediately searchable.
Key Takeaway
For static sites with moderate content volume, Pagefind provides excellent search with zero operational cost. The data-pagefind-body attribute is critical for scoping the index to meaningful content.