From 0c3a89ee546a2a3215eb32d9786dabeda051812d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Mon, 27 Oct 2025 16:04:14 +0100 Subject: fix(section): bad template for RSS --- backend/data.go | 10 +++++++++- backend/section.go | 1 + backend/templates/rss.xml | 10 ++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/backend/data.go b/backend/data.go index 6ca6020..794b763 100644 --- a/backend/data.go +++ b/backend/data.go @@ -92,6 +92,7 @@ func (d *data) handleGeneric(w http.ResponseWriter, r *http.Request, name string }, "next": func(i int) int { return i + 1 }, "before": func(i int) int { return i - 1 }, + "first": templateFirst, }).ParseFS(templates, "templates/components.html", fmt.Sprintf("templates/%s.html", name), "templates/base.html") if err != nil { panic(err) @@ -116,7 +117,7 @@ func (d *data) handleGeneric(w http.ResponseWriter, r *http.Request, name string func (d *data) handleRSS(w http.ResponseWriter, r *http.Request, custom dataUsable) { cfg := r.Context().Value(configKey).(*Config) d.merge(cfg, r) - t, err := txt.ParseFS(templates, "templates/rss.xml") + t, err := txt.New("").Funcs(txt.FuncMap{"first": templateFirst}).ParseFS(templates, "templates/rss.xml") if err != nil { panic(err) } @@ -197,3 +198,10 @@ func getAsset(ctx context.Context, path string) *assetData { assets[path] = asset return asset } + +func templateFirst(a []*Section) *Section { + if len(a) == 0 { + return nil + } + return a[0] +} diff --git a/backend/section.go b/backend/section.go index 01ffc90..06b48cc 100644 --- a/backend/section.go +++ b/backend/section.go @@ -173,6 +173,7 @@ func (s *Section) handleRSS(w http.ResponseWriter, r *http.Request) { return } d.title = s.Name + d.PageDescription = s.Description d.handleRSS(w, r, d) } diff --git a/backend/templates/rss.xml b/backend/templates/rss.xml index 6d99272..2abca8e 100644 --- a/backend/templates/rss.xml +++ b/backend/templates/rss.xml @@ -3,15 +3,17 @@ {{ .Title }} - https://{{ .Domain }}/{{ .URI }}/ + {{ $sec := first .Sections }} + {{ $uri := $sec.URI }} + https://{{ .Domain }}/{{ $uri }}/ {{ .PageDescription }} fr-fr {{ $domain := .Domain }} - {{ range .Section.Data }} + {{ range $sec.Data }} {{ .DataTitle }} - https://{{ $domain }}/{{ .URI }}/{{ .Slug }} - https://{{ $domain }}/{{ .URI }}/{{ .Slug }} + https://{{ $domain }}/{{ $uri }}/{{ .Slug }} + https://{{ $domain }}/{{ $uri }}/{{ .Slug }} {{ .Description }} {{ .PubDateRSS }} -- cgit v1.2.3