Finalize/fix RSS feeds

feat/db
Francesco Minnocci 2 years ago
parent c1a701353a
commit 684859c197
Signed by: BachoSeven
GPG Key ID: 2BE4AB7FDAD828A4

@ -6,7 +6,7 @@
<section> <section>
<h2> <h2>
Feed RSS Feed RSS
<a href="/guide/feed"> <i class="fa-solid fa-rss"></i></a> <a href="/guide/rss"> <i class="fa-solid fa-rss"></i></a>
</h2> </h2>
<h1> <h1>
<i class="fa-solid fa-person-chalkboard"></i> <i class="fa-solid fa-person-chalkboard"></i>

@ -6,7 +6,7 @@
<section> <section>
<h2> <h2>
Feed RSS Feed RSS
<a href="/news/feed"> <i class="fa-solid fa-rss"></i></a> <a href="/news/rss"> <i class="fa-solid fa-rss"></i></a>
</h2> </h2>
<h1> <h1>
<i class="far fa-newspaper"></i> <i class="far fa-newspaper"></i>

@ -198,7 +198,7 @@ func (h *DefaultHandler) HandleNewsFeedPage(w io.Writer) error {
return err return err
} }
newsFeed := rss.GenerateRssFeed(registry) newsFeed := rss.GenerateRssFeed(registry, "Feed Notizie PHC", "https://phc.dm.unipi.it/news", "Le ultime nuove sul PHC.")
return newsFeed.WriteRss(w) return newsFeed.WriteRss(w)
} }
@ -209,7 +209,7 @@ func (h *DefaultHandler) HandleGuideFeedPage(w io.Writer) error {
return err return err
} }
guideFeed := rss.GenerateRssFeed(registry) guideFeed := rss.GenerateRssFeed(registry, "Feed Guide PHC", "https://phc.dm.unipi.it/guide", "Le più recenti guide a carattere informatico a cura dei macchinisti del PHC.")
return guideFeed.WriteRss(w) return guideFeed.WriteRss(w)
} }

@ -5,16 +5,19 @@ import (
"github.com/gorilla/feeds" "github.com/gorilla/feeds"
) )
func GenerateRssFeed(entries []*articles.Article) *feeds.Feed { func GenerateRssFeed(entries []*articles.Article, title string, link string, description string) *feeds.Feed {
// Initialize RSS Feed // Initialize RSS Feed
feed := &feeds.Feed{} feed := &feeds.Feed{
Title: title,
Link: &feeds.Link{Href: link},
Description: description,
}
var feedItems []*feeds.Item var feedItems []*feeds.Item
// Add items to RSS feeds // Add items to RSS feeds
for _, entry := range entries { for _, entry := range entries {
feedItems = append(feedItems, feedItems = append(feedItems,
&feeds.Item{ &feeds.Item{
Id: entry.Id, Id: entry.Id,
@ -24,7 +27,6 @@ func GenerateRssFeed(entries []*articles.Article) *feeds.Feed {
Created: entry.PublishDate, Created: entry.PublishDate,
}) })
} }
feed.Items = feedItems feed.Items = feedItems
return feed return feed

@ -105,12 +105,12 @@ func routes(h handler.Service, r fiber.Router) {
return h.HandleGuidePage(c, CreateContext(c)) return h.HandleGuidePage(c, CreateContext(c))
}) })
r.Get("/news/feed", func(c *fiber.Ctx) error { r.Get("/news/rss", func(c *fiber.Ctx) error {
c.Type("xml") c.Type("xml")
return h.HandleNewsFeedPage(c) return h.HandleNewsFeedPage(c)
}) })
r.Get("/guide/feed", func(c *fiber.Ctx) error { r.Get("/guide/rss", func(c *fiber.Ctx) error {
c.Type("xml") c.Type("xml")
return h.HandleGuideFeedPage(c) return h.HandleGuideFeedPage(c)
}) })

Loading…
Cancel
Save