Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cli/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function options(args) {
],
string: [ // options
'encoding',
'baseurl',
],
alias: {
images: 'noimages', // legacy support
Expand All @@ -34,6 +35,7 @@ function options(args) {
o: 'videos',
m: 'inlinemin',
H: 'header',
b: 'baseurl',
},
});

Expand Down
5 changes: 3 additions & 2 deletions docs/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

Options:

-H, --header LINE custom header pass to the server (ala cURL headers)
-e, --encoding ENC override encoding detection
-H, --header LINE custom header pass to the server (ala cURL headers)
-e, --encoding ENC override encoding detection
-b, --baseurl BASEURL use baseurl to fetch assets with relative paths

Examples:

Expand Down
11 changes: 10 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ function Inliner(source, options, callback) {
this.url = options.url;
}

if (options.baseurl) {
this.baseurl = options.baseurl;
}

if (options.filename) {
this.filename = options.filename;
}
Expand Down Expand Up @@ -375,13 +379,18 @@ function resolve(from, to) {
from = this.url;
}

// add base url to relative urls
if (this.baseurl && from.indexOf('http') === -1) {
from = this.baseurl;
}

// don't resolve data urls (already inlined)
if (to.indexOf('data:') === 0) {
return to;
}

// always strip querystrings from requests off a local file
if (this.isFile) {
if (this.isFile && !this.baseurl) {
to = to.replace(/\??#.*$/, '');
}

Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/baseurl.opts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"baseurl": "https://avatars1.githubusercontent.com"
}
Loading