rss: use Channel tags only if there is no Item tags

This commit is contained in:
Frédéric Guillot 2024-03-23 13:20:11 -07:00
parent 7ee4a731af
commit ad1d349a0c
2 changed files with 9 additions and 7 deletions

View file

@ -123,11 +123,13 @@ func (r *RSSAdapter) BuildFeed(baseURL string) *model.Feed {
// Populate entry categories. // Populate entry categories.
entry.Tags = append(entry.Tags, item.Categories...) entry.Tags = append(entry.Tags, item.Categories...)
entry.Tags = append(entry.Tags, item.MediaCategories.Labels()...) entry.Tags = append(entry.Tags, item.MediaCategories.Labels()...)
entry.Tags = append(entry.Tags, r.rss.Channel.Categories...) if len(entry.Tags) == 0 {
entry.Tags = append(entry.Tags, r.rss.Channel.GetItunesCategories()...) entry.Tags = append(entry.Tags, r.rss.Channel.Categories...)
entry.Tags = append(entry.Tags, r.rss.Channel.GetItunesCategories()...)
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)
}
} }
feed.Entries = append(feed.Entries, entry) feed.Entries = append(feed.Entries, entry)

View file

@ -1890,11 +1890,11 @@ func TestParseEntryWithCategories(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if len(feed.Entries[0].Tags) != 3 { if len(feed.Entries[0].Tags) != 2 {
t.Errorf("Incorrect number of tags, got: %d", len(feed.Entries[0].Tags)) 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 result := feed.Entries[0].Tags
for i, tag := range result { for i, tag := range result {