Merge pull request #21 from mikestopcontinues/refer-false

add ability to disable next/previous references with opts[key].refer === false
This commit is contained in:
Dominic Barnes 2015-02-06 20:44:36 -08:00
commit be95d2b0bd
8 changed files with 40 additions and 0 deletions

View file

@ -88,8 +88,10 @@ function plugin(opts){
keys.forEach(function(key){
debug('referencing collection: %s', key);
var settings = opts[key];
var col = metadata[key];
var last = col.length - 1;
if (settings.refer === false) return;
col.forEach(function(file, i){
if (0 != i) file.previous = col[i-1];
if (last != i) file.next = col[i+1];

View file

@ -0,0 +1,2 @@
one

View file

@ -0,0 +1,2 @@
three

View file

@ -0,0 +1,2 @@
two

View file

@ -0,0 +1,5 @@
---
collection: articles
---
one

View file

@ -0,0 +1,5 @@
---
collection: articles
---
three

View file

@ -0,0 +1,5 @@
---
collection: articles
---
two

View file

@ -129,6 +129,23 @@ describe('metalsmith-collections', function(){
});
});
it('should not add references if opts[key].refer === false', function(done){
var metalsmith = Metalsmith('test/fixtures/references-off');
metalsmith
.use(collections({ articles: { refer: false }}))
.build(function(err){
if (err) return done(err);
var articles = metalsmith.metadata().articles;
assert(!articles[0].previous);
assert(!articles[0].next);
assert(!articles[1].previous);
assert(!articles[1].next);
assert(!articles[2].previous);
assert(!articles[2].next);
done();
});
});
it('should not fail with empty collections', function(done) {
var metalsmith = Metalsmith('test/fixtures/empty');
metalsmith