diff options
author | Thomas Voss <mail@thomasvoss.com> | 2025-08-02 00:24:54 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2025-08-02 00:24:54 +0200 |
commit | db7dc92fc8726a0a89b26fbac5480d9e3847a55f (patch) | |
tree | fe18d99059bff6d10800c9c1ce28ceee90662680 /src | |
parent | afe6a6c8b77a7f1ae99190ab782cdba1f5ee422d (diff) |
Change how we do headers
Diffstat (limited to 'src')
25 files changed, 141 insertions, 29 deletions
diff --git a/src/templates.go b/src/templates.go index a7d7f2a..a3bc52d 100644 --- a/src/templates.go +++ b/src/templates.go @@ -1,7 +1,6 @@ package app import ( - "bytes" "html/template" "io/fs" "log" @@ -82,9 +81,10 @@ func buildTemplate(dir fs.FS, name string) *template.Template { for i, s := range names { names[i] = s + ".html.tmpl" } - t := template.New("-base.html.tmpl").Funcs(funcmap) - t = t.Funcs(includeIfExists(t)) - return template.Must(t.ParseFS(dir, names[:]...)) + return template.Must(template. + New("-base.html.tmpl"). + Funcs(funcmap). + ParseFS(dir, names[:]...)) } func asHTML(s string) template.HTML { @@ -112,20 +112,6 @@ func templateMakeMap(args ...any) map[string]any { return m } -func includeIfExists(tmpl *template.Template) template.FuncMap { - return template.FuncMap{ - "includeIfExists": func(name string, data any) (template.HTML, error) { - t := tmpl.Lookup(name) - if t == nil { - return "", nil - } - var buf bytes.Buffer - err := t.Execute(&buf, data) - return template.HTML(buf.String()), err - }, - } -} - func ifElse(b bool, x, y any) any { if b { return x diff --git a/src/templates/-404.html.tmpl b/src/templates/-404.html.tmpl index 03602e1..b149777 100644 --- a/src/templates/-404.html.tmpl +++ b/src/templates/-404.html.tmpl @@ -1,3 +1,7 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} diff --git a/src/templates/-base.html.tmpl b/src/templates/-base.html.tmpl index 42ec216..62f3301 100644 --- a/src/templates/-base.html.tmpl +++ b/src/templates/-base.html.tmpl @@ -33,7 +33,8 @@ }); })(); </script> - {{ includeIfExists "header" . }} + + {{ template "header" . }} </head> <body> {{ template "content" . }} diff --git a/src/templates/-error.html.tmpl b/src/templates/-error.html.tmpl index a18ec3e..198318d 100644 --- a/src/templates/-error.html.tmpl +++ b/src/templates/-error.html.tmpl @@ -1,3 +1,7 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} diff --git a/src/templates/-navbar.html.tmpl b/src/templates/-navbar.html.tmpl index 442de5b..33484b8 100644 --- a/src/templates/-navbar.html.tmpl +++ b/src/templates/-navbar.html.tmpl @@ -1,3 +1,43 @@ +{{ define "header-navbar" }} +<style> + #nav-icon-lang { + a { + display: flex; + align-items: center; + gap: .5ch; + } + + svg { + stroke: var(--color); + height: 1rem; + } + } + + #nav-icon-theme { + button { + background-color: unset; + margin: 0; + display: flex; + justify-content: center; + align-items: center; + height: 1.5rem; + } + + svg { + --size: 1.2rem; + stroke: var(--primary); + stroke-width: .1; + height: var(--size); + width: var(--size); + } + } + + [data-theme="light"] #nav-icon-theme svg { + fill: var(--primary); + } +</style> +{{ end }} + {{ define "navbar" }} <nav> <menu> diff --git a/src/templates/about.html.tmpl b/src/templates/about.html.tmpl index 1f3aade..1ef6339 100644 --- a/src/templates/about.html.tmpl +++ b/src/templates/about.html.tmpl @@ -1,3 +1,7 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} diff --git a/src/templates/banknotes-codes.html.tmpl b/src/templates/banknotes-codes.html.tmpl index 2ff6395..fcbad40 100644 --- a/src/templates/banknotes-codes.html.tmpl +++ b/src/templates/banknotes-codes.html.tmpl @@ -1,3 +1,7 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} diff --git a/src/templates/banknotes.html.tmpl b/src/templates/banknotes.html.tmpl index 747d37c..750b4db 100644 --- a/src/templates/banknotes.html.tmpl +++ b/src/templates/banknotes.html.tmpl @@ -1,3 +1,7 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} @@ -43,4 +47,4 @@ </div> </section> </main> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/src/templates/coins-designs-ad.html.tmpl b/src/templates/coins-designs-ad.html.tmpl index e5290da..567d2ff 100644 --- a/src/templates/coins-designs-ad.html.tmpl +++ b/src/templates/coins-designs-ad.html.tmpl @@ -1,3 +1,7 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} @@ -48,4 +52,4 @@ (map "LatinStart" `<span lang="la"><em>` "LatinEnd" "em,span") }} </p> </main> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/src/templates/coins-designs-at.html.tmpl b/src/templates/coins-designs-at.html.tmpl index ca5dcb1..e58865e 100644 --- a/src/templates/coins-designs-at.html.tmpl +++ b/src/templates/coins-designs-at.html.tmpl @@ -1,3 +1,7 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} @@ -33,4 +37,4 @@ {{ .Get "The two bimetallic coins feature the busts of the musical composer Wolfgang Amadeus Mozarts on the €1 coin, and the Austrian pacifist and Nobel Peace Prize winner Bertha von Suttner." }} </p> </main> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/src/templates/coins-designs-be.html.tmpl b/src/templates/coins-designs-be.html.tmpl index 9063a3a..e57d0cb 100644 --- a/src/templates/coins-designs-be.html.tmpl +++ b/src/templates/coins-designs-be.html.tmpl @@ -1,4 +1,8 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} {{ define "content" }} + <header> {{ template "navbar" . }} <h1>{{ .Get "Belgian Euro Coin Designs" }}</h1> @@ -29,4 +33,4 @@ {{ .Get "After his accession to the throne, Belgium began a third series of coins in 2014 featuring the portrait of King Philippe. As is customary with coins bearing the portraits of monarchs, the direction in which the portrait faces was flipped to face right instead of left." }} </p> </main> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/src/templates/coins-designs-de.html.tmpl b/src/templates/coins-designs-de.html.tmpl index 118477e..ef4cd62 100644 --- a/src/templates/coins-designs-de.html.tmpl +++ b/src/templates/coins-designs-de.html.tmpl @@ -1,3 +1,7 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} @@ -60,4 +64,4 @@ {{ .Get "The €2 coin also features an edge-inscription of Germany’s national motto and incipit of Germany’s national anthem. It reads ‘{GermanStart:r}EINIGKEIT UND RECHT UND FREIHEIT{GermanEnd:E}’ (English: ‘UNITY AND JUSTICE AND FREEDOM’)." $deargs }} </p> </main> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/src/templates/coins-designs-ee.html.tmpl b/src/templates/coins-designs-ee.html.tmpl index f6d6354..ad1a1dc 100644 --- a/src/templates/coins-designs-ee.html.tmpl +++ b/src/templates/coins-designs-ee.html.tmpl @@ -1,3 +1,7 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} @@ -152,4 +156,4 @@ </tfoot> </table> </main> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/src/templates/coins-designs-hr.html.tmpl b/src/templates/coins-designs-hr.html.tmpl index 01a391e..2112bb1 100644 --- a/src/templates/coins-designs-hr.html.tmpl +++ b/src/templates/coins-designs-hr.html.tmpl @@ -1,3 +1,7 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} @@ -35,4 +39,4 @@ $hrargs (map "Link" "https://www.wikipedia.org/wiki/Dubravka_(drama)") }} </p> </main> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/src/templates/coins-designs-nl.html.tmpl b/src/templates/coins-designs-nl.html.tmpl index a801374..b319e49 100644 --- a/src/templates/coins-designs-nl.html.tmpl +++ b/src/templates/coins-designs-nl.html.tmpl @@ -1,3 +1,7 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} @@ -38,4 +42,4 @@ (map "Link" "/jargon#relief") }} </p> </main> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/src/templates/coins-designs.html.tmpl b/src/templates/coins-designs.html.tmpl index 83164f3..e46efa3 100644 --- a/src/templates/coins-designs.html.tmpl +++ b/src/templates/coins-designs.html.tmpl @@ -1,4 +1,6 @@ {{ define "header" }} +{{ template "header-navbar" . }} + <style> .country-grid { --button-min-width: 20ch; diff --git a/src/templates/coins-mintages.html.tmpl b/src/templates/coins-mintages.html.tmpl index 8df0868..9624a8b 100644 --- a/src/templates/coins-mintages.html.tmpl +++ b/src/templates/coins-mintages.html.tmpl @@ -1,3 +1,7 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} diff --git a/src/templates/coins.html.tmpl b/src/templates/coins.html.tmpl index 6319c22..cc8eea1 100644 --- a/src/templates/coins.html.tmpl +++ b/src/templates/coins.html.tmpl @@ -1,3 +1,7 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} diff --git a/src/templates/collecting-crh.html.tmpl b/src/templates/collecting-crh.html.tmpl index d3f7197..109d9a7 100644 --- a/src/templates/collecting-crh.html.tmpl +++ b/src/templates/collecting-crh.html.tmpl @@ -1,3 +1,7 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} diff --git a/src/templates/collecting-storage.html.tmpl b/src/templates/collecting-storage.html.tmpl index d5a590b..25150d4 100644 --- a/src/templates/collecting-storage.html.tmpl +++ b/src/templates/collecting-storage.html.tmpl @@ -1,3 +1,7 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} @@ -160,4 +164,4 @@ > </div> </details> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/src/templates/collecting-vending.html.tmpl b/src/templates/collecting-vending.html.tmpl index 2bfea22..fa5a72c 100644 --- a/src/templates/collecting-vending.html.tmpl +++ b/src/templates/collecting-vending.html.tmpl @@ -1,3 +1,7 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} diff --git a/src/templates/collecting.html.tmpl b/src/templates/collecting.html.tmpl index fd14184..676f55b 100644 --- a/src/templates/collecting.html.tmpl +++ b/src/templates/collecting.html.tmpl @@ -1,3 +1,7 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} diff --git a/src/templates/index.html.tmpl b/src/templates/index.html.tmpl index da35043..4091ef6 100644 --- a/src/templates/index.html.tmpl +++ b/src/templates/index.html.tmpl @@ -1,9 +1,14 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} + {{ define "content" }} <header> {{ template "navbar" . }} <hgroup> <h1>{{ .Get "The Euro Cash Wiki" }}</h1> <p> + <!-- TODO: Just make this one translation --> {{/* TRANSLATORS: Beginning of sentence, as in ‘United in …’ */}} {{ .Get "United in" }} <del>{{ .Get "diversity" }}</del> diff --git a/src/templates/jargon.html.tmpl b/src/templates/jargon.html.tmpl index 79519aa..f73ed5f 100644 --- a/src/templates/jargon.html.tmpl +++ b/src/templates/jargon.html.tmpl @@ -1,4 +1,8 @@ +{{ define "header" }} +{{ template "header-navbar" . }} +{{ end }} {{ define "content" }} + <header> {{ template "navbar" . }} <h1>{{ .Get "Euro Cash Jargon" }}</h1> @@ -67,4 +71,4 @@ {{ index . 1 }} </a> </dt> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/src/templates/language.html.tmpl b/src/templates/language.html.tmpl index e8d8863..3315fd3 100644 --- a/src/templates/language.html.tmpl +++ b/src/templates/language.html.tmpl @@ -1,4 +1,6 @@ {{ define "header" }} +{{ template "header-navbar" . }} + <style> .lang-fade-in-out { transition: opacity 1s; |