I needed to know which is the nth post of a certain post type in hugo. Just placed this code in my theme’s index.html file at the top and it just works:

1
2
3
4
5
{{ $.Scratch.Add "discno" 0 }}
{{- range first 500 (where (where $.Site.RegularPages "Type" "POST_TYPE").Reverse ".Params.hiddenfromhomepage" "!=" true) -}}
	{{ $.Scratch.Add "discno" 1 }}
	<p class="text-left">{{ $.Scratch.Get "discno" }}. {{ with .Params.artist}}{{.}}{{end}}{{ with .Params.album_name}} - {{.}}{{end}}</p>
{{ end -}}

and it outputs

1 - Placebo - A Place For Us To Dream
2 - Die Antwoord - $O$
3 - Santana - Supernatural
4 - Morcheeba - Fragments of Freedom
5 - Cliff Martinez - Drive (Soundtrack)
[ . . . ]

Of course, I could expand this into a shortcode, add some parameters, and so on, but for now it’s just fine.