diff options
author | Haelwenn (lanodan) Monnier <contact@hacktivis.me> | 2019-07-01 00:26:32 +0200 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-07-01 09:44:21 -0400 |
commit | 6d79d2e3759afd8c7e27b5f758e7f1e387134c40 (patch) | |
tree | 3a3f344d89dd86a3721f863d85e34f542a353556 | |
parent | adede4451d10409f7d7ebf089817a5fbb845d261 (diff) |
Add support for resolving relative feed URLs
I think this is probably more like a bug in github.com/SlyMarbo/rss
but at least this fixes it for now
-rw-r--r-- | openring.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/openring.go b/openring.go index 11950bc..cbaba1f 100644 --- a/openring.go +++ b/openring.go @@ -109,6 +109,14 @@ func main() { if len(items) > *perSource { items = items[:*perSource] } + base, err := url.Parse(feed.UpdateURL) + if err != nil { + log.Fatal("failed parsing update URL of the feed") + } + feedLink, _ := url.Parse(feed.Link) + if err != nil { + log.Fatal("failed parsing canonical feed URL of the feed") + } for _, item := range items { raw_summary := item.Summary if len(raw_summary) == 0 { @@ -116,13 +124,19 @@ func main() { } summary := runewidth.Truncate( policy.Sanitize(raw_summary), *summaryLen, "…") + + itemLink, _ := url.Parse(item.Link) + if err != nil { + log.Fatal("failed parsing article URL of the feed item") + } + articles = append(articles, &Article{ Date: item.Date, - SourceLink: feed.Link, + SourceLink: base.ResolveReference(feedLink).String(), SourceTitle: feed.Title, Summary: template.HTML(summary), Title: item.Title, - Link: item.Link, + Link: base.ResolveReference(itemLink).String(), }) } } |