mirror of
https://github.com/vale981/metalsmith-collections
synced 2025-03-05 09:21:39 -05:00
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:
commit
be95d2b0bd
8 changed files with 40 additions and 0 deletions
|
@ -88,8 +88,10 @@ function plugin(opts){
|
||||||
|
|
||||||
keys.forEach(function(key){
|
keys.forEach(function(key){
|
||||||
debug('referencing collection: %s', key);
|
debug('referencing collection: %s', key);
|
||||||
|
var settings = opts[key];
|
||||||
var col = metadata[key];
|
var col = metadata[key];
|
||||||
var last = col.length - 1;
|
var last = col.length - 1;
|
||||||
|
if (settings.refer === false) return;
|
||||||
col.forEach(function(file, i){
|
col.forEach(function(file, i){
|
||||||
if (0 != i) file.previous = col[i-1];
|
if (0 != i) file.previous = col[i-1];
|
||||||
if (last != i) file.next = 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) {
|
it('should not fail with empty collections', function(done) {
|
||||||
var metalsmith = Metalsmith('test/fixtures/empty');
|
var metalsmith = Metalsmith('test/fixtures/empty');
|
||||||
metalsmith
|
metalsmith
|
||||||
|
|
Loading…
Add table
Reference in a new issue