Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions internal/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,6 @@ func (c Commands) fetchAllFeeds() ([]store.Item, []ErrorItem, error) {
return items, errorItems, nil
}

func includes[T comparable](arr []T, item T) bool {
for _, v := range arr {
if v == item {
return true
}
}
return false
}

func (c Commands) Monitor(prog *tea.Program) {
if c.config.RefreshInterval == 0 {
return
Expand Down
1 change: 1 addition & 0 deletions internal/commands/feeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (c Commands) GetAllFeeds() ([]store.Item, error) {
for _, f := range c.config.Feeds {
if f.URL == is[i].FeedURL {
is[i].FeedName = f.Name
is[i].Tags = f.Tags
}
}
}
Expand Down
24 changes: 16 additions & 8 deletions internal/commands/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ import (
// Struct to aid in filtering items into ranks for BubbleTea
type Filterer struct {
FeedNames []string
Tags []string
Term struct {
Title string
FeedNames []string
Tags []string
}
Config config.FilterConfig
Config config.Config
}

// Filters by feednames
func (f *Filterer) FilterByFeedName(filterValues []string, targetFilterValues []string) fuzzy.Matches {
// Generalized function for filtering over a list of options (Used for filtering by feed name and tags)
func (f *Filterer) FilterAgainstStrings(filterValues []string, targetFilterValues []string) fuzzy.Matches {
// find matching feeds and keep the best matching one in case there are multiple
ranksGrouped := map[int]fuzzy.Match{}
for _, feedName := range filterValues {
Expand Down Expand Up @@ -63,6 +65,7 @@ func (f *Filterer) GetItem(filterValue string) TUIItem {

i.Title = splits[0]
i.FeedName = strings.ToLower(splits[1])
i.Tags = splits[2:]

return i
}
Expand Down Expand Up @@ -121,40 +124,45 @@ func (f *Filterer) ExtractFiltersFor(tags ...string) []string {
func (f *Filterer) Filter(targets []string) []fuzzy.Match {
var targetTitles []string
var targetFeedNames []string
var targetTags []string

for _, target := range targets {
i := f.GetItem(target)
title := i.Title
if f.Config.DefaultIncludeFeedName {
if f.Config.Filtering.DefaultIncludeFeedName {
title = strings.Join([]string{i.FeedName, i.Title}, " ")
}
targetTitles = append(targetTitles, title)
targetFeedNames = append(targetFeedNames, i.FeedName)
targetTags = append(targetTags, strings.Join(i.Tags, " "))
}

var ranks fuzzy.Matches
if len(f.FeedNames) == 0 {
if len(f.FeedNames) == 0 && len(f.Tags) == 0 {
ranks = fuzzy.Find(f.Term.Title, targetTitles)
} else if len(f.FeedNames) > 0 {
ranks = f.FilterAgainstStrings(f.FeedNames, targetFeedNames)
} else {
ranks = f.FilterByFeedName(f.FeedNames, targetFeedNames)
ranks = f.FilterAgainstStrings(f.Tags, targetTags)
}

sort.Stable(ranks)

return ranks
}

func NewFilterer(term string, config config.FilterConfig) Filterer {
func NewFilterer(term string, config config.Config) Filterer {
var f Filterer

f.Config = config
f.Term.Title = term
f.FeedNames = f.ExtractFiltersFor("feedname", "feed", "f")
f.Tags = f.ExtractFiltersFor("tag", "t")

return f
}

func CustomFilter(config config.FilterConfig) list.FilterFunc {
func CustomFilter(config config.Config) list.FilterFunc {
return func(term string, targets []string) []list.Rank {
filterer := NewFilterer(term, config)

Expand Down
8 changes: 6 additions & 2 deletions internal/commands/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ type TUIItem struct {
ID int
Read bool
Favourite bool
Tags []string
}

func (i TUIItem) FilterValue() string { return fmt.Sprintf("%s||%s", i.Title, i.FeedName) }
func (i TUIItem) FilterValue() string {
return fmt.Sprintf("%s||%s||%s", i.Title, i.FeedName, strings.Join(i.Tags, "||"))
}

type model struct {
selectedArticle *int
Expand Down Expand Up @@ -170,6 +173,7 @@ func ItemToTUIItem(i store.Item) TUIItem {
URL: i.Link,
Read: i.Read(),
Favourite: i.Favourite,
Tags: i.Tags,
}
}

Expand Down Expand Up @@ -244,7 +248,7 @@ func Render(items []list.Item, cmds *Commands, errors []string, cfg *config.Conf

l.FilterInput.PromptStyle = lipgloss.NewStyle().Foreground(lipgloss.Color(cfg.Theme.FilterColor))

l.Filter = CustomFilter(cfg.Filtering)
l.Filter = CustomFilter(*cfg)

ListKeyMap.SetOverrides(&l)

Expand Down
5 changes: 3 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ var (
)

type Feed struct {
URL string `yaml:"url"`
Name string `yaml:"name,omitempty"`
URL string `yaml:"url"`
Name string `yaml:"name,omitempty"`
Tags []string `yaml:"tags,omitempty"`
}

type MinifluxBackend struct {
Expand Down
1 change: 1 addition & 0 deletions internal/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Item struct {
Link string
GUID string
Content string
Tags []string
ReadAt time.Time
PublishedAt time.Time
UpdatedAt time.Time
Expand Down