From 94bbbecedfc0816d600193119e1b30272803672d Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Sun, 15 Jun 2014 23:30:43 -0700 Subject: [PATCH] Support custom intro node, fixes #318 --- lib/parse/navigation.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/parse/navigation.js b/lib/parse/navigation.js index 2c783e410..f216d03ec 100644 --- a/lib/parse/navigation.js +++ b/lib/parse/navigation.js @@ -12,6 +12,27 @@ function flattenChapters(chapters) { }, []); } +function defaultChapters(flatChapters) { + // Special README nav + var README_NAV = { + path: 'README.md', + title: 'Introduction', + level: '0', + }; + + // First chapter + var first = _.first(flatChapters); + + // Check for intro node + if(first && first.path === 'README.md') { + // If present, return unmodified + return flatChapters; + } + + // Otherwise add in default node + return [README_NAV].concat(flatChapters); +} + // Returns from a summary a map of /* { @@ -26,15 +47,9 @@ function navigation(summary, files) { // Support single files as well as list files = _.isArray(files) ? files : (_.isString(files) ? [files] : null); - // Special README nav - var README_NAV = { - path: 'README.md', - title: 'Introduction', - level: '0', - }; - // List of all navNodes - var navNodes = [README_NAV].concat(flattenChapters(summary.chapters)); + // Flatten chapters, then add in default README node if ndeeded etc ... + var navNodes = defaultChapters(flattenChapters(summary.chapters)); var prevNodes = [null].concat(navNodes.slice(0, -1)); var nextNodes = navNodes.slice(1).concat([null]);