the easiest would be @chrillek s suggestion to declare an int in your frontmatter. (maybe need toml for that)
then sorting would be as easy as {{ range site.RegularPages.ByParam "min" }}
Sorting by calculated value is uncomfortable. Most of the time one would use a map, but there the keys are always strings, so printf "%04d" min is your friend for the sort order.
here’s a version using a newScratch to create a map that uses lists of pages with the same min. Each “key” holds a list of pages with the same min age taken from your ages param.
That worked a treat, and you and @chrillek are certainly right. At the end of day adding the frontmatter key (and adjusting other templates) makes more sense.
I did manage to get your example working nicely, so thank you very much for that!
For future searchers, I ended up with:
{{ $daymap := newScratch }}
{{ range $i := (where $.Page.Pages "Params.duration" "day") }}
{{ $min := index ($i.Params.ages | findRE "^\\d+") 0 }}
{{ with $daymap.Get $min }}
{{ $daymap.Add $min $i }}
{{ else }}
{{ $daymap.Add $min (slice $i) }}
{{ end }}
{{ end }}
{{ range sort $daymap.Values }}
{{ range . }}
{{ .Params.ages }} ==> {{ .Title }}<br>
{{ end }}
{{ end }}