assemble-related-pages
Advanced tools
Comparing version 0.0.1 to 0.0.2
module.exports = function (grunt) { | ||
var relatedTags = require('./lib/index')(); | ||
//var relatedTags = require('./lib/index')(); | ||
@@ -12,3 +12,3 @@ grunt.initConfig({ | ||
plugins: [ | ||
relatedTags | ||
'./lib/*.js' | ||
] | ||
@@ -15,0 +15,0 @@ }, |
@@ -1,51 +0,48 @@ | ||
module.exports = function () { | ||
var relations = {}; | ||
var relations = {}; | ||
module.exports = function (params, callback) { | ||
var grunt = params.grunt; | ||
var async = grunt.util.async; | ||
var _ = grunt.util._; | ||
return function (params, callback) { | ||
var grunt = params.grunt; | ||
var async = grunt.util.async; | ||
var _ = grunt.util._; | ||
var context = params.context; | ||
var page = context.page; | ||
var pages = context.pages; | ||
var context = params.context; | ||
var page = context.page; | ||
var pages = context.pages; | ||
page.related = page.related || []; | ||
var tags = page.data.tags || []; | ||
page.related = page.related || []; | ||
var tags = page.data.tags || []; | ||
async.forEachSeries(pages, function (otherPage, next) { | ||
if (page.src === otherPage.src) { | ||
next(); | ||
async.forEachSeries(pages, function (otherPage, next) { | ||
if (page.src === otherPage.src) { | ||
next(); | ||
return; | ||
} | ||
relations[page.src] = relations[page.src] || []; | ||
relations[otherPage.src] = relations[otherPage.src] || []; | ||
if (relations[page.src].indexOf(otherPage.src) !== -1 || relations[otherPage.src].indexOf(page.src) !== -1) { | ||
next(); | ||
return; | ||
} | ||
var otherTags = otherPage.data.tags || []; | ||
var related = false; | ||
tags.forEach(function (tag) { | ||
if (related) { | ||
return; | ||
} | ||
relations[page.src] = relations[page.src] || []; | ||
relations[otherPage.src] = relations[otherPage.src] || []; | ||
if (relations[page.src].indexOf(otherPage.src) !== -1 || relations[otherPage.src].indexOf(page.src) !== -1) { | ||
next(); | ||
return; | ||
if (otherTags.indexOf(tag) !== -1) { | ||
related = true; | ||
} | ||
var otherTags = otherPage.data.tags || []; | ||
var related = false; | ||
tags.forEach(function (tag) { | ||
if (related) { | ||
return; | ||
} | ||
if (otherTags.indexOf(tag) !== -1) { | ||
related = true; | ||
} | ||
}); | ||
if (related) { | ||
otherPage.related = otherPage.related || []; | ||
// use `omit` to prevent recursion error | ||
page.related.push(_.omit(otherPage, ['related'])); | ||
otherPage.related.push(_.omit(page, ['related'])); | ||
relations[page.src].push(otherPage.src); | ||
relations[otherPage.src].push(page.src); | ||
} | ||
next(); | ||
}, function (err) { | ||
callback(); | ||
}); | ||
}; | ||
if (related) { | ||
otherPage.related = otherPage.related || []; | ||
// use `omit` to prevent recursion error | ||
page.related.push(_.omit(otherPage, ['related'])); | ||
otherPage.related.push(_.omit(page, ['related'])); | ||
relations[page.src].push(otherPage.src); | ||
relations[otherPage.src].push(page.src); | ||
} | ||
next(); | ||
}, function (err) { | ||
callback(); | ||
}); | ||
}; |
{ | ||
"name": "assemble-related-pages", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "An Assemble plugin for generating lists of related pages.", | ||
@@ -28,3 +28,3 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"assemble": "git://github.com/adjohnson916/assemble#85cd5b62676294311a5dee317fb18f85ce4fd8b2", | ||
"assemble": "~0.4.10", | ||
"grunt": "~0.4.1" | ||
@@ -31,0 +31,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
# assemble-related-pages | ||
# assemble-related-pages [![NPM version](https://badge.fury.io/js/assemble-related-pages.png)](http://badge.fury.io/js/assemble-related-pages) | ||
@@ -7,4 +7,2 @@ An [Assemble](http://assemble.io) plugin for generating lists of related pages. | ||
For now, this depends on [my modified version of Assemble](https://github.com/adjohnson916/assemble), which supports plugins. Hopefully that makes it into Assemble proper ([see my pull request](https://github.com/assemble/assemble/pull/325)). | ||
## Usage | ||
@@ -25,3 +23,3 @@ | ||
options: { | ||
plugins: [ require('assemble-related-pages')() ] | ||
plugins: [ 'assemble-related-pages' ] | ||
}, | ||
@@ -49,2 +47,2 @@ pages: { | ||
See `example/1/src` and the `assemble:example_1` task in `Gruntfile.js`. | ||
See `example/1/src` and the `assemble:example_1` task in `Gruntfile.js`. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7300
68
46