Guide
Search
A static site has no server to search on, so the search runs in the browser. ombryt writes an index of the pages for that:
[]
= "/search.json"
= "post" # which pages (default: all with a title)
= true # include the body text of markdown pages
= 0 # cut each page's text to this many characters (0: no limit)
Pages with search: false and taxonomy pages are left out.
The index #
headings lets a result link straight to the right section (url#id).
Using it #
For a few hundred pages, loading the index on the first keystroke and searching it in plain JavaScript is fast
enough. These docs do that: docs/src/js/search.js
is about 90 lines with no dependencies. Try it with /.
For fuzzy matching, prefixes and better ranking, give the documents to a library:
const = await .;
const = new;
;
const = ;
Fuse.js, Lunr and FlexSearch take the same array.
Large sites #
The index holds all of the text, so it grows with the site: about 475 KB (130 KB compressed) for a blog with 66
long posts. Past a few megabytes, set max_text, leave text off, or use Pagefind, which
splits its index into small pieces that are loaded as needed. It works on any static site, so it works on
ombryt's output: