From cfa3feb7d2cf5df76fa029d0f669a671097a5194 Mon Sep 17 00:00:00 2001 From: Stefan Ostermann Date: Mon, 6 Oct 2025 23:13:50 +0200 Subject: [PATCH] [ai] forgot cleanup script --- scripts/minify_web.py | 257 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 257 insertions(+) create mode 100644 scripts/minify_web.py diff --git a/scripts/minify_web.py b/scripts/minify_web.py new file mode 100644 index 0000000..0b8658b --- /dev/null +++ b/scripts/minify_web.py @@ -0,0 +1,257 @@ +#!/usr/bin/env python3 +""" +Simple build tool to minify web assets in the `web/` folder. + +Usage: + python3 scripts/minify_web.py + +This script will read: + - web/index.html + - web/style.css + - web/script.js + +and write minified outputs to: + - web/cleaned/index.html + - web/cleaned/style.css + - web/cleaned/script.js + +The minifiers are intentionally conservative (no external deps) and aim to be +safe for typical static files used in this project. They remove comments, +collapse unnecessary whitespace and do small syntax-preserving transformations. +They are NOT as powerful as terser/clean-css/html-minifier but avoid external +package installs which may not be available on the build host. + +If you want stronger/min-safe minification later, replace this script with an +npm-based toolchain (npx terser, html-minifier-terser, clean-css) or call those +tools from a Makefile. +""" +from pathlib import Path +import re +import sys +import os + +BASE = Path(__file__).resolve().parent.parent +WEB = BASE / "web" +CLEAN = WEB / "cleaned" + +def ensure_clean_dir(): + CLEAN.mkdir(parents=True, exist_ok=True) + +# ---------------------- +# HTML minifier +# ---------------------- +def minify_html(src: str) -> str: + """ + - Preserve content inside