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 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'backend/data.go') 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] +} -- cgit v1.2.3 From 3ce41d99d688410a361d83767b50b64a35b569d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Mon, 27 Oct 2025 17:21:41 +0100 Subject: feat(sections): general rss feed --- backend/data.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'backend/data.go') diff --git a/backend/data.go b/backend/data.go index 794b763..809e6e6 100644 --- a/backend/data.go +++ b/backend/data.go @@ -36,6 +36,7 @@ type data struct { Links []Link Logo *Logo Quote string + Language string } func (d *data) SetData(data *data) { @@ -74,6 +75,9 @@ func (d *data) merge(cfg *Config, r *http.Request) { } d.URL = r.URL.Path } + if d.Language == "" { + d.Language = cfg.Language + } } func (d *data) handleGeneric(w http.ResponseWriter, r *http.Request, name string, custom dataUsable) { @@ -117,7 +121,15 @@ 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.New("").Funcs(txt.FuncMap{"first": templateFirst}).ParseFS(templates, "templates/rss.xml") + t, err := txt.New("").Funcs(txt.FuncMap{ + "first": templateFirst, + "uri": func(s string) string { + if s == "" { + return "" + } + return s + "/" + }, + }).ParseFS(templates, "templates/rss.xml") if err != nil { panic(err) } -- cgit v1.2.3