53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"github.com/gorilla/feeds"
|
||
|
"github.com/mmcdole/gofeed"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func (ctx* ServerContext) BuildRSS(input *gofeed.Feed) (string, error) {
|
||
|
output := &feeds.Feed{
|
||
|
Title : input.Title,
|
||
|
Link : &feeds.Link{ Href : input.Link },
|
||
|
Description : input.Description,
|
||
|
Author : &feeds.Author{
|
||
|
Name : input.Author.Name,
|
||
|
Email : input.Author.Email,
|
||
|
},
|
||
|
Created : *input.PublishedParsed,
|
||
|
Updated : *input.UpdatedParsed,
|
||
|
Image : &feeds.Image{
|
||
|
Url : input.Image.URL,
|
||
|
Title : input.Image.Title,
|
||
|
},
|
||
|
}
|
||
|
for _, item := range input.Items {
|
||
|
var created time.Time
|
||
|
if item.PublishedParsed!=nil {
|
||
|
created = *item.PublishedParsed
|
||
|
}
|
||
|
var updated time.Time
|
||
|
if item.UpdatedParsed!=nil {
|
||
|
updated = *item.UpdatedParsed
|
||
|
}
|
||
|
output.Items = append(output.Items, &feeds.Item{
|
||
|
Title : item.Title,
|
||
|
Link : &feeds.Link{ Href : item.Link },
|
||
|
Description : item.Description,
|
||
|
Author : &feeds.Author{
|
||
|
Name : item.Author.Name,
|
||
|
Email : item.Author.Email,
|
||
|
},
|
||
|
Created : created,
|
||
|
Updated : updated,
|
||
|
Enclosure : &feeds.Enclosure{
|
||
|
Url : item.Enclosures[0].URL,
|
||
|
Length : item.Enclosures[0].Length,
|
||
|
Type : item.Enclosures[0].Type,
|
||
|
},
|
||
|
})
|
||
|
}
|
||
|
return output.ToRss()
|
||
|
}
|