diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-02-13 08:09:28 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-02-13 08:09:28 +0100 |
commit | b0fd2a67ea586e59f4c8370acc9c093e44d7f3bd (patch) | |
tree | a790813b647c8ae93324232e5a1105d7cde7e891 /lib/utils/page.js | |
parent | 7c8386986919f611dcdaaf917bf0c24fabcfe3a4 (diff) | |
download | gitbook-b0fd2a67ea586e59f4c8370acc9c093e44d7f3bd.zip gitbook-b0fd2a67ea586e59f4c8370acc9c093e44d7f3bd.tar.gz gitbook-b0fd2a67ea586e59f4c8370acc9c093e44d7f3bd.tar.bz2 |
Fix test with post in blocks
Diffstat (limited to 'lib/utils/page.js')
-rw-r--r-- | lib/utils/page.js | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/lib/utils/page.js b/lib/utils/page.js index f58e25a..0714958 100644 --- a/lib/utils/page.js +++ b/lib/utils/page.js @@ -9,6 +9,7 @@ var crc = require("crc"); var links = require('./links'); var imgUtils = require('./images'); var fs = require('./fs'); +var batch = require('./batch'); // Render a cheerio dom as html var renderDom = function($, dom, options) { @@ -232,33 +233,36 @@ function convertImages(images, options) { var downloaded = []; options.book.log.debug.ln("convert ", images.length, "images to png"); - return Q.all(_.map(images, function(image) { - var imgin = path.resolve(options.book.options.output, image.source); - - return Q() - - // Write image if need to be download - .then(function() { - if (!image.origin && !_.contains(downloaded, image.origin)) return; - options.book.log.debug("download image", image.origin, "..."); - downloaded.push(image.origin); - return options.book.log.debug.promise(fs.writeStream(imgin, request(image.origin))); - }) - - // Write svg if content - .then(function() { - if (!image.content) return; - return fs.writeFile(imgin, image.content); - }) - - // Convert - .then(function() { - if (!image.dest) return; - var imgout = path.resolve(options.book.options.output, image.dest); - options.book.log.debug("convert image", image.source, "to", image.dest, "..."); - return options.book.log.debug.promise(imgUtils.convertSVG(imgin, imgout)); - }); - })) + return batch.execEach(images, { + max: 100, + fn: function(image) { + var imgin = path.resolve(options.book.options.output, image.source); + + return Q() + + // Write image if need to be download + .then(function() { + if (!image.origin && !_.contains(downloaded, image.origin)) return; + options.book.log.debug("download image", image.origin, "..."); + downloaded.push(image.origin); + return options.book.log.debug.promise(fs.writeStream(imgin, request(image.origin))); + }) + + // Write svg if content + .then(function() { + if (!image.content) return; + return fs.writeFile(imgin, image.content); + }) + + // Convert + .then(function() { + if (!image.dest) return; + var imgout = path.resolve(options.book.options.output, image.dest); + options.book.log.debug("convert image", image.source, "to", image.dest, "..."); + return options.book.log.debug.promise(imgUtils.convertSVG(imgin, imgout)); + }); + } + }) .then(function() { options.book.log.debug.ok(images.length+" images converted with success"); }); |