mirror of
https://github.com/remy/inliner.git
synced 2024-08-16 20:00:35 +03:00
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:
commit
731e7e9351
@ -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;
|
||||
|
@ -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:
|
||||
|
||||
|
@ -5,5 +5,6 @@ module.exports = function () {
|
||||
compressJS: true,
|
||||
collapseWhitespace: true,
|
||||
nosvg: false, // by default, DO compress SVG with SVGO
|
||||
skipAbsoluteUrls: false,
|
||||
};
|
||||
};
|
||||
|
@ -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);
|
||||
|
@ -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');
|
||||
|
@ -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>');
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
4
test/fixtures/inline-skip-absolute-urls.opts.json
vendored
Normal file
4
test/fixtures/inline-skip-absolute-urls.opts.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"skipAbsoluteUrls": true,
|
||||
"videos": true
|
||||
}
|
1
test/fixtures/inline-skip-absolute-urls.result.html
vendored
Normal file
1
test/fixtures/inline-skip-absolute-urls.result.html
vendored
Normal file
File diff suppressed because one or more lines are too long
17
test/fixtures/inline-skip-absolute-urls.src.html
vendored
Normal file
17
test/fixtures/inline-skip-absolute-urls.src.html
vendored
Normal 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>
|
Loading…
Reference in New Issue
Block a user