summaryrefslogtreecommitdiffstats
path: root/lib/book.js
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2015-05-27 21:05:36 +0200
committerSamy Pesse <samypesse@gmail.com>2015-05-27 21:05:36 +0200
commit36e2236e6bad2071ae604eccb46331bb7da3b79c (patch)
treea8aafce09b34979dbb3bc38ad6fb3df30725baa6 /lib/book.js
parent72df665520353d404efbf9fe46d3afd73631884e (diff)
downloadgitbook-36e2236e6bad2071ae604eccb46331bb7da3b79c.zip
gitbook-36e2236e6bad2071ae604eccb46331bb7da3b79c.tar.gz
gitbook-36e2236e6bad2071ae604eccb46331bb7da3b79c.tar.bz2
Fix #765: in init handle correctly empty entries
Add tests for it, fix #769
Diffstat (limited to 'lib/book.js')
-rw-r--r--lib/book.js18
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/book.js b/lib/book.js
index ac0fc82..2e0ab58 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -789,20 +789,19 @@ Book.prototype.normError = function(err, opts, defs) {
};
// Init and return a book
-Book.init = function(root) {
- var book = new Book(root);
+Book.init = function(root, opts) {
+ var book = new Book(root, opts);
var extensionToUse = ".md";
var chaptersPaths = function(chapters) {
return _.reduce(chapters || [], function(accu, chapter) {
- if (!chapter.path) return accu;
+ var o = {
+ title: chapter.title
+ };
+ if (chapter.path) o.path = chapter.path;
+
return accu.concat(
- _.filter([
- {
- title: chapter.title,
- path: chapter.path
- }
- ].concat(chaptersPaths(chapter.articles)))
+ [o].concat(chaptersPaths(chapter.articles))
);
}, []);
};
@@ -839,6 +838,7 @@ Book.init = function(root) {
.then(function(chapters) {
// Create files that don't exist
return Q.all(_.map(chapters, function(chapter) {
+ if (!chapter.path) return Q();
var absolutePath = path.resolve(book.root, chapter.path);
return fs.exists(absolutePath)