feat/flask: add html, css and js minification
feat/flask: !fix to previous
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -21,3 +21,4 @@ Dockerfile
|
||||
.env
|
||||
static/*.css
|
||||
static/*.css.map
|
||||
static/*.min.js
|
||||
27
app.py
27
app.py
@@ -1,3 +1,4 @@
|
||||
import re
|
||||
import threading
|
||||
import time
|
||||
|
||||
@@ -5,7 +6,8 @@ from os import path, listdir
|
||||
from datetime import date
|
||||
from configparser import ConfigParser
|
||||
|
||||
import sass
|
||||
from sass import compile as compile_sass
|
||||
from htmlmin import minify as minify_html
|
||||
|
||||
from flask import Flask, redirect, render_template, request, url_for, g, Response
|
||||
|
||||
@@ -23,10 +25,20 @@ STATUS_FETCH_DELAY_SEC = 300 # 5 minutes
|
||||
app = Flask(__name__)
|
||||
|
||||
if app.debug:
|
||||
css = sass.compile(filename="static/style.scss")
|
||||
# CSS Compilation and minification
|
||||
css = compile_sass(filename="static/style.scss", output_style="compressed")
|
||||
with open("static/style.css", "w", encoding="utf-8") as f:
|
||||
f.write(css)
|
||||
|
||||
# JS minification
|
||||
with open("static/script.js", encoding="utf-8") as f:
|
||||
js = f.read()
|
||||
js = re.sub(r"/\*.*?\*/", "", js, flags=re.S)
|
||||
js = re.sub(r"//.*", "", js)
|
||||
js = re.sub(r"\s+", " ", js).strip()
|
||||
with open("static/script.min.js", "w", encoding="utf-8") as f:
|
||||
f.write(js)
|
||||
|
||||
|
||||
# ---------- LATEST COMMIT DATE (MINIMAL ADD-ON) -----------------------------
|
||||
|
||||
@@ -102,8 +114,6 @@ def _updater_loop():
|
||||
|
||||
_started = False
|
||||
_refresh_build_date_once()
|
||||
|
||||
# Flask 3.x fix: start updater lazily on first request (since before_first_request is removed)
|
||||
_updater_lock = threading.Lock()
|
||||
|
||||
|
||||
@@ -172,9 +182,12 @@ def render_localized_template(lang, template_name):
|
||||
if lang not in locales_code:
|
||||
return redirect(url_for("index", lang=get_best_lang()))
|
||||
|
||||
return render_template(
|
||||
template_name,
|
||||
year=date.today().year,
|
||||
return minify_html(
|
||||
render_template(
|
||||
template_name,
|
||||
year=date.today().year,
|
||||
),
|
||||
remove_empty_space=True,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ blinker==1.9.0
|
||||
click==8.1.8
|
||||
colorama==0.4.6
|
||||
Flask==3.1.0
|
||||
htmlmin==0.1.12
|
||||
itsdangerous==2.2.0
|
||||
Jinja2==3.1.6
|
||||
libsass==0.23.0
|
||||
|
||||
@@ -345,6 +345,12 @@ td {
|
||||
margin-left: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
&-info {
|
||||
img {
|
||||
margin-right: 0.25em;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hr {
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
|
||||
<table>
|
||||
<tr class="tr-margin-top">
|
||||
<td class="td-description" colspan="2">
|
||||
<td class="td-description td-info" colspan="2">
|
||||
<div role="button" class="help-button"
|
||||
onclick="alert('{{ _('downloads:download_help') }}');">
|
||||
<img src="{{ url_for('static', filename='img/icons/i_info.png') }}" alt="Info">
|
||||
|
||||
@@ -7,5 +7,5 @@
|
||||
content="kolibri, kolibrios, колибри, колибриос, colibri, operating system, assembler, калибри, fasm, alternate, open source">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
|
||||
<script src="{{ url_for('static', filename='script.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='script.min.js') }}"></script>
|
||||
</head>
|
||||
|
||||
Reference in New Issue
Block a user