Makes rss replace channels and items, thus making it stateless
This commit is contained in:
parent
4fa6c97010
commit
6ef84d35e2
30
rss.go
30
rss.go
|
@ -17,23 +17,7 @@ var days = map[string]int{
|
|||
}
|
||||
|
||||
func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
|
||||
|
||||
getChan := func(pubdate, title string) *Channel {
|
||||
for _, c := range this.Channels {
|
||||
switch {
|
||||
case len(pubdate) > 0:
|
||||
if c.PubDate == pubdate {
|
||||
return c
|
||||
}
|
||||
case len(title) > 0:
|
||||
if c.Title == title {
|
||||
return c
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var foundChannels []*Channel
|
||||
var ch *Channel
|
||||
var i *Item
|
||||
var n *xmlx.Node
|
||||
|
@ -51,10 +35,8 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
|
|||
|
||||
channels := root.SelectNodes(ns, "channel")
|
||||
for _, node := range channels {
|
||||
if ch = getChan(node.S(ns, "pubDate"), node.S(ns, "title")); ch == nil {
|
||||
ch = new(Channel)
|
||||
this.Channels = append(this.Channels, ch)
|
||||
}
|
||||
ch = new(Channel)
|
||||
foundChannels = append(foundChannels, ch)
|
||||
|
||||
ch.Title = node.S(ns, "title")
|
||||
list = node.SelectNodes(ns, "link")
|
||||
|
@ -127,7 +109,6 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
|
|||
ch.TextInput.Link = n.S(ns, "link")
|
||||
}
|
||||
|
||||
itemcount := len(ch.Items)
|
||||
list = node.SelectNodes(ns, "item")
|
||||
if len(list) == 0 {
|
||||
list = doc.SelectNodes(ns, "item")
|
||||
|
@ -195,10 +176,7 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
|
|||
|
||||
ch.Items = append(ch.Items, i)
|
||||
}
|
||||
|
||||
if itemcount != len(ch.Items) && this.itemhandler != nil {
|
||||
this.itemhandler(this, ch, ch.Items[itemcount:])
|
||||
}
|
||||
}
|
||||
this.Channels = foundChannels
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue