Compare commits

..
1 Commits
Author SHA1 Message Date
terminar 84a9faff29 Rename PageHeader.Name to AppName to avoid a field collision
A consuming project's own per-page data struct commonly embeds both
PageHeader and a domain type that has its own Name field (e.g. a
Kubernetes resource's name, as in yakwui's node/deployment/pod detail
pages) -- two same-depth promoted "Name" fields make html/template's
".Name" an ambiguous selector that only fails at execution time, not
at parse time.
2026-09-01 14:11:33 +02:00
4 changed files with 11 additions and 4 deletions

No files matched your search

+8 -1
View File
@@ -42,7 +42,14 @@ type NavItem struct {
// username/logout group).
type PageHeader struct {
Title string
Name string // lowercase product name, e.g. "yasta"; used in <title> and the footer
// AppName is the lowercase product name, e.g. "yasta", used in
// <title> and the footer. Deliberately not "Name" -- a consuming
// project's own per-page data struct commonly embeds both PageHeader
// and a domain type that has its own Name field (e.g. a Kubernetes
// resource's name); two same-depth promoted "Name" fields make
// html/template's ".Name" an ambiguous selector that only fails at
// execution time, not at parse time.
AppName string
Lang string // <html lang="...">; "" defaults to "en"
Brand string // navbar brand text, e.g. "YASTA"
BrandInitial string // single-letter favicon glyph, e.g. "y"
+1 -1
View File
@@ -30,7 +30,7 @@ func TestNewRendererAndPage(t *testing.T) {
var buf bytes.Buffer
data := PageHeader{
Title: "Dashboard",
Name: "example",
AppName: "example",
Brand: "EXAMPLE",
BrandInitial: "e",
BasePath: "",
+1 -1
View File
@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{.Title}}{{if .Name}} · {{.Name}}{{end}}</title>
<title>{{.Title}}{{if .AppName}} · {{.AppName}}{{end}}</title>
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%3E%3Crect%20width='100'%20height='100'%20rx='20'%20fill='%2314171e'/%3E%3Ctext%20x='50'%20y='71'%20font-size='58'%20font-family='system-ui,sans-serif'%20font-weight='700'%20fill='%230b82b8'%20text-anchor='middle'%3E{{.BrandInitial}}%3C/text%3E%3C/svg%3E">
<link rel="stylesheet" href="{{.BasePath}}/webui-static/bootstrap.min.css">
<link rel="stylesheet" href="{{.BasePath}}/webui-static/style.css">
+1 -1
View File
@@ -1,3 +1,3 @@
{{define "footer"}}
<footer class="footer">{{.Name}} web UI · {{buildInfo}}</footer>
<footer class="footer">{{.AppName}} web UI · {{buildInfo}}</footer>
{{end}}