inliner/lib/find-assets.js
Remy Sharp 9904b6b334 feat: compress SVG using SVGO
Fixes #58

Compresses inline SVG using SVGO, and compresses CSS background SVG images by making them data URLs (using text/svg+xml mime).

Adds CLI (and lib) option: --nosvg which avoids using SVGO for compression (as it can on occassion mess up).

Also includes a refactor of the code to organise the files a little better (allowing for further inlined elements to be added).
2015-08-26 22:43:40 +01:00

25 lines
480 B
JavaScript

module.exports = findAssets;
var cheerio = require('cheerio');
var debug = require('debug')('inliner');
function findAssets(html, cheerioLoadOptions) {
var $ = cheerio.load(html, cheerioLoadOptions);
debug('loaded DOM');
var tasks = this.jobs.tasks;
var res = Object.keys(tasks).reduce(function (acc, task) {
if (task === 'html') { // skip html task
return acc;
}
acc[task] = $(tasks[task]);
return acc;
}, {});
res.$ = $;
return res;
}