diff --git a/atom.go b/atom.go
index ccbe786..08808a6 100644
--- a/atom.go
+++ b/atom.go
@@ -71,6 +71,10 @@ func (this *Feed) readAtom(doc *xmlx.Document) (err error) {
list = node.SelectNodes(ns, "entry")
for _, item := range list {
+ if isItemPresent(ch, item.S(ns, "id"), item.S(ns, "title")) {
+ continue
+ }
+
i = new(Item)
i.Title = item.S(ns, "title")
i.Id = item.S(ns, "id")
@@ -123,3 +127,19 @@ func (this *Feed) readAtom(doc *xmlx.Document) (err error) {
}
return
}
+
+func isItemPresent(ch *Channel, id, title string) bool {
+ for _, item := range ch.Items {
+ switch {
+ case len(id) > 0:
+ if item.Id == id {
+ return true
+ }
+ case len(title) > 0:
+ if item.Title == title {
+ return true
+ }
+ }
+ }
+ return false
+}
diff --git a/feed_test.go b/feed_test.go
index fad7b7f..c069660 100644
--- a/feed_test.go
+++ b/feed_test.go
@@ -7,6 +7,20 @@ import (
var items []*Item
+func Test_NewItem(t *testing.T) {
+ content, _ := ioutil.ReadFile("testdata/initial.atom")
+ feed := New(1, true, chanHandler, itemHandler)
+ err := feed.FetchBytes("http://example.com", content, nil)
+ if err != nil { t.Error(err) }
+
+ content, _ = ioutil.ReadFile("testdata/initial_plus_one_new.atom")
+ feed.FetchBytes("http://example.com", content, nil)
+ expected := "Second title"
+ if expected != items[0].Title {
+ t.Errorf("Expected %s, got %s", expected, items[0].Title)
+ }
+}
+
func TestFeed(t *testing.T) {
urilist := []string{
//"http://cyber.law.harvard.edu/rss/examples/sampleRss091.xml", // Non-utf8 encoding.
diff --git a/testdata/initial.atom b/testdata/initial.atom
new file mode 100644
index 0000000..b086591
--- /dev/null
+++ b/testdata/initial.atom
@@ -0,0 +1,8 @@
+
+ Some title
+ http://www.example.com/feed/atom/
+
+ First title
+ 1
+
+
diff --git a/testdata/initial_plus_one_new.atom b/testdata/initial_plus_one_new.atom
new file mode 100644
index 0000000..2461a66
--- /dev/null
+++ b/testdata/initial_plus_one_new.atom
@@ -0,0 +1,12 @@
+
+ Some title
+ http://www.example.com/feed/atom/
+
+ First title
+ 1
+
+
+ Second title
+ 2
+
+