A vibe coded tangled fork which supports pijul.
1package pages
2
3import (
4 "fmt"
5 "html"
6 "net/http"
7)
8
9// Notice performs a hx-oob-swap to replace the content of an element with a message.
10// Pass the id of the element and the message to display.
11func (s *Pages) Notice(w http.ResponseWriter, id, msg string) {
12 escaped := html.EscapeString(msg)
13 markup := fmt.Sprintf(`<span id="%s" hx-swap-oob="innerHTML">%s</span>`, id, escaped)
14
15 w.Header().Set("Content-Type", "text/html")
16 w.WriteHeader(http.StatusOK)
17 w.Write([]byte(markup))
18}
19
20func (s *Pages) NoticeHTML(w http.ResponseWriter, id string, trustedHTML string) {
21 markup := fmt.Sprintf(`<span id="%s" hx-swap-oob="innerHTML">%s</span>`, id, trustedHTML)
22
23 w.Header().Set("Content-Type", "text/html")
24 w.WriteHeader(http.StatusOK)
25 w.Write([]byte(markup))
26}
27
28// HxRefresh is a client-side full refresh of the page.
29func (s *Pages) HxRefresh(w http.ResponseWriter) {
30 w.Header().Set("HX-Refresh", "true")
31 w.WriteHeader(http.StatusOK)
32}
33
34// HxRedirect is a full page reload with a new location.
35func (s *Pages) HxRedirect(w http.ResponseWriter, location string) {
36 w.Header().Set("HX-Redirect", location)
37 w.WriteHeader(http.StatusOK)
38}
39
40// HxLocation is an SPA-style navigation to a new location.
41func (s *Pages) HxLocation(w http.ResponseWriter, location string) {
42 w.Header().Set("HX-Location", location)
43 w.WriteHeader(http.StatusOK)
44}