Index sorting #6
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: paintedsky/dead-simple-blog#6
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi people,
For some reasons, I can't find the logic in the way the index is sorted. In my case it is not chronological nor alphabetical, nor following any logic. Is there any way to fix this ?
Thanks in advance,
Hi,
Yeah at the moment there isn't really any custom sorting. It uses DirectoryIterator to get the files from the ./content/ directory. DirectoryIterator doesn't accept any sorting parameters - it simply lists the files in the same order that you'd get them from a "ls -l" command, AFAIK. This should be alphabetical by default if I'm not mistaken.
In my case, I use YYYY-MM-DD date-based names (e.g. 2018-10-30.txt). This worked well for me, but if you want to use a different naming convention it might not work for you.
The way to fix this is to load the files into an array before outputting them, and sort the array. See this link for more details on that.
Your suggestion to have sorting makes sense, so I wouldn't be opposed to updating this to include it. However, it may take some time for me to get around to making that update, so if you'd prefer not to wait and would like to make a pull request instead, please feel free to do so.
Thanks!
Closing this as version 1.1 now explicitly sorts posts. Default is sorting by filename (descending) but the code can be easily modified to sort by different file attributes, in either direction.