mirror of
https://github.com/vale981/metalsmith-collections
synced 2025-03-05 09:21:39 -05:00
Fixed tests
This commit is contained in:
parent
8854628743
commit
6df36fffe1
8 changed files with 47 additions and 10 deletions
21
lib/index.js
21
lib/index.js
|
@ -38,7 +38,6 @@ function plugin(opts){
|
||||||
match(file, data).forEach(function(key){
|
match(file, data).forEach(function(key){
|
||||||
metadata[key] = metadata[key] || [];
|
metadata[key] = metadata[key] || [];
|
||||||
metadata[key].push(data);
|
metadata[key].push(data);
|
||||||
// data.collection = key;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -154,20 +153,22 @@ function matcher(cols){
|
||||||
|
|
||||||
return function(file, data){
|
return function(file, data){
|
||||||
var matches = [];
|
var matches = [];
|
||||||
var collections = data.collection || [];
|
|
||||||
|
|
||||||
if (!Array.isArray(collections)) {
|
if (data.collection) {
|
||||||
collections = [collections];
|
var collection = data.collection;
|
||||||
}
|
if (!Array.isArray(collection)) collection = [collection];
|
||||||
|
collection.forEach(function(key){
|
||||||
collections.forEach(function(key){
|
|
||||||
if (key && ~keys.indexOf(key)) matches.push(key);
|
if (key && ~keys.indexOf(key)) matches.push(key);
|
||||||
for (key in matchers){
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
return unique(matches);
|
data.collection = unique(matches);
|
||||||
|
return data.collection;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
2
test/fixtures/multi/build/one.md
vendored
Normal file
2
test/fixtures/multi/build/one.md
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
one
|
1
test/fixtures/multi/build/three.md
vendored
Normal file
1
test/fixtures/multi/build/three.md
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
three
|
2
test/fixtures/multi/build/two.md
vendored
Normal file
2
test/fixtures/multi/build/two.md
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
two
|
5
test/fixtures/multi/src/one.md
vendored
Normal file
5
test/fixtures/multi/src/one.md
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
collection: articles
|
||||||
|
---
|
||||||
|
|
||||||
|
one
|
1
test/fixtures/multi/src/three.md
vendored
Normal file
1
test/fixtures/multi/src/three.md
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
three
|
8
test/fixtures/multi/src/two.md
vendored
Normal file
8
test/fixtures/multi/src/two.md
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
collection:
|
||||||
|
- articles
|
||||||
|
- posts
|
||||||
|
- drafts
|
||||||
|
---
|
||||||
|
|
||||||
|
two
|
|
@ -194,4 +194,21 @@ describe('metalsmith-collections', function(){
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should allow multiple collections', function (done) {
|
||||||
|
var metalsmith = Metalsmith('test/fixtures/multi');
|
||||||
|
metalsmith
|
||||||
|
.use(collections({ articles: {}, posts: {}, drafts: {} }))
|
||||||
|
.build(function(err){
|
||||||
|
if (err) return done(err);
|
||||||
|
var m = metalsmith.metadata();
|
||||||
|
assert.equal(2, m.articles.length);
|
||||||
|
assert.equal(1, m.drafts.length);
|
||||||
|
assert.equal(1, m.posts.length);
|
||||||
|
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