chore: merge branch 'feature/local-only'

* 'feature/local-only' of https://github.com/eigenuser/inliner:
  chore: renamed flag to --skip-absolute-urls
  chore: renamed flag to --same-origin-only
  feat: support for only inlining local files
This commit is contained in:
Remy Sharp 2016-04-19 11:19:50 +01:00
commit 731e7e9351
10 changed files with 57 additions and 1 deletions

View File

@ -12,6 +12,7 @@ function options(args) {
'noimages',
'nocompress',
'nosvg',
'skip-absolute-urls',
'videos',
'inlinemin',
],
@ -40,6 +41,9 @@ function options(args) {
argv.compressJS = false;
argv.collapseWhitespace = false;
}
if (argv['skip-absolute-urls']) {
argv.skipAbsoluteUrls = true;
}
argv.images = !argv.noimages;
argv.useStdin = !process.stdin.isTTY;

View File

@ -15,6 +15,8 @@
-V, --version output the version number
-h, --help output usage information
-m, --inlinemin inline minified files
--skip-absolute-urls
don't inline files with fully-qualified absolute URLs
Options:

View File

@ -5,5 +5,6 @@ module.exports = function () {
compressJS: true,
collapseWhitespace: true,
nosvg: false, // by default, DO compress SVG with SVGO
skipAbsoluteUrls: false,
};
};

View File

@ -5,6 +5,14 @@ function resolve(inliner, todo, $) {
debug('start %s links', todo.length);
return todo.map(function images(image) {
var url = inliner.resolve(inliner.url, $(image).attr('src'));
if (inliner.options.skipAbsoluteUrls &&
(url.indexOf('//') === 0 || url.indexOf('http') === 0)) {
debug('skipping remote image');
inliner.emit('progress', 'skipping remote image');
return false;
}
return inliner.image(url).then(function then(dataURL) {
$(image).attr('src', dataURL);
}).then(inliner.jobs.done.images);

View File

@ -32,6 +32,11 @@ function resolve(inliner, todo, $) {
inliner.emit('progress', 'skipping analytics script');
// ignore analytics
return false;
} else if (inliner.options.skipAbsoluteUrls &&
(src.indexOf('//') === 0 || src.indexOf('http') === 0)) {
debug('skipping remote scripts');
inliner.emit('progress', 'skipping remote script');
return false;
}
$script.removeAttr('src');

View File

@ -8,6 +8,12 @@ function resolve(inliner, todo, $) {
if (url.indexOf('http') !== 0) {
url = inliner.resolve(inliner.url, url);
}
if (inliner.options.skipAbsoluteUrls &&
(url.indexOf('//') === 0 || url.indexOf('http') === 0)) {
debug('skipping remote links');
inliner.emit('progress', 'skipping remote links');
return false;
}
inliner.emit('progress', 'processing external css ' + url);
return inliner.get(url).then(function then(res) {
var css = res.body;
@ -18,4 +24,4 @@ function resolve(inliner, todo, $) {
$(link).replaceWith('<style>' + css + '</style>');
});
});
}
}

View File

@ -7,6 +7,14 @@ function resolve(inliner, todo, $) {
return todo.map(function videos(video) {
var url = inliner.resolve(inliner.url, $(video).attr('src'));
var posterUrl = inliner.resolve(inliner.url, $(video).attr('poster'));
if (inliner.options.skipAbsoluteUrls &&
(url.indexOf('//') === 0 || url.indexOf('http') === 0)) {
debug('skipping remote video');
inliner.emit('progress', 'skipping remote video');
return false;
}
return Promise.all([
inliner.image(url).then(function then(dataURL) {
$(video).attr('src', dataURL);

View File

@ -0,0 +1,4 @@
{
"skipAbsoluteUrls": true,
"videos": true
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>no remote inline</title>
</head>
<body>
<script src="script-local.js"></script>
<script src="https://cdn.rawgit.com/zloirock/core-js/master/client/shim.min.js"></script>
<link href="import.css" rel="stylesheet" type="text/css" />
<link href="http://localhost:54321/css-ext-import.css" rel="stylesheet" />
<img src="1x1.gif">
<img src="http://localhost:54321/image.jpg">
<video src="video.webm" poster="1x1.gif"></video>
<video src="http://localhost:54321/video.webm?name=value"></video>
</body>
</html>