|
|
@@ -15,14 +15,24 @@ const path = require('path');
|
|
|
const es = require('event-stream');
|
|
|
const Promise = require('bluebird');
|
|
|
|
|
|
-function slugify(text)
|
|
|
+function slugify(str)
|
|
|
{
|
|
|
- return text.toString().toLowerCase()
|
|
|
- .replace(/\s+/g, '-') // Replace spaces with -
|
|
|
- .replace(/[^\w\-]+/g, '') // Remove all non-word chars
|
|
|
- .replace(/\-\-+/g, '-') // Replace multiple - with single -
|
|
|
- .replace(/^-+/, '') // Trim - from start of text
|
|
|
- .replace(/-+$/, ''); // Trim - from end of text
|
|
|
+ str = str.replace(/^\s+|\s+$/g, ''); // trim
|
|
|
+ str = str.toLowerCase();
|
|
|
+
|
|
|
+ // remove accents, swap ñ for n, etc
|
|
|
+ var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
|
|
|
+ var to = "aaaaeeeeiiiioooouuuunc------";
|
|
|
+
|
|
|
+ for (var i=0, l=from.length ; i<l ; i++)
|
|
|
+ str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
|
|
|
+
|
|
|
+
|
|
|
+ str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
|
|
|
+ .replace(/\s+/g, '-') // collapse whitespace and replace by -
|
|
|
+ .replace(/-+/g, '-'); // collapse dashes
|
|
|
+
|
|
|
+ return str; // Trim - from end of text
|
|
|
}
|
|
|
|
|
|
Promise.promisifyAll(fs);
|