diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/index.js | 2 | ||||
-rw-r--r-- | lib/utils/navigation.js | 30 |
2 files changed, 24 insertions, 8 deletions
diff --git a/lib/index.js b/lib/index.js index a03f39d..44574fd 100644 --- a/lib/index.js +++ b/lib/index.js @@ -19,7 +19,7 @@ var LOG_OPTION = { var FORMAT_OPTION = { name: "format", description: "Format to build to", - values: ["website", "json"], + values: ["website", "json", "ebook"], defaults: "website" }; diff --git a/lib/utils/navigation.js b/lib/utils/navigation.js index ae4eb9d..21666ad 100644 --- a/lib/utils/navigation.js +++ b/lib/utils/navigation.js @@ -27,19 +27,35 @@ function navigation(summary, files) { files = _.isArray(files) ? files : (_.isString(files) ? [files] : null); // List of all navNodes - // Flatten chapters, then add in default README node if ndeeded etc ... + // Flatten chapters, then add in default README node if needed etc ... var navNodes = flattenChapters(summary.chapters); - var prevNodes = [null].concat(navNodes.slice(0, -1)); - var nextNodes = navNodes.slice(1).concat([null]); // Mapping of prev/next for a give path - var mapping = _.chain(_.zip(navNodes, prevNodes, nextNodes)) - .map(function(nodes) { - var current = nodes[0], prev = nodes[1], next = nodes[2]; + var mapping = _.chain(navNodes) + .map(function(current, i) { + var prev = null, next = null; // Skip if no path if(!current.path) return null; + // Find prev + prev = _.chain(navNodes) + .slice(0, i) + .reverse() + .find(function(node) { + return node.exists && !node.external; + }) + .value(); + + // Find next + next = _.chain(navNodes) + .slice(i+1) + .find(function(node) { + return node.exists && !node.external; + }) + .value(); + + return [current.path, { title: current.title, prev: prev, @@ -47,7 +63,7 @@ function navigation(summary, files) { level: current.level, }]; }) - .filter() + .compact() .object() .value(); |