diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-03-22 10:54:47 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-03-22 10:59:25 +0100 |
commit | e07719a86c779c8777bae4969313023b37dc671e (patch) | |
tree | a46398a30357304e3a414fab34cf69aaf1ffa163 | |
parent | fa5bee6ca374108ba806442cc7f7c422df8811c4 (diff) | |
download | gitbook-e07719a86c779c8777bae4969313023b37dc671e.zip gitbook-e07719a86c779c8777bae4969313023b37dc671e.tar.gz gitbook-e07719a86c779c8777bae4969313023b37dc671e.tar.bz2 |
Fix template search paths to use plugins listed first
-rw-r--r-- | docs/_layouts/website/page.html | 2 | ||||
-rw-r--r-- | lib/output/website.js | 4 | ||||
-rw-r--r-- | lib/plugins/index.js | 5 | ||||
-rw-r--r-- | lib/template/fs-loader.js | 25 |
4 files changed, 30 insertions, 6 deletions
diff --git a/docs/_layouts/website/page.html b/docs/_layouts/website/page.html index e2dc2ea..47954f7 100644 --- a/docs/_layouts/website/page.html +++ b/docs/_layouts/website/page.html @@ -1,4 +1,4 @@ -{% extends template.theme %} +{% extends template.self %} {% block header_nav %} <a href="https://github.com/GitbookIO/gitbook/blob/master/docs/{{ file.path }}" target="_blank" class="btn btn-link pull-right hidden-xs"> diff --git a/lib/output/website.js b/lib/output/website.js index 43f732c..2533dee 100644 --- a/lib/output/website.js +++ b/lib/output/website.js @@ -119,8 +119,8 @@ WebsiteOutput.prototype.prepare = function() { if (that.book.isLanguageBook()) return; // Assets from the book are already copied - // Copy assets from plugins - return Promise.serie(that.plugins.list(), function(plugin) { + // Copy assets from plugins (start with default plugins) + return Promise.serie(that.plugins.list().reverse(), function(plugin) { // Copy assets only if exists (don't fail otherwise) var assetFolder = path.join(plugin.root, '_assets', that.name); if (!fs.existsSync(assetFolder)) return; diff --git a/lib/plugins/index.js b/lib/plugins/index.js index f897d9c..c6f1686 100644 --- a/lib/plugins/index.js +++ b/lib/plugins/index.js @@ -84,6 +84,11 @@ PluginsManager.prototype.loadAll = function() { ); }); + // Sort plugins to match list in book.json + plugins.sort(function(a, b){ + return pluginNames.indexOf(a.name) < pluginNames.indexOf(b.name) ? -1 : 1; + }); + // Log state that.log.info.ln(_.size(plugins) + ' are installed'); if (_.size(pluginNames) != _.size(plugins)) that.log.info.ln(_.size(pluginNames) + ' explicitly listed'); diff --git a/lib/template/fs-loader.js b/lib/template/fs-loader.js index 00c4743..7f469bb 100644 --- a/lib/template/fs-loader.js +++ b/lib/template/fs-loader.js @@ -13,7 +13,7 @@ function isRelative(filename) { var Loader = nunjucks.Loader.extend({ init: function(searchPaths) { - this.searchPaths = searchPaths.map(path.normalize); + this.searchPaths = _.map(searchPaths, path.normalize); }, getSource: function(fullpath) { @@ -38,18 +38,37 @@ var Loader = nunjucks.Loader.extend({ }, resolve: function(from, to) { + var searchPaths = this.searchPaths; + // Relative template like "./test.html" if (isRelative(to) && from) { return path.resolve(path.dirname(from), to); } + // Determine in which search folder we currently are + var originalSearchPath = _.chain(this.searchPaths) + .sortBy(function(s) { + return -s.length; + }) + .find(function(basePath) { + return (from && from.indexOf(basePath) === 0); + }) + .value(); + var originalFilename = originalSearchPath? path.relative(originalSearchPath, from) : null; + + // If we are including same file from a different search path + // Slice the search paths to avoid including from previous ones + if (originalFilename == to) { + var currentIndex = searchPaths.indexOf(originalSearchPath); + searchPaths = searchPaths.slice(currentIndex + 1); + } + // Absolute template to resolve in root folder - var resultFolder = _.find(this.searchPaths, function(basePath) { + var resultFolder = _.find(searchPaths, function(basePath) { var p = path.resolve(basePath, to); return ( p.indexOf(basePath) === 0 - && p != from && fs.existsSync(p) ); }); |