mirror of
https://github.com/vale981/metalsmith-collections
synced 2025-03-05 09:21:39 -05:00
Allow collections through metadata alone
This commit is contained in:
parent
0f70d87931
commit
86509b0ad3
6 changed files with 34 additions and 1 deletions
10
lib/index.js
10
lib/index.js
|
@ -36,6 +36,11 @@ function plugin(opts){
|
|||
debug('checking file: %s', file);
|
||||
var data = files[file];
|
||||
match(file, data).forEach(function(key){
|
||||
if (key && ~~keys.indexOf(key)){
|
||||
opts[key] = {};
|
||||
keys.push(key);
|
||||
}
|
||||
|
||||
metadata[key] = metadata[key] || [];
|
||||
metadata[key].push(data);
|
||||
});
|
||||
|
@ -158,7 +163,10 @@ function matcher(cols){
|
|||
var collection = data.collection;
|
||||
if (!Array.isArray(collection)) collection = [collection];
|
||||
collection.forEach(function(key){
|
||||
if (key && ~keys.indexOf(key)) matches.push(key);
|
||||
matches.push(key);
|
||||
|
||||
if (key && ~~keys.indexOf(key))
|
||||
debug('adding new collection through metadata: %s', key);
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
|
3
test/fixtures/noconfig/src/four.md
vendored
Normal file
3
test/fixtures/noconfig/src/four.md
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
collection: books
|
||||
---
|
3
test/fixtures/noconfig/src/one.md
vendored
Normal file
3
test/fixtures/noconfig/src/one.md
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
collection: books
|
||||
---
|
3
test/fixtures/noconfig/src/three.md
vendored
Normal file
3
test/fixtures/noconfig/src/three.md
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
collection: movies
|
||||
---
|
1
test/fixtures/noconfig/src/two.md
vendored
Normal file
1
test/fixtures/noconfig/src/two.md
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
Nothing
|
|
@ -211,4 +211,19 @@ describe('metalsmith-collections', function(){
|
|||
});
|
||||
});
|
||||
|
||||
it('should allow collections through metadata alone', function (done) {
|
||||
var metalsmith = Metalsmith('test/fixtures/noconfig');
|
||||
metalsmith
|
||||
.use(collections({ movies: {} }))
|
||||
.build(function(err){
|
||||
if (err) return done(err);
|
||||
var m = metalsmith.metadata();
|
||||
assert.equal(2, m.books.length);
|
||||
assert.equal(1, m.movies.length);
|
||||
assert.equal(m.collections.books, m.books);
|
||||
assert.equal(m.collections.movies, m.movies);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue