1
0
mirror of https://github.com/S2-/minifyfromhtml.git synced 2025-08-02 20:00:05 +02:00

2 Commits

Author SHA1 Message Date
s2
e659f2acb8 1.1.6 2019-10-29 20:58:46 +01:00
s2
16d5a653c2 minify just the stylesheet link elements 2019-10-29 20:57:59 +01:00
3 changed files with 14 additions and 12 deletions

View File

@@ -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]])) {
if (src) { let src = elementTags[i].getAttribute(attr);
scripts.push(src); if (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);
} }
}); });

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "minifyfromhtml", "name": "minifyfromhtml",
"version": "1.1.5", "version": "1.1.6",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@@ -1,6 +1,6 @@
{ {
"name": "minifyfromhtml", "name": "minifyfromhtml",
"version": "1.1.5", "version": "1.1.6",
"description": "minify scripts and css starting from an html file", "description": "minify scripts and css starting from an html file",
"main": "minifyfromhtml.js", "main": "minifyfromhtml.js",
"scripts": { "scripts": {