mirror of
https://github.com/vale981/metalsmith-collections
synced 2025-03-04 17:01:41 -05:00
Allow front matter and pattern collections.
Adjust the matching code to allow collections to be defined in the front matter and by pattern. Currently if you define collection in the front matter no patterns will match that file. This aides in building something like a tagging system on a blog. All posts can be matched with something like `'*.md'` or `'blog/**/*'` and then tags can be added in the individual posts `collection` front matter.
This commit is contained in:
parent
be95d2b0bd
commit
ee4ddb98b7
2 changed files with 22 additions and 5 deletions
|
@ -171,11 +171,10 @@ function matcher(cols){
|
|||
debug('adding new collection through metadata: %s', key);
|
||||
});
|
||||
}
|
||||
else {
|
||||
for (var key in matchers){
|
||||
var m = matchers[key];
|
||||
if (m && m.match(file)) matches.push(key);
|
||||
}
|
||||
|
||||
for (var key in matchers){
|
||||
var m = matchers[key];
|
||||
if (m && m.match(file)) matches.push(key);
|
||||
}
|
||||
|
||||
data.collection = unique(matches);
|
||||
|
|
|
@ -243,4 +243,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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue