add datastar and render shim
This commit is contained in:
parent
9ce576e7e8
commit
2accb26546
6 changed files with 173 additions and 42 deletions
34
repub/pages/shim.py
Normal file
34
repub/pages/shim.py
Normal 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"),
|
||||
],
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue