mirror of
https://github.com/vale981/metalsmith-collections
synced 2025-03-04 17:01:41 -05:00
add ability to disable next/previous references with opts[key].refer === false
This commit is contained in:
parent
0f70d87931
commit
f0fe56bc05
8 changed files with 40 additions and 0 deletions
|
@ -83,8 +83,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];
|
||||
|
|
2
test/fixtures/references-off/build/one.md
vendored
Normal file
2
test/fixtures/references-off/build/one.md
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
one
|
2
test/fixtures/references-off/build/three.md
vendored
Normal file
2
test/fixtures/references-off/build/three.md
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
three
|
2
test/fixtures/references-off/build/two.md
vendored
Normal file
2
test/fixtures/references-off/build/two.md
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
two
|
5
test/fixtures/references-off/src/one.md
vendored
Normal file
5
test/fixtures/references-off/src/one.md
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
collection: articles
|
||||
---
|
||||
|
||||
one
|
5
test/fixtures/references-off/src/three.md
vendored
Normal file
5
test/fixtures/references-off/src/three.md
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
collection: articles
|
||||
---
|
||||
|
||||
three
|
5
test/fixtures/references-off/src/two.md
vendored
Normal file
5
test/fixtures/references-off/src/two.md
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
collection: articles
|
||||
---
|
||||
|
||||
two
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue