reader/rss: don't add empty tags to RSS items
This commit adds a bunch of checks to prevent reader/rss from adding empty tags to rss items, as well as some minor refactors like nested conditions and loops unrolling.
This commit is contained in:
parent
b54fe66809
commit
f109e3207c
1 changed files with 27 additions and 13 deletions
|
@ -90,10 +90,10 @@ func (r *RSSAdapter) BuildFeed(baseURL string) *model.Feed {
|
||||||
entry.Title = findEntryTitle(&item)
|
entry.Title = findEntryTitle(&item)
|
||||||
if entry.Title == "" {
|
if entry.Title == "" {
|
||||||
entry.Title = sanitizer.TruncateHTML(entry.Content, 100)
|
entry.Title = sanitizer.TruncateHTML(entry.Content, 100)
|
||||||
}
|
|
||||||
if entry.Title == "" {
|
if entry.Title == "" {
|
||||||
entry.Title = entry.URL
|
entry.Title = entry.URL
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
entry.Author = findEntryAuthor(&item)
|
entry.Author = findEntryAuthor(&item)
|
||||||
if entry.Author == "" {
|
if entry.Author == "" {
|
||||||
|
@ -101,11 +101,10 @@ func (r *RSSAdapter) BuildFeed(baseURL string) *model.Feed {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate the entry hash.
|
// Generate the entry hash.
|
||||||
for _, value := range []string{item.GUID.Data, entryURL} {
|
if item.GUID.Data != "" {
|
||||||
if value != "" {
|
entry.Hash = crypto.Hash(item.GUID.Data)
|
||||||
entry.Hash = crypto.Hash(value)
|
} else if entryURL != "" {
|
||||||
break
|
entry.Hash = crypto.Hash(entryURL)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find CommentsURL if defined.
|
// Find CommentsURL if defined.
|
||||||
|
@ -121,12 +120,27 @@ func (r *RSSAdapter) BuildFeed(baseURL string) *model.Feed {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate entry categories.
|
// Populate entry categories.
|
||||||
entry.Tags = append(entry.Tags, item.Categories...)
|
for _, tag := range item.Categories {
|
||||||
entry.Tags = append(entry.Tags, item.MediaCategories.Labels()...)
|
if tag != "" {
|
||||||
|
entry.Tags = append(entry.Tags, tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, tag := range item.MediaCategories.Labels() {
|
||||||
|
if tag != "" {
|
||||||
|
entry.Tags = append(entry.Tags, tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
if len(entry.Tags) == 0 {
|
if len(entry.Tags) == 0 {
|
||||||
entry.Tags = append(entry.Tags, r.rss.Channel.Categories...)
|
for _, tag := range r.rss.Channel.Categories {
|
||||||
entry.Tags = append(entry.Tags, r.rss.Channel.GetItunesCategories()...)
|
if tag != "" {
|
||||||
|
entry.Tags = append(entry.Tags, tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, tag := range r.rss.Channel.GetItunesCategories() {
|
||||||
|
if tag != "" {
|
||||||
|
entry.Tags = append(entry.Tags, tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
if r.rss.Channel.GooglePlayCategory.Text != "" {
|
if r.rss.Channel.GooglePlayCategory.Text != "" {
|
||||||
entry.Tags = append(entry.Tags, r.rss.Channel.GooglePlayCategory.Text)
|
entry.Tags = append(entry.Tags, r.rss.Channel.GooglePlayCategory.Text)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue