BIT-101
Bill Gates touched my MacBook Pro
I love Hugo. I have negative regrets on switching over from Wordpress some years ago. But there are a couple things I’ve missed.
One is comments. Well, mixed feelings about that. I miss the interactivity. I do not miss the constant battle with spam.
The other is search. Hugo is a static site generator so there is no search functionality built in. Today I started looking around for how I could add it. There are a number of solutions. The first two I tried just didn’t work. Several required multiple JavaScript libraries and other files in order to do all the search on the client side. And you have to manually place all these files in the right place and then edit to them to configure things. And many of these seemed like hobby projects.
But eventually I found Pagefind. It seems pretty solid.
Lowdown on how it works:
After building your site, you run the pagefind executable, which builds an index of your site and adds it to your public site directory. It also automatically pushes the needed front end files into your site.
You need a small snippet somewhere on your site that will create the search UI, including the results. I just created a new page for that, with a link in the main menu to the search page.
It took a bit of back and forth to get it working, mainly due to my rustiness with Hugo itself. I think Pagefind itself worked fine right away.
Then you can configure various options on what parts of your site and what parts of each page to search, and what parts to ignore, adding some metadata to pages so it knows where to get the page title, etc. All of this was more just tweaking it to get all the right results and get them to look right.
For example, it was indexing my list pages - lists of posts and tags. I had to figure out how to exclude them. Wasn’t too tough. And it was showing a Mastdon logo on each post, which I guess was just the first image it found, somehow. So I turned off showing images in the results, which is fine. And it was showing “BIT-101” as the title for each page result, because it looks for the first H1 tag, which is the title of the whole site. So I had to tag the post title as being the title to index.
All seems to be working pretty well now. Anyway, no need to say more. It’s right up there in the menu. Try it out. I’m really happy to have this functionality back!
Comments? Best way to shout at me is on Mastodon ![]()