Uses more web-friendly and robust slugs for album filenames (no quotes, no colons…)

Fixes #164
pull/178/head
Romain 5 years ago
parent 4d8dfcb7b7
commit 066155f0fb

@ -14,6 +14,7 @@ var index = 0
// number of images to show in the album preview grid
const PREVIEW_COUNT = 10
const SLUGIFY_OPTIONS = { replacement: '-', remove: /[*+~.()'"!:@]/g }
const SORT_ALBUMS_BY = {
'title': function (album) { return album.title },
@ -36,7 +37,7 @@ function Album (opts) {
if (typeof opts === 'string') opts = { title: opts }
this.id = opts.id || ++index
this.title = opts.title || ('Album ' + this.id)
this.basename = slugify(this.title)
this.basename = slugify(this.title, SLUGIFY_OPTIONS)
this.files = opts.files || []
this.albums = opts.albums || []
this.depth = 0

@ -24,6 +24,17 @@ describe('Album', function () {
should(a.basename).eql('and-deja-vu')
})
it('sanitises more special characters than the slugify() default', function () {
const a = new Album(`hello*+~.()'"!:@world`)
should(a.basename).eql('helloworld')
})
it('doesn\'t use a dash if the words have no space', function () {
// not ideal but that's hoz slugify() works
const a = new Album("aujourd'hui")
should(a.basename).eql('aujourdhui')
})
it('concatenates nested filenames for uniqueness', function () {
// to avoid having two nested albums called "October" overwrite each other
// note: doesn't use the root title to avoid "home-" or "index-"

Loading…
Cancel
Save