Skip to content

Commit

Permalink
rss valid fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Pineapple217 committed Mar 24, 2024
1 parent 9f1eb0a commit e13fd18
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions rss/rss.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,26 @@ import (
type RSS struct {
XMLName xml.Name `xml:"rss"`
Version string `xml:"version,attr"`
Channel Channel
Xmlns string `xml:"xmlns:atom,attr"`
Channel Channel `xml:"channel"`
}

type Channel struct {
Title string `xml:"title"`
Description string `xml:"description"`
Link string `xml:"link"`
Generator string `xml:"generator"`
Language string `xml:"language"`
Copyright string `xml:"copyright"`
Items []Item `xml:"item"`
Title string `xml:"title"`
Description string `xml:"description"`
Link string `xml:"link"`
Generator string `xml:"generator"`
Language string `xml:"language"`
Copyright string `xml:"copyright"`
AtomLink AtomLink `xml:"atom:link"`
Items []Item `xml:"item"`
}

type AtomLink struct {
XMLName xml.Name `xml:"atom:link"`
Href string `xml:"href,attr"`
Rel string `xml:"rel,attr"`
Type string `xml:"type,attr"`
}

type Item struct {
Expand All @@ -32,6 +41,7 @@ type Item struct {
Link string `xml:"link"`
PubDate string `xml:"pubDate"`
Category string `xml:"category"`
Guid string `xml:"guid"`
}

func RSSFeed(c echo.Context) error {
Expand All @@ -51,20 +61,23 @@ func RSSFeed(c echo.Context) error {
PubDate: time.Unix(post.CreatedAt, 0).Format(time.RFC1123Z),
Category: post.Tags.String,
Description: truncateString(post.Content),
Guid: config.Host + "/post/" + unixTime,
}
rssPosts = append(rssPosts, p)
}

feed := RSS{
Version: "2.0",
Xmlns: "http://www.w3.org/2005/Atom",
Channel: Channel{
Title: "Micro Blog of " + config.HomepageRights,
Description: config.HomepageMessage,
Link: config.Host + "/index.xml",
Link: config.Host,
Items: rssPosts,
Generator: "Golang",
Language: "en-uk",
Copyright: "Copyright " + strconv.Itoa(time.Now().Year()) + ", " + config.HomepageRights,
AtomLink: AtomLink{Href: config.Host + "/index.xml", Rel: "self", Type: "application/rss+xml"},
},
}
xmlData, err := xml.MarshalIndent(feed, "", " ")
Expand Down

0 comments on commit e13fd18

Please sign in to comment.