Skip to content

Commit

Permalink
Introduce atomExtensionsWithKey
Browse files Browse the repository at this point in the history
  • Loading branch information
Necoro committed Mar 5, 2023
1 parent 9eb41f5 commit 96ac374
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 96ac374

Please sign in to comment.