#!/usr/bin/env python3 from __future__ import annotations import pathlib import re ROOT = pathlib.Path(__file__).resolve().parents[1] / "apps/nomadweb/frontend/src" def fix(text: str) -> str: t = text t = re.sub(r"(? str: path = m.group(1) if path.startswith(("/community", "/book", "/nav", "http")): return m.group(0) if not path.startswith("/"): path = "/" + path return f"next=/community{path}" t = re.sub(r"next=(/[^\s\"'?]+)", repl_next, t) t = t.replace("/community/community/", "/community/") return t def main() -> None: n = 0 for p in ROOT.rglob("*"): if p.suffix not in {".ts", ".tsx"}: continue raw = p.read_text(encoding="utf-8") out = fix(raw) if out != raw: p.write_text(out, encoding="utf-8") n += 1 print("fixed", p.relative_to(ROOT)) print("files", n) if __name__ == "__main__": main()