-
Notifications
You must be signed in to change notification settings - Fork 55
Useful
etaypere edited this page Apr 10, 2013
·
1 revision
schema.pre('validate', function(next) {
var url = this.url;
if (!url)
url = '/' + this.title;
url = url.replace(/[\?\'\"\@\!\#\$\%\^\&\*\(\)\+\=\_\~\{\}\[\]\\\|\,\;\:]/g, "")
.replace(/ +/g, "-")
.replace(/\-+/g, '-')
.replace(/(?:^\-|\-$)/g, '');
if (url.substr(0,1) !== '/')
url = '/' + url;
this.url = url.toLowerCase();
next();
});