From c65716297522c479aafa8a61a257d4c0c0241b51 Mon Sep 17 00:00:00 2001 From: Zach Tratar Date: Tue, 5 Apr 2016 14:07:26 -0700 Subject: [PATCH 1/5] Add option for slug permanence --- lib/slug-generator.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/slug-generator.js b/lib/slug-generator.js index 76370f7..23af223 100644 --- a/lib/slug-generator.js +++ b/lib/slug-generator.js @@ -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; @@ -79,17 +82,23 @@ module.exports = function (schema, options) { }); if (!(item.unique || item.unique_slug)) { - doc[item.name] = makeSlug(values, opts); + if (!(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 (!(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 (!(item.permanent && doc[item.name])) { + doc[item.name] = slug; + } callback(); }) } @@ -182,4 +191,4 @@ function makeUniqueShortIdSlug(doc, field, values, options, next) { next(null, slug); }); -} \ No newline at end of file +} From 5ff1038918f061f573c79a3661d77efe3efd2a99 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Tue, 6 Sep 2016 12:08:40 -0700 Subject: [PATCH 2/5] testing a fix --- lib/slug-generator.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/slug-generator.js b/lib/slug-generator.js index 23af223..39301ab 100644 --- a/lib/slug-generator.js +++ b/lib/slug-generator.js @@ -82,21 +82,21 @@ module.exports = function (schema, options) { }); if (!(item.unique || item.unique_slug)) { - if (!(item.permanent && doc[item.name])) { + 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) { - if (!(item.permanent && doc[item.name])) { + 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) { - if (!(item.permanent && doc[item.name])) { + if (!doc[item.name] || !(item.permanent && doc[item.name])) { doc[item.name] = slug; } callback(); From ed414e0f041793316ea5ac0b0dffdc72aa3723eb Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Tue, 6 Sep 2016 12:13:38 -0700 Subject: [PATCH 3/5] debug --- lib/slug-generator.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/slug-generator.js b/lib/slug-generator.js index 39301ab..f1cc0c2 100644 --- a/lib/slug-generator.js +++ b/lib/slug-generator.js @@ -81,6 +81,8 @@ module.exports = function (schema, options) { values.push(doc[item]); }); + console.log(doc[item.name]); + if (!(item.unique || item.unique_slug)) { if (!doc[item.name] || !(item.permanent && doc[item.name])) { doc[item.name] = makeSlug(values, opts); From a09a84d167d504797b8848125d3400b9adfb7090 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Tue, 6 Sep 2016 12:14:00 -0700 Subject: [PATCH 4/5] debug --- lib/slug-generator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/slug-generator.js b/lib/slug-generator.js index f1cc0c2..b50b6af 100644 --- a/lib/slug-generator.js +++ b/lib/slug-generator.js @@ -81,7 +81,7 @@ module.exports = function (schema, options) { values.push(doc[item]); }); - console.log(doc[item.name]); + console.log(doc[item.name], !doc[item.name] || !(item.permanent && doc[item.name])); if (!(item.unique || item.unique_slug)) { if (!doc[item.name] || !(item.permanent && doc[item.name])) { From a1711367f8551db50e4887f1f460c2e6391a2c66 Mon Sep 17 00:00:00 2001 From: "Andrew E. Rhyne" Date: Tue, 6 Sep 2016 12:33:57 -0700 Subject: [PATCH 5/5] fix --- lib/slug-generator.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/slug-generator.js b/lib/slug-generator.js index b50b6af..39301ab 100644 --- a/lib/slug-generator.js +++ b/lib/slug-generator.js @@ -81,8 +81,6 @@ module.exports = function (schema, options) { values.push(doc[item]); }); - console.log(doc[item.name], !doc[item.name] || !(item.permanent && doc[item.name])); - if (!(item.unique || item.unique_slug)) { if (!doc[item.name] || !(item.permanent && doc[item.name])) { doc[item.name] = makeSlug(values, opts);