summaryrefslogtreecommitdiffstats
path: root/lib/template.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-09-15 11:09:08 +0200
committerSamy Pessé <samypesse@gmail.com>2015-09-15 11:09:08 +0200
commitbaf10e9b159b64c30ce650c83eb437675434e3e2 (patch)
tree583fc00922e6ca52fea87947af0b4d5703aabf7d /lib/template.js
parent463a947df1e5c8c862c555a5b0ae675e356a0d5c (diff)
downloadgitbook-baf10e9b159b64c30ce650c83eb437675434e3e2.zip
gitbook-baf10e9b159b64c30ce650c83eb437675434e3e2.tar.gz
gitbook-baf10e9b159b64c30ce650c83eb437675434e3e2.tar.bz2
Improve book.resolve to ensure file is in the book
Adapt tests to plugin-highlight
Diffstat (limited to 'lib/template.js')
-rw-r--r--lib/template.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/template.js b/lib/template.js
index 4b2035f..b1bc632 100644
--- a/lib/template.js
+++ b/lib/template.js
@@ -30,7 +30,7 @@ var BookLoader = nunjucks.Loader.extend({
git.resolveFile(fileurl)
.then(function(filepath) {
// Is local file
- if (!filepath) filepath = that.book.resolve(fileurl);
+ if (!filepath) filepath = path.resolve(fileurl);
else that.book.log.debug.ln("resolve from git", fileurl, "to", filepath)
// Read file from absolute path
@@ -46,6 +46,12 @@ var BookLoader = nunjucks.Loader.extend({
},
resolve: function(from, to) {
+ // If origin is in the book, we enforce result file to be in the book
+ if (this.book.fileIsInBook(from)) {
+ return this.book.resolve(path.dirname(from), to);
+ }
+
+ // If origin is not in the book (include from a git content ref)
return path.resolve(path.dirname(from), to);
}
});