mirror of
https://github.com/vale981/metalsmith-collections
synced 2025-03-05 09:21:39 -05:00
test and implementation for empty collections
This commit is contained in:
parent
f700016023
commit
ffdb548c9d
14 changed files with 44 additions and 2 deletions
10
lib/index.js
10
lib/index.js
|
@ -40,6 +40,14 @@ function plugin(opts){
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure that a default empty collection exists.
|
||||||
|
*/
|
||||||
|
|
||||||
|
keys.forEach(function(key) {
|
||||||
|
metadata[key] = metadata[key] || [];
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort the collections.
|
* Sort the collections.
|
||||||
*/
|
*/
|
||||||
|
@ -139,4 +147,4 @@ function matcher(cols){
|
||||||
}
|
}
|
||||||
return unique(matches);
|
return unique(matches);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
1
test/fixtures/basic/build/one.md
vendored
1
test/fixtures/basic/build/one.md
vendored
|
@ -1 +1,2 @@
|
||||||
|
|
||||||
one
|
one
|
1
test/fixtures/basic/build/two.md
vendored
1
test/fixtures/basic/build/two.md
vendored
|
@ -1 +1,2 @@
|
||||||
|
|
||||||
two
|
two
|
2
test/fixtures/empty/build/one.md
vendored
Normal file
2
test/fixtures/empty/build/one.md
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
one
|
5
test/fixtures/empty/src/one.md
vendored
Normal file
5
test/fixtures/empty/src/one.md
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: No collection here
|
||||||
|
---
|
||||||
|
|
||||||
|
one
|
1
test/fixtures/pattern/build/one.md
vendored
1
test/fixtures/pattern/build/one.md
vendored
|
@ -1 +1,2 @@
|
||||||
|
|
||||||
one
|
one
|
1
test/fixtures/pattern/build/two.md
vendored
1
test/fixtures/pattern/build/two.md
vendored
|
@ -1 +1,2 @@
|
||||||
|
|
||||||
two
|
two
|
1
test/fixtures/references/build/one.md
vendored
1
test/fixtures/references/build/one.md
vendored
|
@ -1 +1,2 @@
|
||||||
|
|
||||||
one
|
one
|
1
test/fixtures/references/build/three.md
vendored
1
test/fixtures/references/build/three.md
vendored
|
@ -1 +1,2 @@
|
||||||
|
|
||||||
three
|
three
|
1
test/fixtures/references/build/two.md
vendored
1
test/fixtures/references/build/two.md
vendored
|
@ -1 +1,2 @@
|
||||||
|
|
||||||
two
|
two
|
1
test/fixtures/sort/build/one.md
vendored
1
test/fixtures/sort/build/one.md
vendored
|
@ -1 +1,2 @@
|
||||||
|
|
||||||
one
|
one
|
1
test/fixtures/sort/build/three.md
vendored
1
test/fixtures/sort/build/three.md
vendored
|
@ -1 +1,2 @@
|
||||||
|
|
||||||
three
|
three
|
1
test/fixtures/sort/build/two.md
vendored
1
test/fixtures/sort/build/two.md
vendored
|
@ -1 +1,2 @@
|
||||||
|
|
||||||
two
|
two
|
|
@ -128,4 +128,21 @@ describe('metalsmith-collections', function(){
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
it('should not fail with empty collections', function(done) {
|
||||||
|
var metalsmith = Metalsmith('test/fixtures/empty');
|
||||||
|
metalsmith
|
||||||
|
.use(collections({
|
||||||
|
articles: {
|
||||||
|
sortBy: 'date',
|
||||||
|
reverse: true
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.build(function(err) {
|
||||||
|
if (err) return done(err);
|
||||||
|
var articles = metalsmith.metadata().articles;
|
||||||
|
assert.equal(articles.length, 0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue