Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Commit

Permalink
Adding support for rootURL option
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmit committed Oct 18, 2016
1 parent a25d9a2 commit 5ebad6f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ function SRIHashAssets(inputNodes, options) {
}
}
}

if ('rootURL' in this.options) {
this._rootURL = new RegExp('^' + this.options.rootURL);
}
}

SRIHashAssets.prototype = Object.create(CachingWriter.prototype);
Expand Down Expand Up @@ -84,7 +88,6 @@ SRIHashAssets.prototype.addSRI = function addSRI(string, srcDir) {
var base = this.getBaseHREF(string);

return string.replace(SCRIPT_CHECK, function srcMatch(match) {

var src = match.match(SRC_CHECK);
var filePath;

Expand All @@ -94,6 +97,10 @@ SRIHashAssets.prototype.addSRI = function addSRI(string, srcDir) {

filePath = src[1];

if (plugin._rootURL) {
filePath = filePath.replace(plugin._rootURL, '');
}

return plugin.mungeOutput(match, filePath, base || srcDir);
}).replace(LINT_CHECK, function hrefMatch(match) {
var href = match.match(HREF_CHECK);
Expand All @@ -106,6 +113,10 @@ SRIHashAssets.prototype.addSRI = function addSRI(string, srcDir) {

filePath = href[1];

if (plugin._rootURL) {
filePath = filePath.replace(plugin._rootURL, '');
}

return plugin.mungeOutput(match, filePath, base || srcDir);
});
};
Expand Down

0 comments on commit 5ebad6f

Please sign in to comment.