summaryrefslogtreecommitdiffstats
path: root/lib/book.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/book.js')
-rw-r--r--lib/book.js62
1 files changed, 43 insertions, 19 deletions
diff --git a/lib/book.js b/lib/book.js
index 4e4279a..62fe0db 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -200,30 +200,54 @@ Book.prototype.generate = function(generator) {
return generator.prepare();
})
+
+
// Generate content
.then(function() {
if (that.isMultilingual()) {
return that.generateMultiLingual(generator);
} else {
- // Copy file and replace markdown file
- return Q.all(
- _.chain(that.files)
- .map(function(file) {
- if (!file) return;
-
- if (file[file.length -1] == "/") {
- that.log.debug.ln("transferring folder", file);
- return Q(generator.transferFolder(file));
- } else if (_.contains(parsers.extensions, path.extname(file)) && that.navigation[file]) {
- that.log.debug.ln("converting", file);
- return Q(generator.convertFile(file));
- } else {
- that.log.debug.ln("transferring file", file);
- return Q(generator.transferFile(file));
- }
- })
- .value()
- );
+ // Separate list of files into the different operations needed
+ var ops = _.groupBy(that.files, function(file) {
+ if (file[file.length -1] == "/") {
+ return "directories";
+ } else if (_.contains(parsers.extensions, path.extname(file)) && that.navigation[file]) {
+ return "content";
+ } else {
+ return "files";
+ }
+ });
+
+
+ return Q()
+
+ // First, let's create folder
+ .then(function() {
+ return _.reduce(ops["directories"] || [], function(prev, folder) {
+ return prev.then(function() {
+ that.log.debug.ln("transferring folder", folder);
+ return Q(generator.transferFolder(folder));
+ });
+ }, Q());
+ })
+
+ // Then, let's copy other files
+ .then(function() {
+ return Q.all(_.map(ops["files"] || [], function(file) {
+ that.log.debug.ln("transferring file", file);
+ return Q(generator.transferFile(file));
+ }));
+ })
+
+ // Finally let's generate content
+ .then(function() {
+ return _.reduce(ops["content"] || [], function(prev, file) {
+ return prev.then(function() {
+ that.log.debug.ln("converting", file);
+ return Q(generator.convertFile(file));
+ });
+ }, Q());
+ });
}
})