From 96ac374e68e71d8878329434279fbcefd40c7e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Wed, 5 Aug 2020 22:32:59 +0200 Subject: [PATCH] Introduce atomExtensionsWithKey --- translator.go | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/translator.go b/translator.go index 7fe02df8..eab95816 100644 --- a/translator.go +++ b/translator.go @@ -105,16 +105,13 @@ func (t *DefaultRSSTranslator) translateFeedLink(rss *rss.Feed) (link string) { } func (t *DefaultRSSTranslator) translateFeedFeedLink(rss *rss.Feed) (link string) { - atomExtensions := t.extensionsForKeys([]string{"atom", "atom10", "atom03"}, rss.Extensions) - for _, ex := range atomExtensions { - if links, ok := ex["link"]; ok { - for _, l := range links { - if l.Attrs["rel"] == "self" { - link = l.Attrs["href"] - } - } + t.atomExtensionsWithKey(rss, "link", func(l ext.Extension) bool { + if l.Attrs["rel"] == "self" { + link = l.Attrs["href"] + return true } - } + return false + }) return } @@ -467,6 +464,19 @@ func (t *DefaultRSSTranslator) extensionsForKeys(keys []string, extensions ext.E return } +func (t *DefaultRSSTranslator) atomExtensionsWithKey(rss *rss.Feed, tag string, f func(ext.Extension) bool) { + atomExtensions := t.extensionsForKeys([]string{"atom", "atom10", "atom03"}, rss.Extensions) + for _, ex := range atomExtensions { + if exts, ok := ex[tag]; ok { + for _, e := range exts { + if f(e) { + return + } + } + } + } +} + func (t *DefaultRSSTranslator) firstEntry(entries []string) (value string) { if entries == nil { return