diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-13 15:28:07 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-13 15:28:07 +0100 |
commit | ee3faaad1106bb773078e580c9c1611c8f31607c (patch) | |
tree | 5a6298dd565290e1776caec97f5ee9f42c65dd51 /lib/output/base.js | |
parent | d2aad34935cb243dcdaeabfc28dce150c68f6340 (diff) | |
download | gitbook-ee3faaad1106bb773078e580c9c1611c8f31607c.zip gitbook-ee3faaad1106bb773078e580c9c1611c8f31607c.tar.gz gitbook-ee3faaad1106bb773078e580c9c1611c8f31607c.tar.bz2 |
Complete assets inliner
Diffstat (limited to 'lib/output/base.js')
-rw-r--r-- | lib/output/base.js | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/output/base.js b/lib/output/base.js index 688ecb7..9acfb87 100644 --- a/lib/output/base.js +++ b/lib/output/base.js @@ -57,17 +57,27 @@ Output.prototype.generate = function() { .then(function() { return that.book.fs.listAllFiles(that.book.root); }) + + // We want to process assets first, then pages + // Since pages can have logic based on existance of assets .then(function(files) { - return Promise.serie(files, function(filename) { - // Ignore file present in a language book - if (isMultilingual && that.book.isInLanguageBook(filename)) return; + // Ignore file present in a language book + files = _.filter(files, function(filename) { + return !(isMultilingual && that.book.isInLanguageBook(filename)); + }); + + // List assets + var byTypes = _.groupBy(files, function(filename) { + return (that.book.hasPage(filename)? 'page' : 'asset'); + }); - // Process file as page or asset - if (that.book.hasPage(filename)) { + return Promise.serie(byTypes.asset, function(filename) { + return that.onAsset(filename); + }) + .then(function() { + return Promise.serie(byTypes.page, function(filename) { return that.onPage(that.book.getPage(filename)); - } else { - return that.onAsset(filename); - } + }); }); }) |