Im trying to create a section overview sorted by semvar versions. The version is part of the front matter and i would like so to sort the overview in descending order.
I created a template but unfortunately the build step throws an error: error calling sort: sequence must be provided
This is the code i am using:
{{ range (.Paginator.Pages.ByParam "version").Reverse }}
{{/* split version string */}}
{{ $v_major := int (replaceRE "([0-9]+)\\.[0-9]+\\.[0-9]+" "${1}" .Params.version) -}}
{{ $v_minor := int (replaceRE "[0-9]+\\.([0-9]+)\\.[0-9]+" "${1}" .Params.version) -}}
{{ $v_minor_minor := int (replaceRE "[0-9]+\\.[0-9]+\\.([0-9]+)" "${1}" .Params.version) -}}
{{/* add leading zeros */}}
{{ $version := printf "%08d%08d%08d" $v_major $v_minor $v_minor_minor }}
{{/* put all versions into an array */}}
{{ $.Scratch.Add "versions" (slice ($version)) }}
{{end}}
{{ range sort ($.Scratch.Get "versions") "value" "desc"}}
{{ printf "%+v" . }}
{{ end }}
Am i doing something wrong here or is this use case not intended for the built in sort function?
Is there another solution for reverse ordering a custom slice?
The Scratch function GetSortedMapValues would be exactly what is am needing, if it had a reverse option.