Skip to content

Commit

Permalink
expanded support to keeplist
Browse files Browse the repository at this point in the history
  • Loading branch information
filipedeluna committed Dec 20, 2023
1 parent 0fc157b commit f3bca96
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/reader/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,15 @@ func isBlockedEntry(feed *model.Feed, entry *model.Entry) bool {

func isAllowedEntry(feed *model.Feed, entry *model.Entry) bool {
if feed.KeeplistRules != "" {
if matchField(feed.KeeplistRules, entry.URL) || matchField(feed.KeeplistRules, entry.Title) {
var containsAllowedTag bool = false
for _, tag := range entry.Tags {
if matchField(feed.KeeplistRules, tag) {
containsAllowedTag = true
break
}
}

if matchField(feed.KeeplistRules, entry.URL) || matchField(feed.KeeplistRules, entry.Title) || containsAllowedTag {
slog.Debug("Allow entry based on rule",
slog.Int64("entry_id", entry.ID),
slog.String("entry_url", entry.URL),
Expand Down
4 changes: 4 additions & 0 deletions internal/reader/processor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func TestAllowEntries(t *testing.T) {
{&model.Feed{ID: 1, KeeplistRules: "(?i)example"}, &model.Entry{Title: "Some Example"}, true},
{&model.Feed{ID: 1, KeeplistRules: "(?i)example"}, &model.Entry{Title: "Something different"}, false},
{&model.Feed{ID: 1}, &model.Entry{Title: "No rule defined"}, true},
{&model.Feed{ID: 1, KeeplistRules: "(?i)example"}, &model.Entry{Title: "Something different", Tags: []string{"example", "something else"}}, true},
{&model.Feed{ID: 1, KeeplistRules: "(?i)example"}, &model.Entry{Title: "Example", Tags: []string{"example", "something else"}}, true},
{&model.Feed{ID: 1, KeeplistRules: "(?i)example"}, &model.Entry{Title: "Example", Tags: []string{"something different", "something else"}}, true},
{&model.Feed{ID: 1, KeeplistRules: "(?i)example"}, &model.Entry{Title: "Something more", Tags: []string{"something different", "something else"}}, false},
}

for _, tc := range scenarios {
Expand Down

0 comments on commit f3bca96

Please sign in to comment.