Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add media:thumbnail and itunes:image to generated rss feeds #65

Merged
merged 3 commits into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,21 @@ func (s *Server) getFeedCtrl(w http.ResponseWriter, r *http.Request) {
PubDate: items[0].PubDate,
LastBuildDate: time.Now().Format(time.RFC822Z),
NsItunes: "http://www.itunes.com/dtds/podcast-1.0.dtd",
NsMedia: "http://search.yahoo.com/mrss/",
}

// replace link to UI page
if s.Conf.System.BaseURL != "" {
rss.Link = s.Conf.System.BaseURL + "/feed/" + feedName
baseURL := s.Conf.System.BaseURL
rss.Link = baseURL + "/feed/" + feedName
if s.Conf.Feeds[feedName].Image != "" {
rss.ItunesImage = feed.ItunesImg{
URL: baseURL + s.Conf.Feeds[feedName].Image,
}
rss.MediaThumbnail = feed.MediaThumbnail{
URL: baseURL + s.Conf.Feeds[feedName].Image,
}
}
}

b, err := xml.MarshalIndent(&rss, "", " ")
Expand Down
31 changes: 22 additions & 9 deletions app/feed/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,32 @@ import (

// Rss2 feed
type Rss2 struct {
XMLName xml.Name `xml:"rss"`
Version string `xml:"version,attr"`
NsItunes string `xml:"xmlns:itunes,attr"`
Title string `xml:"channel>title"`
Language string `xml:"channel>language"`
Link string `xml:"channel>link"`
Description string `xml:"channel>description"`
PubDate string `xml:"channel>pubDate"`
LastBuildDate string `xml:"channel>lastBuildDate"`
XMLName xml.Name `xml:"rss"`
Version string `xml:"version,attr"`
NsItunes string `xml:"xmlns:itunes,attr"`
NsMedia string `xml:"xmlns:media,attr"`
Title string `xml:"channel>title"`
Language string `xml:"channel>language"`
Link string `xml:"channel>link"`
Description string `xml:"channel>description"`
PubDate string `xml:"channel>pubDate"`
LastBuildDate string `xml:"channel>lastBuildDate"`
ItunesImage ItunesImg `xml:"channel>itunes:image"`
MediaThumbnail MediaThumbnail `xml:"channel>media:thumbnail"`

ItemList []Item `xml:"channel>item"`
}

// ItunesImg image element for iTunes
type ItunesImg struct {
URL string `xml:"href,attr"`
}

// MediaThumbnail image element for media
type MediaThumbnail struct {
URL string `xml:"url,attr"`
}

// Enclosure element from item
type Enclosure struct {
URL string `xml:"url,attr"`
Expand Down