Customise slug base name for different models

fixes #2480

- when the santisation of a slug results in an empty string, we use a basename instead.
- this was 'post' and is now the table name for the model, minus the trailing 's'
- this isn't massively robust but works as a temporary fix
This commit is contained in:
Hannah Wolfe 2014-03-23 18:52:25 +00:00
parent f981e71e3c
commit a0dff19b7a

View File

@ -199,7 +199,10 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
generateSlug: function (Model, base, readOptions) {
var slug,
slugTryCount = 1,
baseName = Model.prototype.tableName.replace(/s$/, ''),
// Look for a post with a matching slug, append an incrementing number if so
checkIfSlugExists;
checkIfSlugExists = function (slugToFind) {
var args = {slug: slugToFind};
//status is needed for posts
@ -249,11 +252,11 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
// Check the filtered slug doesn't match any of the reserved keywords
slug = /^(ghost|ghost\-admin|admin|wp\-admin|wp\-login|dashboard|logout|login|signin|signup|signout|register|archive|archives|category|categories|tag|tags|page|pages|post|posts|user|users|rss)$/g
.test(slug) ? slug + '-post' : slug;
.test(slug) ? slug + '-' + baseName : slug;
//if slug is empty after trimming use "post"
if (!slug) {
slug = 'post';
slug = baseName;
}
// Test for duplicate slugs.
return checkIfSlugExists(slug);