mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 19:06:31 +00:00
Fix GitbookIO/plugin-youtube#2: hash remote image for local path
This commit is contained in:
+5
-1
@@ -22,7 +22,11 @@ var convertSVG = function(source, dest, options) {
|
||||
if (error.code == 127) error = new Error("Need to install 'svgexport' using 'npm install svgexport -g'");
|
||||
return d.reject(error);
|
||||
}
|
||||
d.resolve();
|
||||
if (fs.existsSync(dest)) {
|
||||
d.resolve();
|
||||
} else {
|
||||
d.reject(new Error("Error converting "+source));
|
||||
}
|
||||
});
|
||||
|
||||
return d.promise;
|
||||
|
||||
+6
-3
@@ -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, "...");
|
||||
|
||||
Reference in New Issue
Block a user