diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-24 12:56:26 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-24 12:56:26 +0100 |
commit | bd73c7978743329f893c1125d1645b8aa24eb7d8 (patch) | |
tree | 63a311016951e500478a39d97c30e9473f95854d /lib | |
parent | b244d506bd49526abbcfe84e2175b3410bbabb8c (diff) | |
download | gitbook-bd73c7978743329f893c1125d1645b8aa24eb7d8.zip gitbook-bd73c7978743329f893c1125d1645b8aa24eb7d8.tar.gz gitbook-bd73c7978743329f893c1125d1645b8aa24eb7d8.tar.bz2 |
Don't copy assets for each language book, but only for main book
Diffstat (limited to 'lib')
-rw-r--r-- | lib/book.js | 11 | ||||
-rw-r--r-- | lib/output/base.js | 15 | ||||
-rw-r--r-- | lib/output/website.js | 21 |
3 files changed, 40 insertions, 7 deletions
diff --git a/lib/book.js b/lib/book.js index 86b1d67..d8c6542 100644 --- a/lib/book.js +++ b/lib/book.js @@ -187,7 +187,10 @@ Book.prototype.parse = function() { that.books.push(langBook); - return langBook.parse(); + return langBook.parse() + .then(function() { + langBook.config.set('output', path.join(that.config.get('output'), lang.id)); + }); }); } @@ -320,10 +323,12 @@ Book.prototype.isInBook = function(filename) { // Return true if file is in the scope of a child book Book.prototype.isInLanguageBook = function(filename) { + var that = this; + return _.some(this.langs.list(), function(lang) { return pathUtil.isInRoot( - this.resolve(lang.id), - this.resolve(filename) + that.resolve(lang.id), + that.resolve(filename) ); }); }; diff --git a/lib/output/base.js b/lib/output/base.js index fdddfe8..77c2d9f 100644 --- a/lib/output/base.js +++ b/lib/output/base.js @@ -96,6 +96,16 @@ Output.prototype.generate = function() { }); }) + // Generate sub-books + .then(function() { + if (!that.book.isMultilingual()) return; + + return Promise.serie(that.book.books, function(subbook) { + var out = that.onLanguageBook(subbook); + return out.generate(); + }); + }) + // Finish the generation .then(function() { that.log.debug.ln('finishing the generation'); @@ -179,6 +189,11 @@ Output.prototype.onResolveTemplate = function(from, to) { return path.resolve(path.dirname(from), to); }; +// Prepare output for a language book +Output.prototype.onLanguageBook = function(book) { + return new this.constructor(book, this.opts); +}; + // ---- Utilities ---- diff --git a/lib/output/website.js b/lib/output/website.js index d480550..6961a28 100644 --- a/lib/output/website.js +++ b/lib/output/website.js @@ -5,6 +5,7 @@ var nunjucks = require('nunjucks'); var I18n = require('i18n-t'); var Promise = require('../utils/promise'); +var location = require('../utils/location'); var fs = require('../utils/fs'); var defaultFilters = require('../template/filters'); var conrefsLoader = require('./conrefs'); @@ -106,25 +107,36 @@ WebsiteOutput.prototype.prepare = function() { // Transform an absolute path into a relative path // using this.ctx.page.path that.env.addFilter('resolveFile', function(href) { - return that.resolveForPage(this.ctx.file.path, href); + return location.normalize(that.resolveForPage(this.ctx.file.path, href)); }); // Transform a '.md' into a '.html' (README -> index) that.env.addFilter('contentURL', function(s) { - return that.outputUrl(s); + return location.normalize(that.outputUrl(s)); }); // Relase path to an asset that.env.addFilter('resolveAsset', function(href) { href = path.join('gitbook', href); - if (!this.ctx.file) return href; - return that.resolveForPage(this.ctx.file.path, '/' + href); + // Resolve for current file + if (this.ctx.file) { + href = that.resolveForPage(this.ctx.file.path, '/' + href); + } + + // Use assets from parent + if (that.book.isLanguageBook()) { + href = path.join('../', href); + } + + return location.normalize(href); }); }) // Copy assets from themes before copying files from book .then(function() { + if (that.book.isLanguageBook()) return; + return Promise.serie([ // Assets from the book are already copied // The order is reversed from the template's one @@ -196,6 +208,7 @@ WebsiteOutput.prototype.finish = function() { // Copy assets from plugins .then(function() { + if (that.book.isLanguageBook()) return; return that.plugins.copyResources(that.name, that.resolve('gitbook')); }); }; |