Sort by file name with trailing number
Closed this issue · 2 comments
Hi!
I am using this theme to present just one album as a home page. The content folder contains over 600 images with the file name ending in the desired sort order (ex. starting with name-0.jpg continuing beyond name-600.jpg, etc.) and one index.md file. With default sort of "Name" in the index.md file within the content folder, the first four images displayed are...
- name-0.jpg
- name-1.jpg
- name-10.jpg
- name-100.jpg
- etc
The desired sort order would be...
- name-0.jpg
- name-1.jpg
- name-2.jpg
- name-3.jpg
- etc
I'm in over my head. Any advice/starting point? From there, my next goal will be to sort them in a descending order.
Much appreciated,
Clay
Hi !
The theme is sorting files using their name, making no asumption about their format.
If you want the photos to be sorted as you requested, I would suggest a short shell script renaming files as such :
name-001.jpg
name-002.jpg
...
name-010.jpg
...
name-100.jpg
You are right, that is definitely the easiest solution. Thanks!
In case anyone needs it, additional success with sort order by modifying single.html.
{{ $photos := sort (.Resources.ByType "image") (index .Params "sort_by" |default "Name") "desc" }} {{- partial "photos.html" $photos -}}