mattstratton / castanet

A podcast-oriented theme for Hugo
MIT License
115 stars 61 forks source link

Add search feature #8

Open mattstratton opened 7 years ago

mattstratton commented 7 years ago

This will likely use google custom search; will require some work on the user side and then tweak some config parameters.

Commenting out the search box until this is done.

mattstratton commented 4 years ago

For reference, this has gotten slightly easier

https://blog.jeremylikness.com/blog/dynamic-search-in-a-static-hugo-website/

Developer for Life
Dynamic Search in a Static Hugo Website
Add dynamic search to a static Hugo website with custom templates to generate JSON and JavaScript to parse the results.
mattstratton commented 3 years ago

I think this actually just gets handled with some documentation - I did this on the Arrested DevOps podcast and I'm 99% sure I did it all outside the theme.

mattstratton commented 8 months ago

At the moment this can be accomplished simply via creating pages (nothing special in the theme) but making it documented (and having an example / template for it) is a good idea!

For reference, here's the things needed:

in your config.toml need:

[outputs]
  home = ["HTML", "RSS", "JSON"]
  page = ["HTML", "RSS"]
  1. A shortcode like this: https://github.com/arresteddevops/ado-hugo/blob/main/layouts/shortcodes/staticsearch.html (this can live in the site's layouts/shortcodes directory, doesn't need to be in the theme)
  2. A page of generic template that calls the shortcode, like this one https://github.com/arresteddevops/ado-hugo/blob/main/content/search.md
  3. A json index for the searching like this: https://github.com/arresteddevops/ado-hugo/blob/main/layouts/_default/index.json (I think this gets a problem if you don't have episodes coming off the index?)
  4. JavaScript file in static/js like this https://github.com/arresteddevops/ado-hugo/blob/main/static/js/search.js