Class: Abqari::Search
- Inherits:
-
Object
- Object
- Abqari::Search
- Defined in:
- lib/abqari/search.rb
Overview
Static search via Pagefind. After bin/build emits HTML, Pagefind walks _site/, builds a chunked search index under _site/pagefind/, and ships a tiny JS runtime that runs entirely in the visitor's browser.
Privacy-friendly (no server, no API), free, and the index is just static files served alongside your site.
Pagefind is a single Rust binary. Install it once:
macOS: brew install pagefind
General: curl -LSf https://pagefind.app/install.sh | bash
Cargo: cargo install pagefind
Enable in config/site.yml:
search: true
Then render the search widget anywhere in your templates:
<%= render 'partials/search' %>
Constant Summary collapse
- BINARY =
'pagefind'
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize(site) ⇒ Search
constructor
A new instance of Search.
-
#run ⇒ Object
Called from Site#build — only runs when
search: trueis set so a default site doesn't pay the cost. -
#run! ⇒ Object
Always runs pagefind, regardless of the config flag.
Constructor Details
#initialize(site) ⇒ Search
Returns a new instance of Search.
26 27 28 |
# File 'lib/abqari/search.rb', line 26 def initialize(site) @site = site end |
Instance Method Details
#enabled? ⇒ Boolean
30 31 32 |
# File 'lib/abqari/search.rb', line 30 def enabled? @site.config['search'] == true end |
#run ⇒ Object
Called from Site#build — only runs when search: true is set so a
default site doesn't pay the cost.
36 37 38 39 40 |
# File 'lib/abqari/search.rb', line 36 def run return unless enabled? run! end |
#run! ⇒ Object
Always runs pagefind, regardless of the config flag. Used by bin/index so an explicit invocation works even when search isn't enabled in config. Skips with a helpful warning if the binary isn't on PATH; never raises so a fresh checkout never fails the build.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/abqari/search.rb', line 46 def run! unless command_available? Log.warn "Abqari: `#{BINARY}` is not on PATH." Log.warn ' Install: https://pagefind.app/docs/installation/' Log.warn ' Skipping search index.' return end success = system(BINARY, '--site', @site.output_dir, out: File::NULL, err: File::NULL) if success Log.info 'Indexed for search → _site/pagefind/' else Log.warn "Abqari: pagefind exited with status #{$?.exitstatus}; search may be incomplete." end end |