Reverted Collection VO slug generation

This commit is contained in:
Cássio Zen 2016-10-27 14:59:41 -02:00
parent 2e6e5d1bec
commit 1566e247f3

View File

@ -9,26 +9,6 @@ function formatToExtension(format) {
}[format]; }[format];
} }
function slugFormatter(template, entryData) {
const date = new Date();
const entry = (typeof entryData === 'string') ? entryData : entryData.get('title', entryData.get('path'));
const identifier = entry.match(/([^:\\/]*?)(?:\.([^ :\\/.]*))?$/)[1];
return template.replace(/\{\{([^\}]+)\}\}/g, (_, name) => {
switch (name) {
case 'year':
return date.getFullYear();
case 'month':
return (`0${ date.getMonth() + 1 }`).slice(-2);
case 'day':
return (`0${ date.getDate() }`).slice(-2);
case 'slug':
return identifier.trim().toLowerCase().replace(/[^a-z0-9\.\-_]+/gi, '-');
default:
return identifier.trim().toLowerCase().replace(/[^a-z0-9\.\-_]+/gi, '-');
}
});
}
class FolderCollection { class FolderCollection {
constructor(collection) { constructor(collection) {
this.collection = collection; this.collection = collection;
@ -43,7 +23,7 @@ class FolderCollection {
} }
entrySlug(path) { entrySlug(path) {
return slugFormatter(this.collection.get('slug'), path); return path.split('/').pop().replace(/\.[^\.]+$/, '');
} }
listMethod() { listMethod() {