summaryrefslogtreecommitdiffstats
path: root/lib/utils/page.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-02-12 11:40:17 +0100
committerSamy Pessé <samypesse@gmail.com>2015-02-12 11:40:17 +0100
commitd9da4e9a08e8550031f46ec30b0cdbdffe395eee (patch)
tree29b7bb18dfda6c6d2d06622a58e8a1ae34faf48f /lib/utils/page.js
parent1d0f6370add0f57f3c549826eb87a313b7df33cc (diff)
downloadgitbook-d9da4e9a08e8550031f46ec30b0cdbdffe395eee.zip
gitbook-d9da4e9a08e8550031f46ec30b0cdbdffe395eee.tar.gz
gitbook-d9da4e9a08e8550031f46ec30b0cdbdffe395eee.tar.bz2
Fix GitbookIO/plugin-youtube#2: hash remote image for local path
Diffstat (limited to 'lib/utils/page.js')
-rw-r--r--lib/utils/page.js9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/utils/page.js b/lib/utils/page.js
index ccf5dfa..20caf79 100644
--- a/lib/utils/page.js
+++ b/lib/utils/page.js
@@ -4,6 +4,7 @@ var path = require('path');
var cheerio = require('cheerio');
var domSerializer = require('dom-serializer');
var request = require('request');
+var crc = require("crc");
var links = require('./links');
var imgUtils = require('./images');
@@ -123,7 +124,7 @@ function normalizeHtml(src, options) {
// If image is external and ebook, then downlaod the images
if (isExternal) {
origin = src;
- src = "/"+fs.getUniqueFilename(outputRoot, path.basename(src));
+ src = "/"+crc.crc32(origin).toString(16)+path.extname(origin);
src = links.toAbsolute(src, options.base, options.output);
isExternal = false;
}
@@ -226,6 +227,7 @@ function normalizeHtml(src, options) {
function convertImages(images, options) {
if (!options.convertImages) return Q();
+ var downloaded = [];
options.book.log.debug.ln("convert ", images.length, "images to png");
return _.reduce(images, function(prev, image) {
@@ -235,8 +237,9 @@ function convertImages(images, options) {
// Write image if need to be download
.then(function() {
- if (!image.origin) return;
+ 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)));
})
@@ -247,7 +250,7 @@ function convertImages(images, options) {
})
// Convert
- .then(function(){
+ .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, "...");