#!/usr/bin/env python3 """Remove the redundant footer [data-i18n-toggle] block. After Issue #13 the top-right widget owns toggling. The legacy footer button + "Maschinell übersetzt" disclaimer line are now redundant — top-right button has the same disclaimer in its title tooltip, and ai-disclosure.js still adds the AI footnote. Two patterns handled: Pattern A:
...
Pattern B (knzlmgmt, schulfrai): Idempotent — sites without the patterns are skipped. """ import re import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent SITES_DIR = ROOT / "sites" # Pattern A: a div wrapping the button + br + small disclaimer. # Allow extra style segments after margin-top:16px (some sites add ;opacity:1 etc.) PATTERN_A = re.compile( r'\s*\s*' r'\s*' r'
\s*]*data-de="Maschinell übersetzt"[^>]*>[\s\S]*?\s*' r'', re.IGNORECASE, ) # Pattern B: PATTERN_B = re.compile( r'\s*' r'', re.IGNORECASE, ) # Pattern C: bare button (optionally followed by
...), # not enclosed in our standard wrappers. Used by sites that placed the # toggle inline in a footer paragraph (ichbinotto, kainco, keinefreun, # omakise) or in a custom-classed div (orakil). PATTERN_C = re.compile( r'\s*' r'(?:\s*
\s*]*data-de="Maschinell übersetzt"[^>]*>[\s\S]*?)?', re.IGNORECASE, ) # Pattern D: (orakil only, but tolerant) PATTERN_D = re.compile( r'\s*\s*' r'\s*' r'
\s*]*data-de="Maschinell übersetzt"[^>]*>[\s\S]*?\s*' r'', re.IGNORECASE, ) def patch(html): new = html # Wrappers first (they contain a button); then bare-button fallback. new, n_a = PATTERN_A.subn("", new) new, n_b = PATTERN_B.subn("", new) new, n_d = PATTERN_D.subn("", new) new, n_c = PATTERN_C.subn("", new) return new, n_a + n_b + n_c + n_d def main(): sites = sorted(p for p in SITES_DIR.iterdir() if p.is_dir() and (p / "index.html").exists()) total_removed = 0 sites_changed = 0 sites_with_attr = 0 sites_residual = [] for site in sites: path = site / "index.html" before = path.read_text() if "data-i18n-toggle" not in before: continue sites_with_attr += 1 # Count old buttons before removal (we expect exactly 1 footer button per site; # the new top-right widget injects its own at runtime, not in source). before_count = len(re.findall(r"data-i18n-toggle", before)) after, removed = patch(before) after_count = len(re.findall(r"data-i18n-toggle", after)) if removed > 0: path.write_text(after) sites_changed += 1 total_removed += removed print(f" [removed {removed}] {site.name} (data-i18n-toggle: {before_count} -> {after_count})") if after_count > 0: sites_residual.append((site.name, after_count)) else: sites_residual.append((site.name, before_count)) print(f" [no-match] {site.name} (still has {before_count} data-i18n-toggle)") print(f"\nSites changed: {sites_changed}/{sites_with_attr}") print(f"Total wrappers removed: {total_removed}") if sites_residual: print(f"\nSites with residual data-i18n-toggle attribute (manual review):") for name, n in sites_residual: print(f" - {name}: {n}") if __name__ == "__main__": main()