Index sorting #6

Closed
opened 2022-02-23 15:54:33 +00:00 by jeandav · 2 comments
jeandav commented 2022-02-23 15:54:33 +00:00 (Migrated from github.com)

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 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,
paintedsky commented 2022-02-23 20:34:23 +00:00 (Migrated from github.com)

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!

Hi, Yeah at the moment there isn't really any custom sorting. It uses [DirectoryIterator](https://www.php.net/manual/en/class.directoryiterator.php) 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](https://stackoverflow.com/a/18337742) 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!
paintedsky commented 2022-11-15 20:05:53 +00:00 (Migrated from github.com)

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.

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.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: paintedsky/dead-simple-blog#6
No description provided.