republisher/repub/pages/shim.py

34 lines
1,006 B
Python

from __future__ import annotations
import htpy as h
from htpy import Node, Renderable
ON_LOAD_JS = (
"@post(window.location.pathname + "
"(window.location.search + '&u=').replace(/^&/,'?'), "
"{retryMaxCount: Infinity})"
)
TAB_ID_JS = "self.crypto.randomUUID().substring(0,8)"
def shim_page(*, datastar_src: str, head: Node | None = None) -> Renderable:
return h.html(lang="en")[
h.head[
h.meta(charset="UTF-8"),
head,
h.script(id="js", defer=True, type="module", src=datastar_src),
h.meta(name="viewport", content="width=device-width, initial-scale=1.0"),
],
h.body[
h.div({"data-signals:tabid": TAB_ID_JS}),
h.div(
{
"data-init": ON_LOAD_JS,
"data-on:online__window": ON_LOAD_JS,
}
),
h.noscript["Your browser does not support JavaScript!"],
h.main(id="morph"),
],
]