Skip to content

Commit

Permalink
Merge pull request #4 from Jobstart/master
Browse files Browse the repository at this point in the history
Add option for slug permanence
  • Loading branch information
gelito authored Apr 12, 2017
2 parents adcc93b + a171136 commit 2429908
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/slug-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ module.exports = function (schema, options) {
if (schemaType.options.unique || schemaType.options.unique_slug) {
slug.unique = true;
}
if (schemaType.options.permanent) {
slug.permanent = true;
}

if (schemaType.options.slug_padding_size === undefined) {
slug.isShortIdMode = true;
Expand Down Expand Up @@ -79,17 +82,23 @@ module.exports = function (schema, options) {
});

if (!(item.unique || item.unique_slug)) {
doc[item.name] = makeSlug(values, opts);
if (!doc[item.name] || !(item.permanent && doc[item.name])) {
doc[item.name] = makeSlug(values, opts);
}
callback();
} else {
if (item.isShortIdMode) {
makeUniqueShortIdSlug(doc, item.name, values, opts, function (err, slug) {
doc[item.name] = slug;
if (!doc[item.name] || !(item.permanent && doc[item.name])) {
doc[item.name] = slug;
}
callback();
})
} else {
makeUniqueCounterSlug(doc, item.name, values, opts, item.padding , function (err, slug) {
doc[item.name] = slug;
if (!doc[item.name] || !(item.permanent && doc[item.name])) {
doc[item.name] = slug;
}
callback();
})
}
Expand Down

0 comments on commit 2429908

Please sign in to comment.