Skip to content

A self-hosted dashboard that puts all your feeds in one place

Fix relative rss item thumbnail links #813

Svilen Markovc791ff09d9b7
diff --git a/internal/glance/widget-rss.go b/internal/glance/widget-rss.go
index fe17b2f..74fffce 100644
--- a/internal/glance/widget-rss.go
+++ b/internal/glance/widget-rss.go
@@ -129,14 +129,15 @@ type rssFeedItem struct {
}
type rssFeedRequest struct {
- URL string `yaml:"url"`
- Title string `yaml:"title"`
- HideCategories bool `yaml:"hide-categories"`
- HideDescription bool `yaml:"hide-description"`
- Limit int `yaml:"limit"`
- ItemLinkPrefix string `yaml:"item-link-prefix"`
- Headers map[string]string `yaml:"headers"`
- IsDetailed bool `yaml:"-"`
+ URL string `yaml:"url"`
+ Title string `yaml:"title"`
+ HideCategories bool `yaml:"hide-categories"`
+ HideDescription bool `yaml:"hide-description"`
+ Limit int `yaml:"limit"`
+ ItemLinkPrefix string `yaml:"item-link-prefix"`
+ ThumbnailLinkPrefix string `yaml:"thumbnail-link-prefix"`
+ Headers map[string]string `yaml:"headers"`
+ IsDetailed bool `yaml:"-"`
}
type rssFeedItemList []rssFeedItem
@@ -321,6 +322,24 @@ func (widget *rssWidget) fetchItemsFromFeedTask(request rssFeedRequest) ([]rssFe
}
}
+ // For some reason gofeed sometimes converts absolute URLs to relative ones, so we need to fix
+ // that here and provide the user with an option to override the prefix in case we get it wrong
+ if strings.HasPrefix(rssItem.ImageURL, "/") {
+ prefix := strings.TrimPrefix(feed.Link, "/")
+ if request.ThumbnailLinkPrefix != "" {
+ prefix = strings.TrimPrefix(request.ThumbnailLinkPrefix, "/")
+ } else if prefix == "" {
+ parsed, err := url.Parse(request.URL)
+ if err != nil {
+ prefix = request.URL
+ } else {
+ prefix = parsed.Scheme + "://" + parsed.Host
+ }
+ }
+
+ rssItem.ImageURL = strings.TrimRight(prefix, "/") + rssItem.ImageURL
+ }
+
if item.PublishedParsed != nil {
rssItem.PublishedAt = *item.PublishedParsed
} else {