mirror of
https://github.com/glanceapp/glance.git
synced 2024-12-14 17:13:11 +03:00
feat: use description as fallback for RSS items without titles
This commit is contained in:
parent
d3e3667405
commit
c23dc93c7a
@ -43,6 +43,18 @@ func sanitizeFeedDescription(description string) string {
|
|||||||
return description
|
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 {
|
type RSSFeedRequest struct {
|
||||||
Url string `yaml:"url"`
|
Url string `yaml:"url"`
|
||||||
Title string `yaml:"title"`
|
Title string `yaml:"title"`
|
||||||
@ -110,15 +122,7 @@ func getItemsFromRSSFeedTask(request RSSFeedRequest) ([]RSSFeedItem, error) {
|
|||||||
|
|
||||||
if request.IsDetailed {
|
if request.IsDetailed {
|
||||||
if !request.HideDescription && item.Description != "" {
|
if !request.HideDescription && item.Description != "" {
|
||||||
description, _ := limitStringLength(item.Description, 1000)
|
rssItem.Description = shortenFeedDescriptionLen(item.Description, 200)
|
||||||
description = sanitizeFeedDescription(description)
|
|
||||||
description, limited := limitStringLength(description, 200)
|
|
||||||
|
|
||||||
if limited {
|
|
||||||
description += "…"
|
|
||||||
}
|
|
||||||
|
|
||||||
rssItem.Description = description
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !request.HideCategories {
|
if !request.HideCategories {
|
||||||
@ -138,6 +142,10 @@ func getItemsFromRSSFeedTask(request RSSFeedRequest) ([]RSSFeedItem, error) {
|
|||||||
|
|
||||||
rssItem.Categories = categories
|
rssItem.Categories = categories
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if item.Title == "" {
|
||||||
|
rssItem.Title = shortenFeedDescriptionLen(item.Description, 100)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.Title != "" {
|
if request.Title != "" {
|
||||||
|
Loading…
Reference in New Issue
Block a user