minify css

This commit is contained in:
Roy Olav Purser 2021-06-09 15:01:19 +02:00
parent b721dd451f
commit 1b5249daf3
Signed by: roypur
GPG Key ID: E14D26A036F21656
4 changed files with 38 additions and 25 deletions

View File

@ -43,7 +43,7 @@ else:
except Exception as e:
print(e)
else:
with open("/app/chromecast.css", "w") as f:
with open("/app/setup/chromecast.css", "w") as f:
f.write(resp.text)
with open("/app/version/chromecast.txt", "w") as f:
f.write(chromecast_version)

View File

@ -171,9 +171,7 @@ try:
with open("/app/favicon.png", "rb") as f:
favicon = f.read()
with open("/app/style.css", "r") as f:
custom_style_raw = bytes(f.read().strip(), "utf-8")
b64 = str(base64.b64encode(custom_style_raw), "ascii")
custom_style = f'data:text/css;charset=utf-8;base64,{b64}'
custom_style = f.read()
except Exception as e:
logger.info(e)
@ -210,7 +208,6 @@ class MainHandler(tornado.web.RequestHandler):
data["videojs_version"] = videojs_version
data["chromecast_version"] = chromecast_version
data["font_awesome_version"] = font_awesome_version
data["custom_style"] = custom_style
rendered_html = template_html.generate(data=data, meta=provider_data.meta(), title=provider_data.title())
self.write(rendered_html)
else:
@ -222,18 +219,25 @@ class MainHandler(tornado.web.RequestHandler):
async def head(self):
await self.handle_any(False)
class FileHandler(tornado.web.RequestHandler):
class PlaylistHandler(tornado.web.RequestHandler):
def get(self):
self.set_header("Content-Type", "text/plain; charset=utf-8")
self.write(playlist)
class IconHandler(tornado.web.RequestHandler):
def get(self):
self.set_header("Content-Type", "image/png")
self.write(favicon)
class StyleHandler(tornado.web.RequestHandler):
def get(self):
self.set_header("Content-Type", "text/css; charset=utf-8")
self.write(custom_style)
try:
handlers = []
handlers.append((tornado.routing.PathMatches("/sources.m3u8"), FileHandler))
handlers.append((tornado.routing.PathMatches("/sources.m3u8"), PlaylistHandler))
handlers.append((tornado.routing.PathMatches("/favicon.ico"), IconHandler))
handlers.append((tornado.routing.PathMatches("/style.css"), StyleHandler))
handlers.append((tornado.routing.AnyMatches(), MainHandler))
app_web = tornado.web.Application(handlers)
app_web.listen(8080)

View File

@ -3,7 +3,15 @@
const fs = require("fs");
const css = require("css");
fs.readFile("/app/chromecast.css", "utf-8", (err, data) => {
fs.readFile("/app/style.css", "utf-8", (err, a) => {
let data = "";
if(err === null) {
data = a + "\n";
}
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) {
const decls = [];
@ -18,9 +26,10 @@ fs.readFile("/app/chromecast.css", "utf-8", (err, data) => {
rule.declarations = decls;
}
}
fs.appendFile("/app/style.css", css.stringify(ast, {"compress": true}), (err) => {
fs.writeFile("/app/style.css", css.stringify(ast, {"compress": true}), (err) => {
if(err !== null) {
console.log(err);
}
});
});
});

View File

@ -10,6 +10,6 @@
<script defer src="{{ data["script"] }}"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/video.js/{{ data["videojs_version"] }}/video-js.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/{{ data["font_awesome_version"] }}/css/all.min.css">
<link rel="stylesheet" href="{{ data["custom_style"] }}">
<link rel="stylesheet" href="/style.css">
</head>
</html>