From ad1d349a0cde68a09a1c328479aa2937ce2c885e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Sat, 23 Mar 2024 13:20:11 -0700 Subject: [PATCH] rss: use Channel tags only if there is no Item tags --- internal/reader/rss/adapter.go | 10 ++++++---- internal/reader/rss/parser_test.go | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/reader/rss/adapter.go b/internal/reader/rss/adapter.go index 07d56059..134f15b2 100644 --- a/internal/reader/rss/adapter.go +++ b/internal/reader/rss/adapter.go @@ -123,11 +123,13 @@ 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()...) - entry.Tags = append(entry.Tags, r.rss.Channel.Categories...) - entry.Tags = append(entry.Tags, r.rss.Channel.GetItunesCategories()...) + if len(entry.Tags) == 0 { + entry.Tags = append(entry.Tags, r.rss.Channel.Categories...) + entry.Tags = append(entry.Tags, r.rss.Channel.GetItunesCategories()...) - if r.rss.Channel.GooglePlayCategory.Text != "" { - entry.Tags = append(entry.Tags, r.rss.Channel.GooglePlayCategory.Text) + if r.rss.Channel.GooglePlayCategory.Text != "" { + entry.Tags = append(entry.Tags, r.rss.Channel.GooglePlayCategory.Text) + } } feed.Entries = append(feed.Entries, entry) diff --git a/internal/reader/rss/parser_test.go b/internal/reader/rss/parser_test.go index 8d84e582..83e844cb 100644 --- a/internal/reader/rss/parser_test.go +++ b/internal/reader/rss/parser_test.go @@ -1890,11 +1890,11 @@ func TestParseEntryWithCategories(t *testing.T) { t.Fatal(err) } - if len(feed.Entries[0].Tags) != 3 { - t.Errorf("Incorrect number of tags, got: %d", len(feed.Entries[0].Tags)) + if len(feed.Entries[0].Tags) != 2 { + t.Fatalf("Incorrect number of tags, got: %d", len(feed.Entries[0].Tags)) } - expected := []string{"Category 1", "Category 2", "Category 3"} + expected := []string{"Category 1", "Category 2"} result := feed.Entries[0].Tags for i, tag := range result {