diff options
Diffstat (limited to 'lib/output/modifiers/fetchRemoteImages.js')
-rw-r--r-- | lib/output/modifiers/fetchRemoteImages.js | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/lib/output/modifiers/fetchRemoteImages.js b/lib/output/modifiers/fetchRemoteImages.js deleted file mode 100644 index ef868b9..0000000 --- a/lib/output/modifiers/fetchRemoteImages.js +++ /dev/null @@ -1,44 +0,0 @@ -var path = require('path'); -var crc = require('crc'); - -var editHTMLElement = require('./editHTMLElement'); -var fs = require('../../utils/fs'); -var LocationUtils = require('../../utils/location'); - -/** - Fetch all remote images - - @param {String} rootFolder - @param {String} currentFile - @param {HTMLDom} $ - @return {Promise} -*/ -function fetchRemoteImages(rootFolder, currentFile, $) { - var currentDirectory = path.dirname(currentFile); - - return editHTMLElement($, 'img', function($img) { - var src = $img.attr('src'); - var extension = path.extname(src); - - if (!LocationUtils.isExternal(src)) { - return; - } - - // We avoid generating twice the same PNG - var hash = crc.crc32(src).toString(16); - var fileName = hash + extension; - var filePath = path.join(rootFolder, fileName); - - return fs.assertFile(filePath, function() { - return fs.download(src, filePath); - }) - .then(function() { - // Convert to relative - src = LocationUtils.relative(currentDirectory, fileName); - - $img.replaceWith('<img src="' + src + '" />'); - }); - }); -} - -module.exports = fetchRemoteImages; |