mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-02 12:00:03 +02:00
minify just the stylesheet link elements
This commit is contained in:
@@ -45,19 +45,21 @@ let readStdin = function(cb) {
|
|||||||
|
|
||||||
readStdin(function(html) {
|
readStdin(function(html) {
|
||||||
let dom = new JSDOM(html);
|
let dom = new JSDOM(html);
|
||||||
let getTagAttrs = function(dom, tag, attr) {
|
let getTagAttrs = function(dom, tag, attr, filter) {
|
||||||
let scripts = [];
|
let elements = [];
|
||||||
|
|
||||||
let document = dom.window.document;
|
let document = dom.window.document;
|
||||||
let scriptTags = document.getElementsByTagName(tag);
|
let elementTags = document.getElementsByTagName(tag);
|
||||||
let i = scriptTags.length;
|
let i = elementTags.length;
|
||||||
for (let i = 0; i < scriptTags.length; i++) {
|
for (let i = 0; i < elementTags.length; i++) {
|
||||||
let src = scriptTags[i].getAttribute(attr);
|
if (filter && elementTags[i].getAttribute(Object.keys(filter)[0]).includes(filter[Object.keys(filter)[0]])) {
|
||||||
|
let src = elementTags[i].getAttribute(attr);
|
||||||
if (src) {
|
if (src) {
|
||||||
scripts.push(src);
|
elements.push(src);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return scripts;
|
}
|
||||||
|
return elements;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -101,6 +103,6 @@ readStdin(function(html) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (argv.css) {
|
if (argv.css) {
|
||||||
processThings(getTagAttrs(dom, 'link', 'href'), argv.css);
|
processThings(getTagAttrs(dom, 'link', 'href', {rel: 'stylesheet'}), argv.css);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user