Jekyll offline search plugin
A plugin for Jekyll to search for all posts and rank them by relevance. Relevance is determined by TF-IDF. Newer posts relevance is boosted exponentally so that they show up ealier in the results.
Installation
Install the plugin via bundler
from rubygems in the latest version:
bundle add jekyll_ranked_search
Edit your _config.yml
and add the plugin:
plugins:
- jekyll_ranked_search
Finally, restart your Jekyll server locally if it is currently running. This will generate the two files /js/search.js
and /search.json
in your _site
folder. As a next step, you will need to load the search plugin in your HTML code.
Usage
In your template, add the following lines:
<!-- Put the following line in your head -->
<script type="module" src="/js/search.js"></script>
<!-- Place this line where you want to render the search box -->
<search-box
lazy="true"></search-box>
You only need to add the <script>
tag once. It is recommended to add it to the header. The search box will fill 100% of the width of its parent container. The <search-box>
tag is a WebComponent that uses Lit and follows W3C standards and are available in all modern browswers.
Configuration
Search box
The following settings can be set on the <search-box>
component on the frontend.
Parameter | Description | Type | Default | Possible Values |
---|---|---|---|---|
lazy |
Lazy load results on first focus of search box | Boolean | false |
false ,true (see important note below) |
max-results |
Maximum number of results to display | Number | 8 |
[1, inf) |
Example:
<search-box
lazy="true"
max-results=4></search-box>
Important The presence of a boolean attribute is interpreted as true
. Therefore, if you wish to set it to false, remove the attribute completely instead of setting it to false
.
Jekyll
The following values can be set in the _config.yml
file in the Jekyll folder.
Currently none