2024-02-27 09:03:21 +01:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"html/template"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
2024-03-05 17:13:59 +01:00
|
|
|
"git.streifling.com/jason/rss"
|
2024-02-27 09:03:21 +01:00
|
|
|
"streifling.com/jason/cpolis/cmd/data"
|
|
|
|
)
|
|
|
|
|
2024-03-05 17:13:59 +01:00
|
|
|
func ShowRSS(c *data.Channel) http.HandlerFunc {
|
2024-02-27 09:03:21 +01:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
2024-03-05 17:13:59 +01:00
|
|
|
channel := c.Get()
|
|
|
|
feed := rss.NewFeed()
|
|
|
|
feed.Channels = append(feed.Channels, &channel)
|
|
|
|
rss, err := feed.ToXML()
|
2024-02-27 09:03:21 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
2024-03-02 09:09:55 +01:00
|
|
|
|
|
|
|
files := []string{"web/templates/index.html", "web/templates/feed.rss"}
|
|
|
|
tmpl, err := template.ParseFiles(files...)
|
|
|
|
template.Must(tmpl, err).Execute(w, rss)
|
2024-02-27 09:03:21 +01:00
|
|
|
}
|
|
|
|
}
|