Merge pull request #16 from skypher/master

Support Atom dates in RSS.
This commit is contained in:
Erik Unger 2019-03-10 10:27:37 +01:00 committed by GitHub
commit eec8e4f8e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 3860 additions and 3 deletions

5
rss.go
View file

@ -46,7 +46,7 @@ type Item struct {
Category []string `xml:"category"`
Enclosure []ItemEnclosure `xml:"enclosure"`
Description string `xml:"description"`
Author string `xml:"author"`
Author string `xml:"author"`
Content string `xml:"content"`
FullText string `xml:"full-text"`
}
@ -59,6 +59,9 @@ func (d Date) Parse() (time.Time, error) {
t, err := d.ParseWithFormat(wordpressDateFormat)
if err != nil {
t, err = d.ParseWithFormat(time.RFC822) // RSS 2.0 spec
if err != nil {
t, err = d.ParseWithFormat(time.RFC3339) // Atom
}
}
return t, err
}

View file

@ -30,7 +30,7 @@ func (f *testFetcher) Get(url string) (resp *http.Response, err error) {
}
// A trivial test making sure that that all feeds parse - it *does not* check
// for correctness or completeness thereof.
// for correctness or completeness thereof, except for dates.
func TestAllFeedsParse(t *testing.T) {
fileInfos, err := ioutil.ReadDir(testDataDir)
if err != nil {
@ -41,8 +41,14 @@ func TestAllFeedsParse(t *testing.T) {
if !strings.HasSuffix(fileName, testFileSuffix) {
continue
}
if _, err := ReadWithClient(fileName, new(testFetcher)); err != nil {
channel, err := ReadWithClient(fileName, new(testFetcher))
if err != nil {
t.Fatalf("ReadWithClient(%q) err = %v, expected nil", fileName, err)
}
for _, item := range channel.Item {
if _, err := item.PubDate.Parse(); err != nil {
t.Fatalf("Date Parser(%q) err = %v, expected nil", fileName, err)
}
}
}
}

3848
testdata/remoteok.io.rss vendored Normal file

File diff suppressed because one or more lines are too long