Trying agin without using packages that require Rust.
Some checks are pending
lint / runner / vale (push) Waiting to run
Lint / MegaLinter (push) Waiting to run

This commit is contained in:
g_it 2026-03-15 00:23:44 +01:00
commit 9695449e79
Signed by untrusted user who does not match committer: g_it
GPG key ID: A2B0A7C06A054627
2 changed files with 20 additions and 9 deletions

View file

@ -1,25 +1,35 @@
#!/usr/bin/env python3
"""Minify CSS, JS, and HTML files in the deploy directory in-place."""
import re
import sys
from pathlib import Path
import minify_html
import rcssmin
import rjsmin
DEPLOY_DIR = Path("./deploy")
def minify_html_content(content):
content = re.sub(r"<!--.*?-->", "", content, flags=re.DOTALL) # remove comments
content = re.sub(r">\s+<", "><", content) # collapse whitespace between tags
content = re.sub(r"\s{2,}", " ", content) # collapse remaining whitespace
return content.strip()
def minify_files():
handlers = {
".css": lambda c: rcssmin.cssmin(c),
".js": lambda c: rjsmin.jsmin(c, keep_bang_comments=False),
".html": minify_html_content,
}
for file in DEPLOY_DIR.rglob("*"):
if file.suffix not in {".html", ".css", ".js"}:
handler = handlers.get(file.suffix)
if not handler:
continue
content = file.read_text(encoding="utf-8")
minified = minify_html.minify(
content,
minify_js=True,
minify_css=True,
)
file.write_text(minified, encoding="utf-8")
file.write_text(handler(content), encoding="utf-8")
print(f"{file.suffix.upper().rjust(5)}: {file}")

View file

@ -9,7 +9,6 @@ Jinja2==3.1.6
Markdown==3.10.2
MarkupSafe==3.0.3
mergedeep==1.3.4
minify-html==0.15.0
mkdocs==1.6.1
mkdocs-autorefs==1.4.4
mkdocs-get-deps==0.2.2
@ -23,6 +22,8 @@ pymdown-extensions==10.21
python-dateutil==2.9.0.post0
PyYAML==6.0.3
pyyaml_env_tag==1.1
rcssmin==1.2.2
rjsmin==1.2.4
six==1.17.0
watchdog==6.0.0
zensical==0.0.27