RSS Amplifier

Dixi. · Aug 20, 2025

Search Through lunr.js and Other Website Goodies

0
Sign in to vote or save

Dixi.

  1. Blog
  2. Search Through lunr.js and Other Website Goodies

648 words3 min read

If you navigate to search you can see the lunr.js powered search. I’m very pleased with this, and I think it looks great. It has a decent amount of features I’d say; the search functionalities are mostly detailed on the search page itself.

External links are marked. I think this is missing some but I’m not sure why; will check it out later.

Double whammy: I wrote some shortcodes to list files in a directory which is convenient for posters and slides which will now automatically populate with any files placed in those folders. So, easy for me to maintain, and easy for you to find. You can see some curiosity work there.

I wrote the lunr.js stuff with Gemini. I saw Vicki Boykis’s post and had to implement it too. I’m doing the index generation through Hugo though, which I think is a lot cleaner. I relied on the LLM a lot since I still haven’t bothered to understand Hugo’s build system and I don’t really want to learn JS despite brushing up it against it a bit too frequently oft late for my linking… LLMs are nice here because I can clearly see if something is right or wrong, and I know enough to really read their output if I wanted to, but vibeish coding is fine here I think. LLMs can’t build software but they’re very good at writing code.

{{- $.Scratch.Add "index" slice -}}

{{- range where .Site.Pages "Kind" "page" -}}

{{- if and (ne .Layout "search") (ne .Type "search") .Title .Permalink (ne .Params.searchable false) -}}

{{- $byline_parts := slice -}}

{{- if ne .Params.byline false -}}

{{- if .Date -}}{{- if not .Date.IsZero -}}{{- $byline_parts = $byline_parts | append (.Date.Format (default "Jan 2, 2006" .Site.Params.dateFormat)) -}}{{- end -}}{{- end -}}

{{- if .Date -}}{{- if ne (.Lastmod.Format "2006-01-02") (.Date.Format "2006-01-02") -}}{{- $byline_parts = $byline_parts | append (printf "(Updated: %s)" (.Lastmod.Format .Site.Params.dateFormat)) -}}{{- end -}}{{- end -}}

{{- if gt .WordCount 0 -}}{{- $byline_parts = $byline_parts | append (printf "%d words" .WordCount) -}}{{- end -}}

{{- if and (.Site.Params.showContentTime) (not .Params.hideContentTime) -}}

{{- if .Params.contentTime -}}{{- $byline_parts = $byline_parts | append (printf "%d min read" .Params.contentTime) -}}{{- else if gt .ReadingTime 0 -}}{{- $byline_parts = $byline_parts | append (printf "%d min read" .ReadingTime) -}}{{- end -}}

{{- end -}}

{{- end -}}

{{- $byline := delimit $byline_parts " | " -}}

{{- $section := .Section | humanize -}}

{{- $.Scratch.Add "index" (dict

"title" .Title

"permalink" .Permalink

"tags" .Params.tags

"byline" $byline

"section" $section

"content" .Plain

)

-}}

{{- end -}}

{{- end -}}

{{- $.Scratch.Get "index" | jsonify -}}

Obviously not all of it will apply to your site, but its hopefully a good starting point if you wanted your own index.json. You need to enable that output in your Hugo config too. The snippet would be better in context but my website isn’t open source because I have some drafts and such I don’t want people seeing, sorry. Maybe if I clear out my backlog of posts I’ll make the GH repo public, but for now I must keep some secrets.

The next thing I want to see if I can add (w/o JS) is a copy button for code chunks, and maybe also nested menus? I’ve been thinking about forking bear-cub and publishing my changes, thus exposing my website indirectly? I’ve added a lot of somewhat random things which I like, but I’m not sure if anyone else would want them—hence the uncertainty of forking (and then maintaining a fork and such. Updating would be fine since I’d just swap themes to the fork.).

I’m more than happy to share any of my shortcodes and other stuff if you want em (aside: it is very strange to address virtual people who I know do not exist; nobody reads my blog. That’s fine with me honestly it is, after all, my blog).

Read the original on visruth.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.