feat(cli): now option to set the home album name

Part of #176
pull/178/head
Romain 5 years ago
parent 8aa2780507
commit f088615caa

@ -194,6 +194,12 @@ const OPTIONS = {
choices: ['asc', 'desc'],
'default': 'asc'
},
'home-album-name': {
group: 'Album options:',
description: 'Name of the top-level album',
type: 'string',
'default': 'Home'
},
'album-zip-files': {
group: 'Album options:',
description: 'Create a ZIP file per album',
@ -409,6 +415,7 @@ exports.get = (args) => {
sortAlbumsDirection: opts['sort-albums-direction'],
sortMediaBy: opts['sort-media-by'],
sortMediaDirection: opts['sort-media-direction'],
homeAlbumName: opts['home-album-name'],
albumZipFiles: opts['album-zip-files'],
theme: opts['theme'],
themePath: opts['theme-path'],

@ -5,18 +5,18 @@ exports.createAlbums = function (collection, mapper, opts) {
// returns a top-level album for the home page
// under which all files are grouped into sub-albums
// and finalised recursively (calculate stats, etc...)
const home = group(collection, mapper)
const home = group(collection, mapper, opts.homeAlbumName)
home.finalize(opts)
return home
}
function group (collection, mapper) {
function group (collection, mapper, homeAlbumName) {
// this hashtable will contain all albums, with the full path as key
// e.g. groups['holidays/tokyo']
var groups = {
// the home album is indexed as '.'
// the value of '.' is local to this function, and doesn't appear anywhere else
'.': new Album('Home')
'.': new Album(homeAlbumName)
}
// put all files in the right albums
// a file can be in multiple albums

@ -4,6 +4,8 @@ const hierarchy = require('../../src/input/hierarchy.js')
const Album = require('../../src/model/album.js')
const fixtures = require('../fixtures')
const DEFAULT_OPTS = { homeAlbumName: 'Home' }
describe('hierarchy', function () {
beforeEach(function () {
Album.resetIds()
@ -12,20 +14,26 @@ describe('hierarchy', function () {
describe('root album', function () {
it('creates a root album (homepage) to put all sub-albums', function () {
const mapper = mockMapper(file => ['all'])
const home = hierarchy.createAlbums([], mapper, {})
const home = hierarchy.createAlbums([], mapper, DEFAULT_OPTS)
should(home.title).eql('Home')
})
it('can configure the top-level album name', function () {
const mapper = mockMapper(file => ['all'])
const home = hierarchy.createAlbums([], mapper, { homeAlbumName: 'Holidays' })
should(home.title).eql('Holidays')
})
it('defaults the homepage to index.html', function () {
const mapper = mockMapper(file => ['all'])
const home = hierarchy.createAlbums([], mapper, {})
const home = hierarchy.createAlbums([], mapper, DEFAULT_OPTS)
should(home.path).eql('index.html')
should(home.url).eql('index.html')
})
it('can configure the homepage path', function () {
const mapper = mockMapper(file => ['all'])
const home = hierarchy.createAlbums([], mapper, { index: 'default.html' })
const home = hierarchy.createAlbums([], mapper, { homeAlbumName: 'Home', index: 'default.html' })
should(home.path).eql('default.html')
should(home.url).eql('default.html')
})
@ -40,7 +48,7 @@ describe('hierarchy', function () {
fixtures.photo({ path: 'IMG_000002.jpg' })
]
const mapper = mockMapper(file => [value])
const home = hierarchy.createAlbums(files, mapper)
const home = hierarchy.createAlbums(files, mapper, DEFAULT_OPTS)
should(home.albums.length).eql(0)
should(home.files.length).eql(2)
should(home.files[0].filename).eql('IMG_000001.jpg')
@ -56,7 +64,7 @@ describe('hierarchy', function () {
fixtures.photo({ path: 'IMG_000002.jpg' })
]
const mapper = mockMapper(file => ['all'])
const home = hierarchy.createAlbums(files, mapper)
const home = hierarchy.createAlbums(files, mapper, DEFAULT_OPTS)
should(home.albums.length).eql(1)
should(home.albums[0].title).eql('all')
should(home.albums[0].files).eql([files[0], files[1]])
@ -68,7 +76,7 @@ describe('hierarchy', function () {
fixtures.photo({ path: 'two/IMG_000002.jpg' })
]
const mapper = mockMapper(file => [path.dirname(file.path)])
const home = hierarchy.createAlbums(files, mapper)
const home = hierarchy.createAlbums(files, mapper, DEFAULT_OPTS)
should(home.albums.length).eql(2)
should(home.albums[0].title).eql('one')
should(home.albums[0].files).eql([files[0]])
@ -82,7 +90,7 @@ describe('hierarchy', function () {
fixtures.photo({ path: 'IMG_000002.jpg' })
]
const mapper = mockMapper(file => ['one/two'])
const home = hierarchy.createAlbums(files, mapper)
const home = hierarchy.createAlbums(files, mapper, DEFAULT_OPTS)
should(home.albums.length).eql(1)
should(home.albums[0].title).eql('one')
should(home.albums[0].albums.length).eql(1)
@ -96,7 +104,7 @@ describe('hierarchy', function () {
fixtures.photo({ path: 'one/two/IMG_000002.jpg' })
]
const mapper = mockMapper(file => [path.dirname(file.path)])
const home = hierarchy.createAlbums(files, mapper)
const home = hierarchy.createAlbums(files, mapper, DEFAULT_OPTS)
should(home.albums.length).eql(1)
should(home.albums[0].title).eql('one')
should(home.albums[0].files).eql([files[0]])

@ -24,6 +24,7 @@ describe('Full integration', function () {
input: path.join(tmpdir, 'input'),
output: path.join(tmpdir, 'output'),
title: 'Photo album',
homeAlbumName: 'Home',
theme: 'classic',
log: 'info'
}

Loading…
Cancel
Save