gulp-tpl-rev
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "gulp-tpl-rev", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "template resource url revisioning by appending content hash to filenames: unicorn.css => unicorn.css?_v=1", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -18,6 +18,15 @@ "use strict"; | ||
name: "_v", | ||
hash: function (pahtname) { return "" + Date.now(); } | ||
hash: function (pathname) { return "" + Date.now(); }, | ||
match: function (pathname) { return /^\/[^/]+/.test(pathname); } | ||
}; | ||
function default_1(options) { | ||
if (options === void 0) { options = defaultOptions; } | ||
if (!options.name) { | ||
options.name = defaultOptions.name; | ||
} | ||
if (!options.hash) { | ||
options.hash = defaultOptions.hash; | ||
} | ||
if (!options.match) { | ||
options.match = defaultOptions.match; | ||
} | ||
return through2_1.default.obj(function (file, _, cb) { | ||
@@ -27,11 +36,15 @@ var tpl = ""; | ||
rewriter.on('startTag', function (token) { | ||
var attr; | ||
if (token.tagName === 'link') { | ||
var attr = token.attrs.filter(function (attr) { return attr.name === "href"; })[0]; | ||
if (attr) { | ||
var urlObject = url.parse(attr.value, true); | ||
var query = urlObject.query; | ||
query[options.name] = options.hash(urlObject.pathname); | ||
attr.value = url.format(urlObject); | ||
} | ||
attr = token.attrs.filter(function (attr) { return attr.name === "href"; })[0]; | ||
} | ||
else if (token.tagName === 'script') { | ||
attr = token.attrs.filter(function (attr) { return attr.name === "src"; })[0]; | ||
} | ||
if (attr && attr.value && options.match(attr.value)) { | ||
var urlObject = url.parse(attr.value, true); | ||
var query = urlObject.query; | ||
query[options.name] = options.hash(urlObject.pathname); | ||
attr.value = url.format(urlObject); | ||
} | ||
rewriter.emitStartTag(token); | ||
@@ -38,0 +51,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
9588
8
120