Knocked another task off my blog migration list: we have search functionality again! This was much easier than I thought it was going to be, but as promised, Pagefind is super easy to install.
At any given moment it might be a few hours out of date, since I only run the reindex job once a day. I don’t think that’ll matter much to anyone.
Couple of technical notes just in case it helps someone else:
The Getting Started guide gave me everything I needed. Since I’m running Hugo, I had to spend a minute or two thinking about where the block of HTML provided should go. Answer:
- The
<div id="search"></div>line goes in my sidebar (layouts/partials/sidebar.html), plus I added my existing sidebar classes for styling, so<div class="sidebar-widget sidebar-section" id="search"> - The rest of that block – the
<link>and<script>lines, both above and beneath the<div>line – are in a partial template,layouts\partials\pagefind.html - And finally I include the partial into
layouts/_default/baseof.htmlwith{{ partial "pagefind.html" .}} - Oh, and a cronjob on the server to rebuild the index nightly
Couldn’t have been much easier. It’s so minimalist it was hard to believe it worked, but as you can see from the lovely search box at the top of the sidebar, it does.