Fix #30 Fix #31 allow asc/desc order when sorting albums and media

pull/47/head
Romain 8 years ago
parent 5117c19eed
commit 315e08e0e5

@ -72,19 +72,29 @@ var opts = yargs
},
// Deprecated for <sort-albums>
'sort-folders': {
description: 'How to sort gallery folders',
description: 'How to sort albums [deprecated]',
choices: ['name', 'date']
},
'sort-albums': {
'sort-albums-by': {
description: 'How to sort albums',
choices: ['name', 'date'],
choices: ['title', 'start-date', 'end-date'],
default: 'date'
},
'sort-media': {
'sort-albums-direction': {
description: 'Album sorting direction',
choices: ['asc', 'desc'],
default: 'asc'
},
'sort-media-by': {
description: 'How to sort photos and videos',
choices: ['name', 'date'],
choices: ['filename', 'date'],
default: 'date'
},
'sort-media-direction': {
description: 'Media sorting direction',
choices: ['asc', 'desc'],
default: 'asc'
},
'theme': {
description: 'Name of the gallery theme to apply',
choices: ['classic', 'cards', 'mosaic'],
@ -106,9 +116,14 @@ var opts = yargs
.config('config')
.epilogue('The optional JSON config should contain a single object with one key ' +
'per argument, not including the trailing "--". For example:\n\n' +
'{ "sort-albums": "date" }')
'{ "sort-albums-by": "start-date" }')
.argv;
// Compatibility
if (opts['sort-folders'] == 'name') opts['sort-albums-by'] = 'title';
if (opts['sort-folders'] == 'name') opts['sort-albums-by'] = 'start-date';
index.build({
input: path.resolve(opts['input']),
output: path.resolve(opts['output']),
@ -117,10 +132,12 @@ index.build({
largeSize: opts['large-size'],
originalPhotos: opts['original-photos'],
originalVideos: opts['original-videos'],
sortAlbums: opts['sort-folders'] || opts['sort-albums'],
sortMedia: opts['sort-media'],
albumsFrom: opts['albums-from'],
albumsDateFormat: opts['albums-date-format'],
sortAlbumsBy: opts['sort-albums-by'],
sortAlbumsDirection: opts['sort-albums-direction'],
sortMediaBy: opts['sort-media-by'],
sortMediaDirection: opts['sort-media-direction'],
theme: opts['theme'],
css: opts['css'],
googleAnalytics: opts['google-analytics'],

@ -5,13 +5,14 @@ var index = 0;
var PREVIEW_COUNT = 4;
var SORT_ALBUMS_BY = {
title: function(album) { return album.title; },
date: function(album) { return album.stats.fromDate; }
'title': function(album) { return album.title; },
'start-date': function(album) { return album.stats.fromDate; },
'end-date': function(album) { return album.stats.toDate; }
};
var SORT_MEDIA_BY = {
filename: function(file) { return file.filename; },
date: function(file) { return file.date; }
'filename': function(file) { return file.filename; },
'date': function(file) { return file.date; }
};
var PREVIEW_MISSING = {
@ -35,10 +36,6 @@ function Album(opts) {
}
Album.prototype.finalize = function(options) {
options = _.defaults(options, {
sortAlbums: 'date',
sortMedia: 'date'
});
// is this the top-level album?
this.home = this.depth === 0;
// finalize all nested albums first (recursive)
@ -89,8 +86,8 @@ Album.prototype.calculateSummary = function() {
};
Album.prototype.sort = function(options) {
this.files = _.sortBy(this.files, SORT_MEDIA_BY[options.sortMedia]);
this.albums = _.sortBy(this.albums, SORT_ALBUMS_BY[options.sortAlbums]);
this.files = _.orderBy(this.files, SORT_MEDIA_BY[options.sortMediaBy], options.sortMediaDirection);
this.albums = _.orderBy(this.albums, SORT_ALBUMS_BY[options.sortAlbumsBy], options.sortAlbumsDirection);
this.albums.forEach(function(nested) {
nested.sort(options);
});

Loading…
Cancel
Save