I have created a website with solutions for static sites (Jekyll), called Jekyll Codex (https://jekyllcodex.org). Currently I am porting this website (and their solutions) to Hugo. You can find the Hugo website here:
@jhvanderschee Hello, thank you for the quick solution. Though, I am not conversant with Jekyll, and also not familiar with Javascript, so cannot comment anything useful by just looking at the code.
(I can though try out something quickly if you present an example setup for Hugo.)
First a local index is build, using the documents variable.
If I am not wrong, a Hugo-local index can be built during deployment using Custom Output Format JSON. I was able to achieve that part. Where I stumbled was where @bep referred to a âreverse document indexâ generation in this comment. I have no idea where that piece of code would go in the whole flow.
So my idea would be:
Generate the JSON using Hugo Custom Output as explained here. I got this part working!
???(The reverse index generation part)
Download the file lunr.js
Save the file in the âjsâ (root) directory of your project
Call the reverse index generation script by putting this partial in your HTML header template.
The content of the JSON file (the index) is now situated in the documents variable (so in the partial/include). You are looking at the complete solution.
However, this solution might cause a problem for larger indexes, because like this the index can not be cached. My current index is <30kb, and contains around 50 pages. Not really a problem, but if you have a larger website, you want this index to be downloaded once. This requires a script that loads the external cachable JSON file (you already created).
Some time ago I changed from Jekyll to Hugo which turned out to be a great move. Therefore I know Jekyll Codex - great work. Porting that in my opinion is a good idea.