summaryrefslogtreecommitdiffstats
path: root/lib/output/base.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/output/base.js')
-rw-r--r--lib/output/base.js26
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);
- }
+ });
});
})