"""
def patch_file(path: Path) -> bool:
text = path.read_text(encoding="utf-8")
orig = text
if 'data-theme="dark"' not in text:
text = text.replace('', '', 1)
if "/static/instance_theme.js" not in text:
text = text.replace(
"",
"\n" + SCRIPT_TAG.strip() + "\n",
1,
)
if "/static/instance_theme.css" not in text:
text = text.replace("", "\n" + CSS_LINK, 1)
if path.name == "index.html" and INDEX_HEADER_OLD in text and "instance-theme-toggle" not in text:
text = text.replace(INDEX_HEADER_OLD, INDEX_HEADER_NEW)
if path.name == "login.html" and "instance-theme-toggle" not in text:
text = text.replace(
"",
'
\n' + THEME_TOGGLE + "
\n",
1,
)
if path.name == "key_focus_v2.html" and "instance-theme-toggle" not in text:
marker = '
'
if marker in text:
text = text.replace(
marker,
marker + "\n " + THEME_TOGGLE.replace("\n", "\n "),
1,
)
if path.name == "order_focus_v2.html" and "instance-theme-toggle" not in text:
marker = '
'
if marker in text:
text = text.replace(
marker,
marker + "\n " + THEME_TOGGLE.replace("\n", "\n "),
1,
)
if text != orig:
path.write_text(text, encoding="utf-8")
return True
return False
def main() -> None:
n = 0
for ex in EXCHANGES:
for fn in FILES:
p = ROOT / ex / "templates" / fn
if p.is_file() and patch_file(p):
print("patched", p.relative_to(ROOT))
n += 1
print("done", n, "files")
if __name__ == "__main__":
main()