summaryrefslogtreecommitdiff
path: root/internal/reader/rss/adapter.go
diff options
context:
space:
mode:
authorGravatar jvoisin <julien.voisin@dustri.org> 2024-03-25 02:02:50 +0100
committerGravatar Frédéric Guillot <f@miniflux.net> 2024-03-24 19:46:56 -0700
commitf109e3207cd195a694656d9ad30a151ef587f94a (patch)
tree850e34719f80363fd64d7ae610ba8d8aad4f2dbd /internal/reader/rss/adapter.go
parentb54fe66809d820233da00b582b645e4b513f6dda (diff)
downloadv2-f109e3207cd195a694656d9ad30a151ef587f94a.tar.gz
v2-f109e3207cd195a694656d9ad30a151ef587f94a.tar.zst
v2-f109e3207cd195a694656d9ad30a151ef587f94a.zip
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.
Diffstat (limited to '')
-rw-r--r--internal/reader/rss/adapter.go40
1 files changed, 27 insertions, 13 deletions
diff --git a/internal/reader/rss/adapter.go b/internal/reader/rss/adapter.go
index 134f15b2..38192714 100644
--- a/internal/reader/rss/adapter.go
+++ b/internal/reader/rss/adapter.go
@@ -90,9 +90,9 @@ func (r *RSSAdapter) BuildFeed(baseURL string) *model.Feed {
entry.Title = findEntryTitle(&item)
if entry.Title == "" {
entry.Title = sanitizer.TruncateHTML(entry.Content, 100)
- }
- if entry.Title == "" {
- entry.Title = entry.URL
+ if entry.Title == "" {
+ entry.Title = entry.URL
+ }
}
entry.Author = findEntryAuthor(&item)
@@ -101,11 +101,10 @@ func (r *RSSAdapter) BuildFeed(baseURL string) *model.Feed {
}
// Generate the entry hash.
- for _, value := range []string{item.GUID.Data, entryURL} {
- if value != "" {
- entry.Hash = crypto.Hash(value)
- break
- }
+ if item.GUID.Data != "" {
+ entry.Hash = crypto.Hash(item.GUID.Data)
+ } else if entryURL != "" {
+ entry.Hash = crypto.Hash(entryURL)
}
// Find CommentsURL if defined.
@@ -121,12 +120,27 @@ func (r *RSSAdapter) BuildFeed(baseURL string) *model.Feed {
}
// Populate entry categories.
- entry.Tags = append(entry.Tags, item.Categories...)
- entry.Tags = append(entry.Tags, item.MediaCategories.Labels()...)
+ for _, tag := range item.Categories {
+ 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 {
- entry.Tags = append(entry.Tags, r.rss.Channel.Categories...)
- entry.Tags = append(entry.Tags, r.rss.Channel.GetItunesCategories()...)
-
+ for _, tag := range r.rss.Channel.Categories {
+ 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 != "" {
entry.Tags = append(entry.Tags, r.rss.Channel.GooglePlayCategory.Text)
}