Support custom intro node, fixes #318

This commit is contained in:
Aaron O'Mullan
2014-06-15 23:30:43 -07:00
parent f49eab42a9
commit 94bbbecedf
+23 -8
View File
@@ -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]);