only filter remote css

This commit is contained in:
Roy Olav Purser 2021-06-10 10:41:10 +02:00
parent 1b5249daf3
commit f04d343bdf
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -3,16 +3,11 @@
const fs = require("fs"); const fs = require("fs");
const css = require("css"); const css = require("css");
fs.readFile("/app/style.css", "utf-8", (err, a) => { fs.readFile("/app/setup/chromecast.css", "utf-8", (err, a) => {
let data = ""; let data = "";
if(err === null) { if(err === null) {
data = a + "\n"; try {
} let ast = css.parse(a);
fs.readFile("/app/setup/chromecast.css", "utf-8", (err, b) => {
if(err === null) {
data += b + "\n";
}
const ast = css.parse(data);
for(const rule of ast.stylesheet.rules) { for(const rule of ast.stylesheet.rules) {
const decls = []; const decls = [];
if(Symbol.iterator in Object(rule.declarations)) { if(Symbol.iterator in Object(rule.declarations)) {
@ -26,7 +21,17 @@ fs.readFile("/app/style.css", "utf-8", (err, a) => {
rule.declarations = decls; rule.declarations = decls;
} }
} }
fs.writeFile("/app/style.css", css.stringify(ast, {"compress": true}), (err) => { data = css.stringify(ast);
} catch(e) {
console.log(e);
}
}
fs.readFile("/app/style.css", "utf-8", (err, b) => {
if(err === null) {
data = b + "\n" + data + "\n";
}
console.log(data);
fs.writeFile("/app/style.css", css.stringify(css.parse(data), {"compress": true}), (err) => {
if(err !== null) { if(err !== null) {
console.log(err); console.log(err);
} }