Simple JSON site index in Hugo

DISCLAIMER: The following will only work with the latest build of Hugo (0.16-DEV).

It has been a slow Sunday, no weather for skiing, so I have fiddled around with getting the foundation for site search on my blog. The actual search parts are still missing, but the JSON part is nice.

JSON isn’t a first class citizen in Hugo just yet, but this doesn’t look too bad:

This depends on several recent features/fixes added to Hugo:

  • The new slice func (added by @digitalcraftsman)
  • where now respects []interface{} slices.
  • Scratch now supports slices
  • Hugo now actually respects url with extension in frontmatter.
  • The Hugo server now handles JSON files with proper content type and character encoding.
  • The new jsonify template func
  • And the new template whitespace-trimmer in Go 1.6

A proof that it actually works: http://bepsays.com/index.json

And for the curious ones wondering how I deploy this to Amazon S3, I have now migrated this site to s3deploy to get proper headers:

See:

2 Likes

@bep This is awesome. Thank you. Looking forward to the new filters, especially |jsonify. Think I’ll create a similar tip/trick now that I’ve gotten lunr to work on my organization’s documentation site.