
I updated Hugo recently and had to make some updates to keep things working. I haven’t been following extremely closely on Hugo development, so this may not all be the absolute best way to do things, but it did work for me.
Note: This is an update to my previous post on Hugo and Lunr. So, check out that post for the full implementation.
I noticed that Hugo no longer liked me using straight HTML in my MarkDown files. I opted to go with creating a shortcode to provide the HTML needed on my search page.
So my previous search.md became:
---
title: "Search"
date: 1999-01-01
layout: page
exclude_search: true
---
{{< searchpage >}}
Then I created a shortcode in themes/<mytheme>/layouts/shortcodes/searchpage.html
with:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://unpkg.com/lunr@2.3.8/lunr.js"></script> | |
<script src="/search.js"></script> | |
<div> | |
<input id="search-input" type="text" placeholder="What are you looking for?" name="search-input" class="form-control"> | |
</div> | |
<div id="search-results" class="container"></div> |
I also happened to update lunr to 2.3.8, which may or may not matter. Nothing in my search.js had to change though.