add datastar and render shim

This commit is contained in:
Abel Luck 2026-03-30 12:27:45 +02:00
parent 9ce576e7e8
commit 2accb26546
6 changed files with 173 additions and 42 deletions

34
repub/pages/shim.py Normal file
View file

@ -0,0 +1,34 @@
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"),
],
]