Improve JSON feed parsing

This commit is contained in:
Peter Stuifzand 2018-04-08 21:07:51 +02:00
parent fa877ef89b
commit 2818576e2e
2 changed files with 13 additions and 1 deletions

View File

@ -269,6 +269,7 @@ func (b *memoryBackend) feedItems(fetchURL, contentType string, body io.Reader)
for _, feedItem := range feed.Items {
var item microsub.Item
item.Type = "entry"
item.Name = feedItem.Title
item.Content.HTML = feedItem.ContentHTML
item.Content.Text = feedItem.ContentText
@ -276,7 +277,17 @@ func (b *memoryBackend) feedItems(fetchURL, contentType string, body io.Reader)
item.Summary = []string{feedItem.Summary}
item.Id = hex.EncodeToString([]byte(feedItem.ID))
item.Published = feedItem.DatePublished
itemAuthor := microsub.Card{}
itemAuthor.Type = "card"
itemAuthor.Name = feedItem.Author.Name
itemAuthor.URL = feedItem.Author.URL
itemAuthor.Photo = feedItem.Author.Avatar
if itemAuthor.URL != "" {
item.Author = itemAuthor
} else {
item.Author = author
}
item.Photo = []string{feedItem.Image}
items = append(items, item)
}

View File

@ -18,6 +18,7 @@ type JSONFeedItem struct {
Image string `json:"image,omitempty"`
ExternalURL string `json:"external_url,omitempty"`
DatePublished string `json:"date_published,omitempty"`
Author JSONFeedAuthor `json:"author,omitempty"`
Tags []string `json:"tags,omitempty"`
Attachments []JSONFeedAttachment `json:"attachments,omitempty"`
}