Add page <title> to every rendered page

layout.html now emits <title>{{ pageTitle . }} · Palette</title>; the
pageTitle template func maps the Page field to a label (New paste,
Public pastes, Saved, Settings, paste title or 'Paste <id>', Unlock,
Can, Not found).
This commit is contained in:
fen committed 2026-10-16 16:52:29 -05:00
1 parent 1c08647742
commit b4c23a09bf
2 files changed
+34

No files matched your search

+33
View File
@@ -74,6 +74,7 @@ func New() (*UI, error) {
"humanSize": humanSize,
"version": func() string { return Version }, // #93: topbar version label
"defaultDark": func() bool { return DefaultDark }, // #127: server-configured default
"pageTitle": pageTitle, // page <title> labels
}
t, err := template.New("").Funcs(funcs).ParseFS(tmplFS, "templates/*.html")
if err != nil {
@@ -82,6 +83,38 @@ func New() (*UI, error) {
return &UI{tmpl: t}, nil
}
// pageTitle returns the <title> label for the rendered page. Page data is
// always a map with a "Page" key set by the handlers.
func pageTitle(data any) string {
m, _ := data.(map[string]any)
page, _ := m["Page"].(string)
id, _ := m["ID"].(string)
title, _ := m["Title"].(string)
switch page {
case "new":
return "New paste"
case "public":
return "Public pastes"
case "saved":
return "Saved"
case "settings":
return "Settings"
case "paste":
if title != "" {
return title
}
return "Paste " + id
case "unlock":
return "Unlock " + id
case "can":
return "Can " + id
case "notfound":
return "Not found"
default:
return "Palette"
}
}
func humanSize(n int) string {
if n < 1024 {
return fmt.Sprintf("%d B", n)