Hugo: Only Show Content Under a Given Section

One thing I initially found strange of Hugo was that it listed every piece of content on the front page - as if they were all blog posts. Luckily Hugo is flexible enough to change that behaviour without having to do any hacking. This blog post is mostly so that I remember how to do this in the future.

To limit your front page to show only content from a certain sub-directory, say, “post”, edit your index.html file (in your theme’s layout). If you see a certain line like

range .Data.Pages

simply change it to

range where .Data.Pages "Section" "post"

and rebuild your site. Neat! I’m not the kind of person who would shy away from hacking on some code (even go-lang) but easy fixes like this one are much appreciated.

comments powered by Disqus