diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-12-21 23:13:22 +0100 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-12-21 23:13:22 +0100 |
commit | 56942b5372aa16de00dbbf6a9ab33836802a3f10 (patch) | |
tree | ce719dc7ac477077536c8a844ffb55611b032da7 /internal | |
parent | 549fa5aaf56a23a090e27f273f15ee09dd0a37cf (diff) | |
download | feed2imap-go-56942b5372aa16de00dbbf6a9ab33836802a3f10.tar.gz feed2imap-go-56942b5372aa16de00dbbf6a9ab33836802a3f10.tar.bz2 feed2imap-go-56942b5372aa16de00dbbf6a9ab33836802a3f10.zip |
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.
Diffstat (limited to '')
-rw-r--r-- | internal/feed/feed.go | 26 |
1 files changed, 16 insertions, 10 deletions
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 |