Spica
June 29, 2018, 11:25am
1
{{- range $index, $image := .Resources.ByType "image" -}}
With this range on images with numbered filenames like
i-1.jpg
i-2.jpg
i-10.jpg
I get a default sorting like
i-1.jpg
i-10.jpg
i-2.jpg
How to get a Natural Sort Order like the first list?
bep
June 29, 2018, 12:02pm
2
You name your files in natural order.
Spica
June 29, 2018, 12:13pm
3
you’re right. simplest solution.
bep
June 29, 2018, 12:39pm
4
As an added note, you can rename the resources and use a counter etc. (there should be docs about this), but for the natural sort you currently need to do that on the disk.
Yes, there are docs on the use of counter.
Though, I would just name the files as 00-foo, 01-foo, etc. if I needed natural sort.
igr
November 19, 2018, 6:45pm
6
Well, this is not a solution. What if he gets to 100? Should he rename everything? No.
1 Like
Completely agree - this isn’t even a reasonable workaround.
Could we pre-pad the incoming range with zeroes somehow? I’m really new to Hugo and to Go, so I’m not sure what this would look like.
regis
April 1, 2019, 3:26pm
8