Skip to content

Commit

Permalink
Add tests for passing in options to slug and slugify filters. Switch …
Browse files Browse the repository at this point in the history
…to decamelize default for slugify filter.
  • Loading branch information
zachleat committed Jul 7, 2021
1 parent 4eded23 commit 6169883
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Filters/Slugify.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const slugify = require("@sindresorhus/slugify");

module.exports = function(str, options = {}) {
return slugify(str, options);
return slugify(str, Object.assign({
decamelize: false
}, options));
};
22 changes: 21 additions & 1 deletion test/TemplateTest_Permalink.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ test("Using slugify filter!", async (t) => {
t.is(await tmpl.getOutputPath(), "./dist/subdir/slug-love-candidate-lyublyu/index.html");
});

test("Using slugify filter with comma", async (t) => {
test("Using slugify filter with comma and apostrophe", async (t) => {
let tmpl = getNewTemplate(
"./test/slugify-filter/comma.njk",
"./test/slugify-filter/",
Expand All @@ -209,3 +209,23 @@ test("Using slugify filter with comma", async (t) => {

t.is(await tmpl.getOutputPath(), "./dist/subdir/hi-i-m-zach/index.html");
});

test("Using slug filter with options params", async (t) => {
let tmpl = getNewTemplate(
"./test/slugify-filter/slug-options.njk",
"./test/slugify-filter/",
"./dist"
);

t.is(await tmpl.getOutputPath(), "./dist/subdir/hi_i_am_zach/index.html");
});

test("Using slugify filter with options params", async (t) => {
let tmpl = getNewTemplate(
"./test/slugify-filter/slugify-options.njk",
"./test/slugify-filter/",
"./dist"
);

t.is(await tmpl.getOutputPath(), "./dist/subdir/hi-i-m-z-ach/index.html");
});
2 changes: 1 addition & 1 deletion test/slugify-filter/comma.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Hi, I'm Zach"
title: "Hi, I'm ZAch"
permalink: subdir/{{ title | slugify }}/index.html
---
Slugged.
5 changes: 5 additions & 0 deletions test/slugify-filter/slug-options.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "Hi, I am ZAch"
permalink: "subdir/{{ title | slug({replacement:'_'}) }}/index.html"
---
Slugged.
5 changes: 5 additions & 0 deletions test/slugify-filter/slugify-options.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "Hi, I'm ZAch"
permalink: "subdir/{{ title | slugify({decamelize: true}) }}/index.html"
---
Slugged.

0 comments on commit 6169883

Please sign in to comment.