summaryrefslogtreecommitdiffstats
path: root/lib/book.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/book.js')
-rw-r--r--lib/book.js26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/book.js b/lib/book.js
index e61d771..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,12 +838,17 @@ 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)
.then(function(exists) {
- book.log.info.ln("create", chapter.path);
- if(exists) return;
+ if(exists) {
+ book.log.info.ln("found", chapter.path);
+ return;
+ } else {
+ book.log.info.ln("create", chapter.path);
+ }
return fs.mkdirp(path.dirname(absolutePath))
.then(function() {