CloudCannon / pagefind

Static low-bandwidth search at scale
https://pagefind.app
MIT License
3.4k stars 106 forks source link

Allow setting options before initialising the Pagefind search JS #400

Closed bglw closed 1 year ago

bglw commented 1 year ago

Addresses #129

Adds a new step to the flow of initializing Pagefind via the JavaScript API:

const pagefind = await import("/pagefind/pagefind.js");
await pagefind.options({ /* . . . */ });
await pagefind.init(); // <------ 🆕 and optional
await pagefind.search( /* . . . */ );

Previously the import itself would init and start loading assets, which meant the options() call could not affect this by changing the basePath or language.

Now, Pagefind will initialize when init() is called, or when any call to search or filters is made. As such, this change won't break any existing implementations, but may delay the loading of Pagefind until a search is made.