I decided to implement a searching feature for this blog (the one you’re reading).
Since this blog is statically generated (using Hugo) - I had to implement this functionality client-side.
Thanks to js-search, this was quite simple.
I would just need Hugo to generate a JSON map of all the posts on this blog, and pass that map to the search library.
However, as the JSON file would be relatively large, I wanted to implement a cache - so that the file will not be requested on every load. To be static HTTP server agnostic, I opted against using an ETag
solution, and instead writing some code to compare the version of the loaded search script.
However, generating templated JavaScript code in Hugo turned out to be… rather difficult.
I ended up opting to generate the templated data during the post-build stage.
EDIT: GitHub uses ETags
, wow I wasted some time :')
You can find the changes here… if you want…