Hugo - sort by multiple fields
As I started working with Hugo, my main bottleneck was the default article sorting.
Hugo default sorting is Weight > Date > LinkTitle > FilePath. While this could be useful, the Date always messes up a list if you want to have a website and not a blog.
My issue was that sorting by title using .Pages.ByTitle on a range wasn’t enough. I still wanted to have Weight first and then the Title.
By using the grouping functions I was able to group and then sort them:
{{ range .Pages.GroupBy "Weight" }}
{{ range sort .Pages "Title" }}
<li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
{{ end }}
{{ end }}
It should be possible to sort with .Pages.ByTitle although I prefer the longer version.
August 11, 2019