Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #25, all falsy pattern values and empty arrays are now treated the same #35

Merged
merged 1 commit into from
Jul 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function replace(pattern, data, options){

for (var i = 0, key; key = keys[i++];) {
var val = data[key];
if (val == null) return null;
if (!val || Array.isArray(val) && val.length === 0) return null;
if (val instanceof Date) {
ret[key] = options.date(val);
} else {
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/empty-array/src/emptyarray.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
array: []
title: test
---
test
5 changes: 5 additions & 0 deletions test/fixtures/falsy/src/emptystring.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
falsy: ''
title: test
---
test
5 changes: 5 additions & 0 deletions test/fixtures/falsy/src/false.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
falsy: false
title: test
---
test
5 changes: 5 additions & 0 deletions test/fixtures/falsy/src/nan.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
falsy: .NAN
title: test
---
test
5 changes: 5 additions & 0 deletions test/fixtures/falsy/src/null.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
falsy: null
title: test
---
test
4 changes: 4 additions & 0 deletions test/fixtures/falsy/src/undefined.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: test
---
test
29 changes: 29 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,33 @@ describe('metalsmith-permalinks', function(){
done();
});
});

it('should use the resolve path for false values (not root)', function (done) {
Metalsmith('test/fixtures/falsy')
.use(permalinks(':falsy/:title'))
.use(function (files, metalsmith, pluginDone) {
Object.keys(files).forEach(function (file) {
assert.notEqual(files[file].path.charAt(0), '/');
});
done();
})
.build(function (err) {
if (err) return done(err);
});
});


it('should use the resolve path for empty arrays (not root)', function (done) {
Metalsmith('test/fixtures/empty-array')
.use(permalinks(':array/:title'))
.use(function (files, metalsmith, pluginDone) {
Object.keys(files).forEach(function (file) {
assert.notEqual(files[file].path.charAt(0), '/');
});
done();
})
.build(function (err) {
if (err) return done(err);
});
});
});