Searching baty.net
š”
This applies to the Eleventy version of the blog.
Iāve added a search page. It uses Pagefind. It turns out Iād already begun work on this with the original site. The clue was a commented-out line in my Makefile:
index:
npx -y pagefind --site ${SITE_DIR}
All I needed to do was create a search page and add a snippet:
---
layout: layouts/base.njk
title: Search
slug: /search
---
<link href="/pagefind/pagefind-ui.css" rel="stylesheet">
<script src="/pagefind/pagefind-ui.js"></script>
<div id="search"></div>
<script>
window.addEventListener('DOMContentLoaded', (event) => {
new PagefindUI({ element: "#search", showSubResults: true, pageSize: 10, autofocus: true });
});
</script>
To manually build the index, I render the site and then index it. using npx -y pagefind --site _site
. I do this as part of the deploy recipe in the Makefile.
That was easy enough. Iāll fart around with the indexing a bit, but otherwise it works really well right out of the box.