mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 19:06:31 +00:00
Support custom intro node, fixes #318
This commit is contained in:
+23
-8
@@ -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]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user