summaryrefslogtreecommitdiffstats
path: root/lib/book.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/book.js')
-rw-r--r--lib/book.js31
1 files changed, 24 insertions, 7 deletions
diff --git a/lib/book.js b/lib/book.js
index 2e0ab58..08dd6dc 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -10,6 +10,7 @@ var fs = require("./utils/fs");
var parseNavigation = require("./utils/navigation");
var parseProgress = require("./utils/progress");
var pageUtil = require("./utils/page");
+var pathUtil = require("./utils/path");
var batch = require("./utils/batch");
var links = require("./utils/links");
var i18n = require("./utils/i18n");
@@ -512,7 +513,7 @@ Book.prototype.parsePage = function(filename, options) {
var interpolate = function(fn) {
return Q(fn(page))
.then(function(_page) {
- page = _page;
+ page = _page || page;
});
};
@@ -630,21 +631,26 @@ Book.prototype.findFile = function(filename) {
// Check if a file exists in the book
Book.prototype.fileExists = function(filename) {
return fs.exists(
- path.join(this.root, filename)
+ this.resolve(filename)
);
};
+// Check if a file path is inside the book
+Book.prototype.fileIsInBook = function(filename) {
+ return pathUtil.isInRoot(this.root, filename);
+};
+
// Read a file
Book.prototype.readFile = function(filename) {
return fs.readFile(
- path.join(this.root, filename),
+ this.resolve(filename),
{ encoding: "utf8" }
);
};
// Return stat for a file
Book.prototype.statFile = function(filename) {
- return fs.stat(path.join(this.root, filename));
+ return fs.stat(this.resolve(filename));
};
// List all files in the book
@@ -702,9 +708,20 @@ Book.prototype.isEntryPoint = function(fp) {
return fp == this.readmeFile;
};
-// Resolve a path in book
-Book.prototype.resolve = function(p) {
- return path.resolve(this.root, p);
+// Alias to book.config.get
+Book.prototype.getConfig = function(key, def) {
+ return this.config.get(key, def);
+};
+
+// Resolve a path in the book source
+// Enforce that the output path in the root folder
+Book.prototype.resolve = function() {
+ return pathUtil.resolveInRoot.apply(null, [this.root].concat(_.toArray(arguments)));
+};
+
+// Convert an abslute path into a relative path to this
+Book.prototype.relative = function(p) {
+ return path.relative(this.root, p);
};
// Normalize a path to .html and convert README -> index