feat(webui): templates + static assets; SSE broadcast; link cards; link summary endpoint; raw soju client store; UI polish
- Switch UI to Go html/templates and embedded /static (Pico.css-compatible) - Add Server.Broadcast and normalize SSE channel keys to lowercase - Implement /api/linkcard (OG/Twitter) and /api/linksummary (24h cache) - Wire Store into raw soju client for CHATHISTORY LATEST fallback
This commit is contained in:
parent
cbd798dfd5
commit
8a6111aeb5
8 changed files with 537 additions and 293 deletions
47
internal/httpapi/templates.go
Normal file
47
internal/httpapi/templates.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package httpapi
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
//go:embed templates/*.tmpl
|
||||
var uiFS embed.FS
|
||||
|
||||
//go:embed static/*
|
||||
var staticFS embed.FS
|
||||
|
||||
var (
|
||||
tplOnce sync.Once
|
||||
tpl *template.Template
|
||||
)
|
||||
|
||||
func (s *Server) parseTemplatesOnce() {
|
||||
tplOnce.Do(func() {
|
||||
// Parse all templates under templates/
|
||||
t := template.New("base").Funcs(template.FuncMap{})
|
||||
t = template.Must(t.ParseFS(uiFS, "templates/*.tmpl"))
|
||||
tpl = t
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) render(w http.ResponseWriter, name string, data map[string]any) {
|
||||
s.parseTemplatesOnce()
|
||||
if data == nil {
|
||||
data = map[string]any{}
|
||||
}
|
||||
data["Version"] = s.Version
|
||||
data["Commit"] = s.Commit
|
||||
base := strings.TrimSuffix(path.Base(name), path.Ext(name))
|
||||
if base == "dashboard" {
|
||||
data["Title"] = "sojuboy"
|
||||
} else {
|
||||
data["Title"] = strings.Title(base)
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
_ = tpl.ExecuteTemplate(w, name, data)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue