From c23dc93c7a8ea9a442a8ca320def1c8489095251 Mon Sep 17 00:00:00 2001 From: ssrtw Date: Wed, 12 Jun 2024 15:36:29 +0000 Subject: [PATCH] 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 != "" {