mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
eliminate duplicate links
This commit is contained in:
parent
be0ae1c1be
commit
796832025c
@ -60,17 +60,36 @@ func searchFeedLinks(html []byte, siteurl string) ([]FeedSource, error) {
|
|||||||
return sources, err
|
return sources, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// feed {url: title} map
|
||||||
|
feeds := make(map[string]string)
|
||||||
|
|
||||||
doc.Find(feedLinks).Each(func(i int, s *goquery.Selection) {
|
doc.Find(feedLinks).Each(func(i int, s *goquery.Selection) {
|
||||||
|
// Unlikely to happen, but don't get more than N links
|
||||||
|
if len(feeds) > 10 {
|
||||||
|
return
|
||||||
|
}
|
||||||
if href, ok := s.Attr("href"); ok {
|
if href, ok := s.Attr("href"); ok {
|
||||||
feedUrl, err := url.Parse(href)
|
feedUrl, err := url.Parse(href)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
title := s.AttrOr("title", "")
|
title := s.AttrOr("title", "")
|
||||||
url := base.ResolveReference(feedUrl).String()
|
url := base.ResolveReference(feedUrl).String()
|
||||||
sources = append(sources, FeedSource{Title: title, Url: url})
|
|
||||||
|
if _, alreadyExists := feeds[url]; alreadyExists {
|
||||||
|
if feeds[url] == "" {
|
||||||
|
feeds[url] = title
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
feeds[url] = title
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
for url, title := range feeds {
|
||||||
|
sources = append(sources, FeedSource{Title: title, Url: url})
|
||||||
|
}
|
||||||
return sources, nil
|
return sources, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user