Order pages by the id

Have folders in /content named: 1,2,3,4,16.

I want to get them sorted by the int value, not the text value (natural sorting).

How?

{{ $s := slice 0 }}
{{ range $index, $element := (sort .Pages "RelPermalink") }}
	{{ $s = $s | append (int (strings.TrimSuffix "/" (slicestr .RelPermalink 1) )) }}
{{ end }}

{{ range $index, $element := (after 1 (sort $s)) }}
{{ $c := add $index 1 }}
<a href="/{{.}}/">{{$c}}</a>
{{ end }}

Given content like this:

├── content
│   ├── 1.md
│   ├── 16.md
│   ├── 2.md
│   ├── 3.md
│   └── 4.md

I guess you could sort by .File.BaseFileName in your template:

{{- range sort .Pages .File.BaseFileName }}
<p>{{ .File.BaseFileName }}</p>
{{- end }}

But this will only display pages in descending order:

<p>16</p>
<p>4</p>
<p>3</p>
<p>2</p>
<p>1</p>

I did it, see my answer.

Ah, I missed that. Well, glad you have a solution now :+1: