Skip to content

Commit abf86d9

Browse files
committed
use is-valid-app
1 parent ef6d312 commit abf86d9

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
'use strict';
99

1010
var path = require('path');
11-
var through = require('through2');
1211
var utils = require('./utils');
1312

1413
/**
@@ -25,21 +24,24 @@ module.exports = function permalinksPlugin(pattern, config) {
2524
var args = [].slice.call(arguments);
2625

2726
return function appPlugin(app) {
28-
if (!app.isApp) {
27+
if (!utils.isValid(app, 'assemble-permalinks')) {
2928
return collectionPlugin.apply(this, arguments);
3029
}
31-
app.emit('plugin', 'assemble-permalinks');
3230

3331
app.define('permalink', pipeline(pattern));
3432

3533
function collectionPlugin(collection) {
3634
if (collection.isView || collection.isItem) {
3735
return viewPlugin.apply(this, arguments);
3836
}
39-
collection.emit('plugin', 'assemble-permalinks');
37+
38+
if (!utils.isValid(collection, 'assemble-permalinks', ['collection', 'views'])) {
39+
return collectionPlugin;
40+
}
41+
4042
collection.define('permalink', pipeline(pattern));
4143

42-
app.onLoad(/./, function(file, next) {
44+
collection.onLoad(/./, function(file, next) {
4345
if (collection.options.plural !== file.options.collection) {
4446
return next();
4547
}
@@ -51,7 +53,10 @@ module.exports = function permalinksPlugin(pattern, config) {
5153
});
5254

5355
function viewPlugin(view) {
54-
view.emit('plugin', 'assemble-permalinks');
56+
if (!utils.isValid(view, 'assemble-permalinks', ['view', 'item'])) {
57+
return;
58+
}
59+
5560
this.define('permalink', function(dest, opts) {
5661
if (typeof dest !== 'string') {
5762
opts = dest;
@@ -104,7 +109,7 @@ module.exports = function permalinksPlugin(pattern, config) {
104109

105110
function pipeline(pattern) {
106111
return function(viewPattern, data) {
107-
return through.obj(function(view, enc, next) {
112+
return utils.through.obj(function(view, enc, next) {
108113
var structure = viewPattern || pattern;
109114
try {
110115
view.permalink(structure, data);

utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ require = utils;
1212
* Lazily required module dependencies
1313
*/
1414

15+
require('is-valid-app', 'isValid');
1516
require('isobject', 'isObject');
1617
require('mixin-deep', 'merge');
1718
require('placeholders');
19+
require('through2', 'through');
1820
require = fn;
1921

2022
/**

0 commit comments

Comments
 (0)