diff --git a/cmd/main.go b/cmd/main.go index e0a67bd..2749faa 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -60,13 +60,7 @@ func main() { mux.HandleFunc("GET /rejected-articles", view.ShowRejectedArticles(args, db, store)) mux.HandleFunc("GET /review-rejected-article/{id}", view.ReviewRejectedArticle(args, db, store)) mux.HandleFunc("GET /review-unpublished-article/{id}", view.ReviewUnpublishedArticle(args, db, store)) - mux.HandleFunc("GET /rss", view.ShowRSS( - args, - db, - "Freimaurer Distrikt Niedersachsen und Sachsen-Anhalt", - "https://distrikt-ni-st.de", - "Freiheit, Gleichheit, Brüderlichkeit, Toleranz und Humanität", - )) + mux.HandleFunc("GET /rss", view.ShowRSS(args)) mux.HandleFunc("GET /this-issue", view.ShowCurrentArticles(args, db)) mux.HandleFunc("GET /unpublished-articles", view.ShowUnpublishedArticles(args, db)) mux.HandleFunc("GET /write-article", view.WriteArticle(args, db)) diff --git a/cmd/view/rss.go b/cmd/view/rss.go index 5c749bc..6338913 100644 --- a/cmd/view/rss.go +++ b/cmd/view/rss.go @@ -1,95 +1,15 @@ package view import ( - "fmt" - "html/template" - "log" "net/http" - "time" + "path/filepath" - "git.streifling.com/jason/rss" "streifling.com/jason/cpolis/cmd/control" - "streifling.com/jason/cpolis/cmd/model" ) -func ShowRSS(c *control.CliArgs, db *model.DB, title, link, desc string) http.HandlerFunc { +func ShowRSS(c *control.CliArgs) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - channel := &rss.Channel{ - Title: title, - Link: link, - Description: desc, - Items: make([]*rss.Item, 0), - } - - articles, err := db.GetCertainArticles(true, false) - if err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - for _, article := range articles { - tags, err := db.GetArticleTags(article.ID) - if err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - tagNames := make([]string, 0) - for _, tag := range tags { - tagNames = append(tagNames, tag.Name) - } - tagNames = append(tagNames, fmt.Sprint("Orient Express ", article.IssueID)) - - user, err := db.GetUser(article.AuthorID) - if err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - articleTitle, err := control.ConvertToPlain(article.Title) - if err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - articleDescription, err := control.ConvertToPlain(article.Description) - if err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - articleContent, err := control.ConvertToHTML(article.Content) - if err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - channel.Items = append(channel.Items, &rss.Item{ - Title: articleTitle, - Author: user.FirstName + user.LastName, - PubDate: article.Created.Format(time.RFC1123Z), - Description: articleDescription, - Content: &rss.Content{Value: articleContent}, - Categories: tagNames, - }) - } - - feed := rss.NewFeed() - feed.Channels = append(feed.Channels, channel) - rss, err := feed.ToXML() - if err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - files := []string{c.WebDir + "/templates/index.html", c.WebDir + "/templates/feed.rss"} - tmpl, err := template.ParseFiles(files...) - template.Must(tmpl, err).Execute(w, rss) + w.Header().Add("Content-Disposition", "attachment; filename=\""+filepath.Base(c.RSSFile)+"\"") + http.ServeFile(w, r, c.RSSFile) } } diff --git a/web/templates/hub.html b/web/templates/hub.html index 0051cd0..09cf905 100644 --- a/web/templates/hub.html +++ b/web/templates/hub.html @@ -7,7 +7,7 @@