summaryrefslogtreecommitdiffstats
path: root/lib/parse/summary.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-06-16 13:02:38 +0200
committerSamy Pessé <samypesse@gmail.com>2014-06-16 13:02:38 +0200
commit3d8b6e550a1ca6ed2c3f3f459c375d6c62432d91 (patch)
tree9eaf04a5adaaa568dd656b0b2de9f05730283c22 /lib/parse/summary.js
parent3245d7e430ee309961d40c1c03b4c15dac4ec232 (diff)
parent4c3dbca5ca12c2ea3806a17dc186deff5ce83b79 (diff)
downloadgitbook-3d8b6e550a1ca6ed2c3f3f459c375d6c62432d91.zip
gitbook-3d8b6e550a1ca6ed2c3f3f459c375d6c62432d91.tar.gz
gitbook-3d8b6e550a1ca6ed2c3f3f459c375d6c62432d91.tar.bz2
Merge pull request #319 from GitbookIO/enchancement/custom_intro
Enchancement/custom intro
Diffstat (limited to 'lib/parse/summary.js')
-rw-r--r--lib/parse/summary.js27
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/parse/summary.js b/lib/parse/summary.js
index 1fd5676..7e54df0 100644
--- a/lib/parse/summary.js
+++ b/lib/parse/summary.js
@@ -94,18 +94,35 @@ function parseChapter(nodes, nums) {
});
}
+function defaultChapterList(chapterList) {
+ var first = _.first(chapterList);
+
+ var chapter = parseChapter(first, [0]);
+
+ // Already have README node, we're good to go
+ if(chapter.path === 'README.md') {
+ return chapterList;
+ }
+
+ return [
+ [ { type: 'text', text: '[Introduction](README.md)' } ]
+ ].concat(chapterList);
+}
+
function parseSummary(src) {
var nodes = marked.lexer(src);
// Get out list of chapters
- var chapterList = filterList(nodes);
+ var chapterList = listSplit(
+ filterList(nodes),
+ 'list_item_start', 'list_item_end'
+ );
// Split out chapter sections
- var chapters = _.chain(listSplit(chapterList, 'list_item_start', 'list_item_end'))
+ var chapters = defaultChapterList(chapterList)
.map(function(nodes, i) {
- return parseChapter(nodes, [i + 1]);
- })
- .value();
+ return parseChapter(nodes, [i]);
+ });
return {
chapters: chapters