feat: use description as fallback for RSS items without titles

This commit is contained in:
ssrtw 2024-06-12 15:36:29 +00:00
parent d3e3667405
commit c23dc93c7a

View File

@ -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 != "" {