diff options
author | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-06-15 23:30:43 -0700 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-06-15 23:30:43 -0700 |
commit | 94bbbecedfc0816d600193119e1b30272803672d (patch) | |
tree | 417350bbe84dd054dd216343825271585fd9858d /lib/parse | |
parent | f49eab42a9c0033833c2ab5382217a0baf490d1f (diff) | |
download | gitbook-94bbbecedfc0816d600193119e1b30272803672d.zip gitbook-94bbbecedfc0816d600193119e1b30272803672d.tar.gz gitbook-94bbbecedfc0816d600193119e1b30272803672d.tar.bz2 |
Support custom intro node, fixes #318
Diffstat (limited to 'lib/parse')
-rw-r--r-- | lib/parse/navigation.js | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/lib/parse/navigation.js b/lib/parse/navigation.js index 2c783e4..f216d03 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]); |