Reverted Collection VO slug generation
This commit is contained in:
parent
2e6e5d1bec
commit
1566e247f3
@ -9,26 +9,6 @@ function formatToExtension(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 {
|
||||
constructor(collection) {
|
||||
this.collection = collection;
|
||||
@ -43,7 +23,7 @@ class FolderCollection {
|
||||
}
|
||||
|
||||
entrySlug(path) {
|
||||
return slugFormatter(this.collection.get('slug'), path);
|
||||
return path.split('/').pop().replace(/\.[^\.]+$/, '');
|
||||
}
|
||||
|
||||
listMethod() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user