From a5973b3c2a910a5f9250a5230e991b8d0506d23f Mon Sep 17 00:00:00 2001 From: Slatian Date: Fri, 25 Nov 2022 20:57:01 +0100 Subject: [PATCH 1/3] Pass a view variable to the templates to allow more shared templates --- server/server.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/server.go b/server/server.go index f7b16d0..fdc0946 100644 --- a/server/server.go +++ b/server/server.go @@ -24,6 +24,7 @@ type RequestHandler struct { type TemplateView struct { SiteName string + View string Data interface{} } @@ -211,6 +212,7 @@ func (h RequestHandler) webringRoute(res http.ResponseWriter, req *http.Request) func (h RequestHandler) renderView(res http.ResponseWriter, tmpl string, view *TemplateView) { view.SiteName = h.config.General.Name + view.View = tmpl var errTemp error if _, exists := os.LookupEnv("LIEU_DEV"); exists { var templates = template.Must(template.ParseFiles( From 39d1b53bdb174eae52517ae3828d262f34458f0a Mon Sep 17 00:00:00 2001 From: Slatian Date: Sat, 26 Nov 2022 02:49:44 +0100 Subject: [PATCH 2/3] Deduplicated search form and header (search form moved to nav.html too) and some minor accessibility improvements (hopefully) Note for potential upstreaming: This depends on commit eb4aed02e98083892afbf805ec628a2a20951b58 for passing the .View variable to the templates --- html/index.html | 21 +++------------------ html/nav.html | 32 +++++++++++++++++++++++++------- html/search.html | 14 ++------------ 3 files changed, 30 insertions(+), 37 deletions(-) diff --git a/html/index.html b/html/index.html index f23b98e..4c6bfd8 100644 --- a/html/index.html +++ b/html/index.html @@ -1,13 +1,5 @@ {{ template "head" . }} -
- Lieu - -
+{{ template "nav" . }}
@@ -17,15 +9,8 @@

{{ .Data.Tagline }}

- + + {{ template "search-form" . }}
diff --git a/html/nav.html b/html/nav.html index eb85a54..27e12bb 100644 --- a/html/nav.html +++ b/html/nav.html @@ -1,11 +1,29 @@ {{ define "nav" }}
- {{ .SiteName }} - + {{ if eq .View "index" }} + Lieu + {{else}} + {{ .SiteName }} + {{ end }} +
{{ end }} + +{{ define "search-form" }} + +{{ end }} diff --git a/html/search.html b/html/search.html index 387f7e1..209ace2 100644 --- a/html/search.html +++ b/html/search.html @@ -3,18 +3,8 @@

{{ .Data.Title }} {{ if ne .Data.Site "" }} for {{ .Data.Site }} {{ end }}

- + + {{ template "search-form" . }} {{ if ne .Data.Site "" }}