diff options
| author | William Hergès <william@herges.fr> | 2025-10-27 16:04:14 +0100 |
|---|---|---|
| committer | William Hergès <william@herges.fr> | 2025-10-27 16:04:14 +0100 |
| commit | 0c3a89ee546a2a3215eb32d9786dabeda051812d (patch) | |
| tree | 5043137ab9b2a15b7a5786d4b7d22641ad06d403 /backend/data.go | |
| parent | 1f0cf029644861bc31a363ecfdbfcb6ebafff3b2 (diff) | |
fix(section): bad template for RSS
Diffstat (limited to 'backend/data.go')
| -rw-r--r-- | backend/data.go | 10 |
1 files changed, 9 insertions, 1 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] +} |
