thumbsup icon indicating copy to clipboard operation
thumbsup copied to clipboard

Sort albums by month name

Open amcolash opened this issue 5 years ago • 3 comments

Feature request

In my personal album, I have a structure like this:

  • photos/
    • 2019/
      • January/
        • 01-05 Vacation Day 1
      • February/
        • 02-03 Birthday

etc...

I would like to sort albums by month name (i.e. January, February, etc) so that they are shown in the proper ordering (which does not happen with nested folders currently).

At the moment, I can try to use start-date which only gets me part of the way, or change my naming such that it is alphabetical. Since I have this (maybe odd) way of structuring things, I would like to add a new option for sorting or append to an existing one.

I have a very simple way to do such a thing and would like to propose an idea and get feedback before making a PR.

This simple change works for my needs, but might need to be thought out a bit more. If there is a month name in the title, it prioritizes that. Otherwise right now it will fall back to dates.

const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
...
const SORT_ALBUMS_BY = {
...
  'start-date': function (album) { 
    const title = album.title;
    const index = months.indexOf(title);
    if (index !== -1) return index;
    return album.stats.fromDate;
  },

Obviously this is English-Only at the moment and does not account for abbreviations, such as "Jan". Another option may be adding an option use a list (that is already sorted) as the primary sorting and falling back to another sort. This would effectively replace the months array with a used-defined array so they can get whatever sorting setup they like.

amcolash avatar Apr 27 '19 23:04 amcolash

Hi, can you elaborate why sorting by start date doesn't work? The January album should come before February.

You're right I'd like to avoid hardcoding the special case folder name = english month in the code, maybe it could be a custom sort function instead?

rprieto avatar Apr 29 '19 17:04 rprieto

So the reason for me that it doesn't work is that I have multi-level nested folders where some folders only contain subdirectories and no images. It seems that with the current implementation, sorting by date of albums only works when the subdirectory contains images directly.

So in my above example, 2019 contains January and February but neither of those folders contain images directly. Only the directories below them (01-05 Vacation Day 1 and 02-03 Birthday) contain images.

Yeah I think some sort of custom sort function exposure might be sufficient. That might be a bit tough because it would have to be a custom file and cannot rely on commandline switches easily.

Clearly it was easy for me to get something set up, but selfishly I want a committed solution since I use the docker images and also of course want to share :wink:

amcolash avatar Apr 30 '19 05:04 amcolash

Thanks, I think you found a bug! Sorting should take sub-albums into account, just like the "album stats" caption that says 12 Jan - 30 Jan, 12 photos.

The code is

this.stats = {
    albums: this.albums.length,
    photos: _.sum(_.compact(_.concat(nestedPhotos, currentPhotos))) || 0,
    videos: _.sum(_.compact(_.concat(nestedVideos, currentVideos))) || 0,
    fromDate: _.min(_.compact(_.concat(nestedFromDates, currentFromDate))),
    toDate: _.max(_.compact(_.concat(nestedToDates, currentToDate)))
  }

I'll see if I can add unit tests for sorting based on nested albums. Or let me know if you're keen to do it!

rprieto avatar Apr 30 '19 07:04 rprieto