#!/usr/bin/env python3 """ Simple build tool to minify web assets in the `web/` folder and generate gzipped versions. 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 Additionally, gzipped variants are produced to enable efficient on-device serving: - web/cleaned/index.html.gz - web/cleaned/style.css.gz - web/cleaned/script.js.gz 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 import gzip 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