diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-28 16:36:17 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-28 16:36:17 +0100 |
commit | 56d1720aaea2472f12e045f61a2fb0bdf7da9343 (patch) | |
tree | ac1b18bd3851e3395d1dee9eca5a2ae11ee66c84 /lib/book.js | |
parent | 02d7102c687c3d2295bd1586fe6e79f14396e740 (diff) | |
download | gitbook-56d1720aaea2472f12e045f61a2fb0bdf7da9343.zip gitbook-56d1720aaea2472f12e045f61a2fb0bdf7da9343.tar.gz gitbook-56d1720aaea2472f12e045f61a2fb0bdf7da9343.tar.bz2 |
Improve image conversion to png to avoid doublons
Diffstat (limited to 'lib/book.js')
-rw-r--r-- | lib/book.js | 62 |
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()); + }); } }) |