From d3e3667405738218f4ea86557bea654c23585ecc Mon Sep 17 00:00:00 2001 From: ssrtw Date: Wed, 12 Jun 2024 03:28:43 +0000 Subject: [PATCH 1/4] fix: add detailed mode flag to fix RSS logic conflict --- internal/feed/rss.go | 49 ++++++++++++++++++++++-------------------- internal/widget/rss.go | 5 ++--- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/internal/feed/rss.go b/internal/feed/rss.go index 4d22af6..8260876 100644 --- a/internal/feed/rss.go +++ b/internal/feed/rss.go @@ -49,6 +49,7 @@ type RSSFeedRequest struct { HideCategories bool `yaml:"hide-categories"` HideDescription bool `yaml:"hide-description"` ItemLinkPrefix string `yaml:"item-link-prefix"` + IsDetailed bool } type RSSFeedItems []RSSFeedItem @@ -107,34 +108,36 @@ func getItemsFromRSSFeedTask(request RSSFeedRequest) ([]RSSFeedItem, error) { } } - if !request.HideDescription && item.Description != "" { - description, _ := limitStringLength(item.Description, 1000) - description = sanitizeFeedDescription(description) - description, limited := limitStringLength(description, 200) + if request.IsDetailed { + if !request.HideDescription && item.Description != "" { + description, _ := limitStringLength(item.Description, 1000) + description = sanitizeFeedDescription(description) + description, limited := limitStringLength(description, 200) - if limited { - description += "…" - } - - rssItem.Description = description - } - - if !request.HideCategories { - var categories = make([]string, 0, 6) - - for _, category := range item.Categories { - if len(categories) == 6 { - break + if limited { + description += "…" } - if len(category) == 0 || len(category) > 30 { - continue - } - - categories = append(categories, category) + rssItem.Description = description } - rssItem.Categories = categories + if !request.HideCategories { + var categories = make([]string, 0, 6) + + for _, category := range item.Categories { + if len(categories) == 6 { + break + } + + if len(category) == 0 || len(category) > 30 { + continue + } + + categories = append(categories, category) + } + + rssItem.Categories = categories + } } if request.Title != "" { diff --git a/internal/widget/rss.go b/internal/widget/rss.go index 1d8ce9e..de89ec3 100644 --- a/internal/widget/rss.go +++ b/internal/widget/rss.go @@ -39,10 +39,9 @@ func (widget *RSS) Initialize() error { widget.CardHeight = 0 } - if widget.Style != "detailed-list" { + if widget.Style == "detailed-list" { for i := range widget.FeedRequests { - widget.FeedRequests[i].HideCategories = true - widget.FeedRequests[i].HideDescription = true + widget.FeedRequests[i].IsDetailed = true } } From c23dc93c7a8ea9a442a8ca320def1c8489095251 Mon Sep 17 00:00:00 2001 From: ssrtw Date: Wed, 12 Jun 2024 15:36:29 +0000 Subject: [PATCH 2/4] feat: use description as fallback for RSS items without titles --- internal/feed/rss.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/internal/feed/rss.go b/internal/feed/rss.go index 8260876..2cd93c8 100644 --- a/internal/feed/rss.go +++ b/internal/feed/rss.go @@ -43,6 +43,18 @@ func sanitizeFeedDescription(description string) string { return description } +func shortenFeedDescriptionLen(description string, maxLen int) string { + description, _ = limitStringLength(description, 1000) + description = sanitizeFeedDescription(description) + description, limited := limitStringLength(description, maxLen) + + if limited { + description += "…" + } + + return description +} + type RSSFeedRequest struct { Url string `yaml:"url"` Title string `yaml:"title"` @@ -110,15 +122,7 @@ func getItemsFromRSSFeedTask(request RSSFeedRequest) ([]RSSFeedItem, error) { if request.IsDetailed { if !request.HideDescription && item.Description != "" { - description, _ := limitStringLength(item.Description, 1000) - description = sanitizeFeedDescription(description) - description, limited := limitStringLength(description, 200) - - if limited { - description += "…" - } - - rssItem.Description = description + rssItem.Description = shortenFeedDescriptionLen(item.Description, 200) } if !request.HideCategories { @@ -138,6 +142,10 @@ func getItemsFromRSSFeedTask(request RSSFeedRequest) ([]RSSFeedItem, error) { rssItem.Categories = categories } + } else { + if item.Title == "" { + rssItem.Title = shortenFeedDescriptionLen(item.Description, 100) + } } if request.Title != "" { From a2b7f59dc9c28b3cc53ef4db4cc10c13adf74ef9 Mon Sep 17 00:00:00 2001 From: ssrtw Date: Thu, 13 Jun 2024 03:13:57 +0000 Subject: [PATCH 3/4] fix: correct title handling for RSS items without titles --- internal/feed/rss.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/feed/rss.go b/internal/feed/rss.go index 2cd93c8..3ca8b51 100644 --- a/internal/feed/rss.go +++ b/internal/feed/rss.go @@ -93,7 +93,6 @@ func getItemsFromRSSFeedTask(request RSSFeedRequest) ([]RSSFeedItem, error) { rssItem := RSSFeedItem{ ChannelURL: feed.Link, - Title: item.Title, } if request.ItemLinkPrefix != "" { @@ -120,8 +119,14 @@ func getItemsFromRSSFeedTask(request RSSFeedRequest) ([]RSSFeedItem, error) { } } + if item.Title != "" { + rssItem.Title = item.Title + } else { + rssItem.Title = shortenFeedDescriptionLen(item.Description, 100) + } + if request.IsDetailed { - if !request.HideDescription && item.Description != "" { + if !request.HideDescription && item.Description != "" && item.Title != "" { rssItem.Description = shortenFeedDescriptionLen(item.Description, 200) } @@ -142,10 +147,6 @@ func getItemsFromRSSFeedTask(request RSSFeedRequest) ([]RSSFeedItem, error) { rssItem.Categories = categories } - } else { - if item.Title == "" { - rssItem.Title = shortenFeedDescriptionLen(item.Description, 100) - } } if request.Title != "" { From 16da25898fb087067a342f3dbeb43027637bf7b3 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Wed, 3 Jul 2024 19:48:58 +0100 Subject: [PATCH 4/4] Prevent users from modifying internal property --- internal/feed/rss.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/feed/rss.go b/internal/feed/rss.go index 3ca8b51..fb400b5 100644 --- a/internal/feed/rss.go +++ b/internal/feed/rss.go @@ -61,7 +61,7 @@ type RSSFeedRequest struct { HideCategories bool `yaml:"hide-categories"` HideDescription bool `yaml:"hide-description"` ItemLinkPrefix string `yaml:"item-link-prefix"` - IsDetailed bool + IsDetailed bool `yaml:"-"` } type RSSFeedItems []RSSFeedItem