Site search
Set "search": true in site.json and every publish builds a Pagefind index. It runs as static files in the visitor’s browser.
Set "search": true in site.json and every publish builds a Pagefind index. It runs as static files in the visitor’s browser.
Any Statically site can now have its own search. Add one line to site.json, "search": true, and every time the site is published we build a search index of its pages using Pagefind.
The index is published as plain static files alongside the site, and searches run in the visitor's own browser. There's no search server to host, no third-party service and no visitor data sent anywhere. It works on any host, and it even keeps working in the copy your client gets when they export their site.
The 404 page and any page marked "Hide from search engines" are left out automatically. Mark the main content area in your layout and menus and footers won't clutter up the results, and you can leave out any other part of a page you don't want searched.
A search page is just an ordinary page whose template loads Pagefind's ready-made search box and results. Style it with a few CSS variables to match the site's design. Full details and copy-and-paste code are in the Site search docs.
Search works on the published site. Previews render pages one at a time and don't have an index, so search won't find anything there.