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}")