webidx is a client-side search engine for static websites.
The search functionality is implemented in webidx.js, which uses sql.js to provide an interface to an SQLite database.
The database is generated by a simple Perl script (webidx.pl) that should be run as part of the site build pipeline (eg after jekyll build
or whatever). The SQLite database should then be published alongside the static content.
You can see a live demo of it here.
- use webidx.pl to generate the index:
$ /path/to/webidx.pl -x index.html -x archives.html --xP secret_files -o https://example.com -z . ./index.db
You can run webidx.pl --help
to see all the available command-line options.
<script src="https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.12.0/sql-wasm.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pako/2.1.0/pako.min.js"></script>
<script src="/path/to/webidx.js"></script>
- Create a search form:
<form onsubmit="window.webidx.search({dbfile:'/webidx.db.gz',query:document.getElementById('q').value});return false;">
<input id="q" type="search">
</form>
When the user hits the return key in the search box, a modal dialog will pop up containing search results!
The object that's passed to window.webidx.search()
can have the following properties:
dbfile
: URL of the SQLite database filequery
: search queryresultCallback
: a callback which is passed an array of search results. Each result is an object with thetitle
andurl
properties. If not defined, a modal dialog will be displayed.errorCallback
: a callback which is passed any error string as an argument.titleSuffix
: a string to be removed from the end of page titles.titlePrefix
: a string to be removed from the beginning of page titles.