Search code examples
hugostatic-site-generation

Hugo SSG use numbers instead of dates to rank posts


very dumb/random question but is there a way to just use numbers instead of dates to rank posts?

For example what if I want to build an outline in my post listing

  • 1.0
  • 1.1
  • 1.11
  • 1.111

Instead of the normal rank desc date.


Solution

  • It depends on how you are listing out your posts. You can sort: https://gohugo.io/functions/sort/ So, a front matter param like: (Pseudo code here)

    post_index: 1.0
    

    Then in the template/layout:

    {{ range sort .Params.post_index "value" "desc" }}{{ . }} {{ end }}
    

    Your reference is here: https://gohugo.io/functions/sort/

    (there are a few ways to do this - so this should at least get you started)