Sfoglia il codice sorgente

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

Frédéric Guillot 2 anni fa
parent
commit
ad1d349a0c
2 ha cambiato i file con 9 aggiunte e 7 eliminazioni
  1. 6 4
      internal/reader/rss/adapter.go
  2. 3 3
      internal/reader/rss/parser_test.go

+ 6 - 4
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)

+ 3 - 3
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 {