Improve JSON feed handling (add author)
This commit is contained in:
parent
cf5b84fd19
commit
ce169ec397
|
@ -126,6 +126,13 @@ func (b *memoryBackend) feedItems(fetchURL, contentType string, body io.Reader)
|
|||
log.Printf("Error while parsing json feed: %s\n", err)
|
||||
return items, err
|
||||
}
|
||||
|
||||
author := microsub.Author{}
|
||||
author.Type = "card"
|
||||
author.Name = feed.Author.Name
|
||||
author.URL = feed.Author.URL
|
||||
author.Photo = feed.Author.Avatar
|
||||
|
||||
for _, feedItem := range feed.Items {
|
||||
var item microsub.Item
|
||||
item.Name = feedItem.Title
|
||||
|
@ -135,6 +142,7 @@ 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
|
||||
item.Author = author
|
||||
items = append(items, item)
|
||||
}
|
||||
} else if strings.HasPrefix(contentType, "text/xml") || strings.HasPrefix(contentType, "application/rss+xml") || strings.HasPrefix(contentType, "application/atom+xml") {
|
||||
|
@ -152,8 +160,8 @@ func (b *memoryBackend) feedItems(fetchURL, contentType string, body io.Reader)
|
|||
for _, feedItem := range feed.Items {
|
||||
var item microsub.Item
|
||||
item.Name = feedItem.Title
|
||||
item.Content.HTML = feedItem.Summary
|
||||
item.Content.Text = feedItem.Content
|
||||
item.Content.HTML = feedItem.Content
|
||||
item.Content.Text = feedItem.Summary
|
||||
item.URL = feedItem.Link
|
||||
item.Id = hex.EncodeToString([]byte(feedItem.ID))
|
||||
item.Published = feedItem.Date.Format(time.RFC3339)
|
||||
|
|
|
@ -21,10 +21,26 @@ type JSONFeedItem struct {
|
|||
Attachments []JSONFeedAttachment `json:"attachments,omitempty"`
|
||||
}
|
||||
|
||||
type JSONFeedAuthor struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
URL string `json:"url,omitempty"`
|
||||
Avatar string `json:"avatar,omitempty"`
|
||||
}
|
||||
|
||||
type JSONFeedHub struct {
|
||||
Type string `json:"type"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
type JSONFeed struct {
|
||||
Version string `json:"version"`
|
||||
Title string `json:"title"`
|
||||
HomePageURL string `json:"home_page_url"`
|
||||
FeedURL string `json:"feed_url"`
|
||||
NextUrl string `json:"next_url"`
|
||||
Icon string `json:"icon"`
|
||||
Favicon string `json:"favicon"`
|
||||
Author JSONFeedAuthor `json:"author,omitempty"`
|
||||
Items []JSONFeedItem `json:"items"`
|
||||
Hubs []JSONFeedHub `json:"hubs"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user