I just added static search to this website, and it is super easy. (see /search )
How does it work?
- we create one big json with all the page content (index.json).
Every page is summarized into title, summary, content and tags.
- The search javascript goes through this.
The logic in that javascript matches the keywords against the content of the pages. You can even modify the relative weights of the search parts.
How can I add it too?
I followed the guidance here: on the hugo discourse website. Add the following things to the website:
- a shortcode in layouts/shortcodes/search.html
- a custom javascript in static/js/search.js
- a page for search: content/search.md
- a custom layout that creates a json in layouts/index.json
- Modify the config.toml to also produce json for the main page:
[outputs]
home = [ "HTML", "JSON" ]
I tried it out and it worked out of the box! The only thing I modified was the search.html shortcode because it used German words for AND / OR search.
I’m publishing this as part of 100 Days To Offload. You can join in yourself by visiting https://100daystooffload.com, post - 38/100
Find other posts tagged #100DaysToOffload here