aboutsummaryrefslogtreecommitdiff
path: root/backend/data.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-10-06 20:32:20 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2025-10-06 20:32:20 +0200
commitbde341ccfa74ad702745e84ee91c2e7045cbe307 (patch)
tree3d914112e7153c8fd7bc1d6a459d143f8ccab8f3 /backend/data.go
parent9cfcbabb032c729b06d581412a64a9e7cefed6b1 (diff)
feat(backend): rss feeds for logs
Diffstat (limited to 'backend/data.go')
-rw-r--r--backend/data.go28
1 files changed, 26 insertions, 2 deletions
diff --git a/backend/data.go b/backend/data.go
index 2d9f97d..6ca6020 100644
--- a/backend/data.go
+++ b/backend/data.go
@@ -14,6 +14,7 @@ import (
"net/url"
"regexp"
"strings"
+ txt "text/template"
)
var (
@@ -41,8 +42,7 @@ func (d *data) SetData(data *data) {
*d = *data
}
-func (d *data) handleGeneric(w http.ResponseWriter, r *http.Request, name string, custom dataUsable) {
- cfg := r.Context().Value(configKey).(*Config)
+func (d *data) merge(cfg *Config, r *http.Request) {
if d.Domain == "" {
d.Domain = cfg.Domain
}
@@ -74,6 +74,11 @@ func (d *data) handleGeneric(w http.ResponseWriter, r *http.Request, name string
}
d.URL = r.URL.Path
}
+}
+
+func (d *data) handleGeneric(w http.ResponseWriter, r *http.Request, name string, custom dataUsable) {
+ cfg := r.Context().Value(configKey).(*Config)
+ d.merge(cfg, r)
t, err := template.New("").Funcs(template.FuncMap{
"static": getStatic,
"fullStatic": func(path string) string {
@@ -108,6 +113,25 @@ 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")
+ if err != nil {
+ panic(err)
+ }
+ r.Header.Set("Content-Type", "application/rss+xml")
+ if custom == nil {
+ err = t.ExecuteTemplate(w, "rss.xml", d)
+ } else {
+ custom.SetData(d)
+ err = t.ExecuteTemplate(w, "rss.xml", custom)
+ }
+ if err != nil {
+ panic(err)
+ }
+}
+
func (d *data) Title() string {
title := d.Name
if d.Article {