Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
"""HTML pages: skeletons in templates/, CSS/JS in static/, assembled ONCE at import into single self-contained
|
|
documents (inline <style>/<script>), exactly as the old monolith served them.
|
|
|
|
The share page must stay fully self-contained: outsiders (non-LAN) reach only /s/<token>... and /favicon.svg.
|
|
"""
|
|
import json
|
|
import os
|
|
|
|
from radio.channels import groups
|
|
|
|
_HERE = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
def _read(*parts):
|
|
# newline="" : no newline translation, bytes stay exactly as in the file
|
|
with open(os.path.join(_HERE, *parts), encoding="utf-8", newline="") as fh:
|
|
return fh.read()
|
|
|
|
|
|
def _assemble(template, css, js):
|
|
# js: one file name or a list of names, inlined in order (one shared script scope)
|
|
js_all = "".join(_read("static", j) for j in ([js] if isinstance(js, str) else js))
|
|
return _read("templates", template).replace("@@CSS@@", _read("static", css)).replace("@@JS@@", js_all)
|
|
|
|
|
|
PAGE = _assemble("index.html", "app.css", ["app.js", "sources.js", "boot.js"]) # contains the __GROUPS__ placeholder
|
|
SHARE_PAGE = _assemble("share.html", "share.css", "share.js")
|
|
FAVICON = _read("static", "favicon.svg")
|
|
|
|
|
|
def page():
|
|
return PAGE.replace("__GROUPS__", json.dumps(groups(), ensure_ascii=False).replace("</", "<\\/"))
|