mirror of
https://github.com/vale981/metalsmith-collections
synced 2025-03-05 09:21:39 -05:00
add shorthand for pattern matching
This commit is contained in:
parent
97d1d86bf5
commit
f573929416
2 changed files with 31 additions and 1 deletions
19
lib/index.js
19
lib/index.js
|
@ -19,7 +19,7 @@ module.exports = plugin;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function plugin(opts){
|
function plugin(opts){
|
||||||
opts = opts || {};
|
opts = normalize(opts);
|
||||||
var keys = Object.keys(opts);
|
var keys = Object.keys(opts);
|
||||||
var match = matcher(opts);
|
var match = matcher(opts);
|
||||||
|
|
||||||
|
@ -79,6 +79,23 @@ function plugin(opts){
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize an `options` dictionary.
|
||||||
|
*
|
||||||
|
* @param {Object} options
|
||||||
|
*/
|
||||||
|
|
||||||
|
function normalize(options){
|
||||||
|
options = options || {};
|
||||||
|
|
||||||
|
for (var key in options) {
|
||||||
|
var val = options[key];
|
||||||
|
if ('string' == typeof val) options[key] = { pattern: val };
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a matching function for a given set of `collections`.
|
* Generate a matching function for a given set of `collections`.
|
||||||
*
|
*
|
||||||
|
|
|
@ -30,6 +30,19 @@ describe('metalsmith-collections', function(){
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should take a pattern shorthand string', function(done){
|
||||||
|
var metalsmith = Metalsmith('test/fixtures/basic');
|
||||||
|
metalsmith
|
||||||
|
.use(collections({
|
||||||
|
articles: '*.md'
|
||||||
|
}))
|
||||||
|
.build(function(err){
|
||||||
|
if (err) return done(err);
|
||||||
|
assert.equal(3, metalsmith.metadata().articles.length);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should accept a "sortBy" option', function(done){
|
it('should accept a "sortBy" option', function(done){
|
||||||
var metalsmith = Metalsmith('test/fixtures/sort');
|
var metalsmith = Metalsmith('test/fixtures/sort');
|
||||||
metalsmith
|
metalsmith
|
||||||
|
|
Loading…
Add table
Reference in a new issue