Search Index .json-file for Lunr.js

I was actually just playing with this.

  1. Put this in config.toml
	home = [ "HTML", "JSON"]
	page = [ "HTML"]

That tells your site to make a JSON page for the home page.

  1. Make a file called index.json in the layouts folder of your preference (mine is in my theme for reasons)

  2. Use Rick’s example for the content of what he did as /json/single.html. Mine is different since I wanted to include categories and tags, and I’m using lunrjs prebuilt to look for uri instead of href:

{{- $.Scratch.Add "index" slice -}}
{{- range where .Site.Pages "Type" "not in"  (slice "page" "json") -}}
{{- $.Scratch.Add "index" (dict "uri" .Permalink "title" .Title "content" .Plain "tags" .Params.tags "categories" .Params.tags) -}}
{{- end -}}
{{- $.Scratch.Get "index" | jsonify -}}

I think that’s what bep was talking about. And I have to say, I like it a lot better than trying to use node (hugo-lunr or lunr-hugo) or Grunt, since I tend to write the docs on my iPad and auto-push the site updates when git syncs.