From 56942b5372aa16de00dbbf6a9ab33836802a3f10 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 21 Dec 2021 23:13:22 +0100 Subject: Prefer the self-link of the feed over the URL. Rationale: The URL we use to access the feed may be an (old) alias. Relative URLs in feed items are written with the "real" URL of the feed in mind, though. --- internal/feed/feed.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'internal/feed') diff --git a/internal/feed/feed.go b/internal/feed/feed.go index 014f8b6..0741e8c 100644 --- a/internal/feed/feed.go +++ b/internal/feed/feed.go @@ -138,18 +138,24 @@ func (feed *Feed) id() string { func (feed *Feed) url() *url.URL { var feedUrl *url.URL - var err error - if feed.Url != "" { - feedUrl, err = url.Parse(feed.Url) - if err != nil { - panic(fmt.Sprintf("URL '%s' of feed '%s' is not a valid URL. How have we ended up here?", feed.Url, feed.Name)) - } - } else if feed.feed.Link != "" { - feedUrl, err = url.Parse(feed.feed.Link) - if err != nil { - panic(fmt.Sprintf("Link '%s' of feed '%s' is not a valid URL.", feed.feed.Link, feed.Name)) + tryUrl := func(content, what string) bool { + var err error + if content != "" { + feedUrl, err = url.Parse(content) + if err != nil { + log.Errorf("%s '%s' of feed '%s' is not a valid URL.", what, content, feed.Name) + } else { + return true + } } + return false + } + + if !(tryUrl(feed.feed.FeedLink, "Self-Link") || + tryUrl(feed.Url, "URL") || + tryUrl(feed.feed.Link, "Link")) { + panic(fmt.Sprintf("Could not find a valid URL for for feed '%s'. How have we ended up here?", feed.Name)) } return feedUrl -- cgit v1.2.3-70-g09d2