rdf date & content

This commit is contained in:
Nazar Kanaev 2021-04-15 10:27:50 +01:00
parent d308bb64c2
commit f8455236dc
2 changed files with 34 additions and 5 deletions

View File

@ -21,7 +21,7 @@ type rdfItem struct {
Description string `xml:"description"` Description string `xml:"description"`
DublinCoreDate string `xml:"http://purl.org/dc/elements/1.1/ date"` DublinCoreDate string `xml:"http://purl.org/dc/elements/1.1/ date"`
DublinCoreContent string `xml:"http://purl.org/rss/1.0/modules/content/ encoded"` ContentEncoded string `xml:"http://purl.org/rss/1.0/modules/content/ encoded"`
} }
func ParseRDF(r io.Reader) (*Feed, error) { func ParseRDF(r io.Reader) (*Feed, error) {
@ -40,7 +40,9 @@ func ParseRDF(r io.Reader) (*Feed, error) {
dstfeed.Items = append(dstfeed.Items, Item{ dstfeed.Items = append(dstfeed.Items, Item{
GUID: srcitem.Link, GUID: srcitem.Link,
URL: srcitem.Link, URL: srcitem.Link,
Date: dateParse(srcitem.DublinCoreDate),
Title: srcitem.Title, Title: srcitem.Title,
Content: srcitem.ContentEncoded,
}) })
} }
return dstfeed, nil return dstfeed, nil

View File

@ -4,6 +4,7 @@ import (
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
"time"
) )
func TestRDFFeed(t *testing.T) { func TestRDFFeed(t *testing.T) {
@ -52,3 +53,29 @@ func TestRDFFeed(t *testing.T) {
t.Fatal("invalid rdf") t.Fatal("invalid rdf")
} }
} }
func TestRDFExtensions(t *testing.T) {
have, _ := Parse(strings.NewReader(`
<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns="http://purl.org/rss/1.0/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:content="http://purl.org/rss/1.0/modules/content/">
<item>
<dc:date>2006-01-02T15:04:05-07:00</dc:date>
<content:encoded><![CDATA[test]]></content:encoded>
</item>
</rdf:RDF>
`))
date, _ := time.Parse(time.RFC1123Z, time.RFC1123Z)
want := &Feed{
Items: []Item{
{Content: "test", Date: date},
},
}
if !reflect.DeepEqual(want, have) {
t.Logf("want: %#v", want)
t.Logf("have: %#v", have)
t.FailNow()
}
}