Merge pull request #25 from boushley/master

Allow front matter and pattern collections.
This commit is contained in:
Dominic Barnes 2015-02-07 12:38:44 -08:00
commit 0d84c978ba
2 changed files with 22 additions and 5 deletions

View file

@ -175,11 +175,10 @@ function matcher(cols){
debug('adding new collection through metadata: %s', key); debug('adding new collection through metadata: %s', key);
}); });
} }
else {
for (var key in matchers){ for (var key in matchers){
var m = matchers[key]; var m = matchers[key];
if (m && m.match(file)) matches.push(key); if (m && m.match(file)) matches.push(key);
}
} }
data.collection = unique(matches); data.collection = unique(matches);

View file

@ -283,4 +283,22 @@ describe('metalsmith-collections', function(){
}); });
}); });
it('should allow collections by pattern and front matter', function (done) {
var metalsmith = Metalsmith('test/fixtures/multi');
metalsmith
.use(collections({ articles: {}, posts: {}, drafts: {}, blog: '*.md' }))
.build(function(err){
if (err) return done(err);
var m = metalsmith.metadata();
assert.equal(3, m.blog.length);
assert.equal(2, m.articles.length);
assert.equal(1, m.drafts.length);
assert.equal(1, m.posts.length);
assert.equal(m.collections.blog, m.blog);
assert.equal(m.collections.articles, m.articles);
assert.equal(m.collections.drafts, m.drafts);
assert.equal(m.collections.posts, m.posts);
done();
});
});
}); });