diff options
Diffstat (limited to 'lib/book.js')
-rw-r--r-- | lib/book.js | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/lib/book.js b/lib/book.js index 09bd59f..ca8c0c0 100644 --- a/lib/book.js +++ b/lib/book.js @@ -123,7 +123,16 @@ Book.prototype.getContext = function() { // Parse and prepare the configuration, fail if invalid Book.prototype.prepareConfig = function() { - return this.config.load(); + var that = this; + + return this.config.load() + .then(function() { + var root = that.config.get('root'); + if (!root) return; + + that.originalRoot = that.root; + that.root = path.resolve(that.root, root); + }) }; // Resolve a path in the book source @@ -344,35 +353,14 @@ Book.prototype.isInLanguageBook = function(filename) { }); }; -// Locate a book in a folder -// - Read the ".gitbook" is exists -// - Try the folder itself -// - Try a "docs" folder -Book.locate = function(fs, root) { - return fs.readAsString(path.join(root, '.gitbook')) - .then(function(content) { - return path.join(root, content); - }, function() { - // .gitbook doesn't exists, fall back to the root folder - return Promise(root); - }); -}; - -// Locate and setup a book -Book.setup = function(fs, root, opts) { - return Book.locate(fs, root) - .then(function(_root) { - return new Book(_.extend(opts || {}, { - root: _root, - fs: fs - })); - }); -}; - // Initialize a book Book.init = function(fs, root, opts) { - return Book.setup(fs, root, opts) - .then(initBook); + var book = new Book(_.extend(opts || {}, { + root: root, + fs: fs + })); + + return initBook(book); }; |