Skip to content

Commit

Permalink
Support multiple links (#164)
Browse files Browse the repository at this point in the history
* Add Feed.Links

* Update tests, don't create empty list

* Use same rel logic for RSS atom extensions

* Support for JSON feed

* Fix invalid JSON and run `go mod tidy`

* Fix tests, don't return empty strings
  • Loading branch information
makew0rld authored Apr 19, 2021
1 parent 68eef24 commit 41f47c9
Show file tree
Hide file tree
Showing 18 changed files with 148 additions and 25 deletions.
2 changes: 2 additions & 0 deletions feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Feed struct {
Description string `json:"description,omitempty"`
Link string `json:"link,omitempty"`
FeedLink string `json:"feedLink,omitempty"`
Links []string `json:"links,omitempty"`
Updated string `json:"updated,omitempty"`
UpdatedParsed *time.Time `json:"updatedParsed,omitempty"`
Published string `json:"published,omitempty"`
Expand Down Expand Up @@ -50,6 +51,7 @@ type Item struct {
Description string `json:"description,omitempty"`
Content string `json:"content,omitempty"`
Link string `json:"link,omitempty"`
Links []string `json:"links,omitempty"`
Updated string `json:"updated,omitempty"`
UpdatedParsed *time.Time `json:"updatedParsed,omitempty"`
Published string `json:"published,omitempty"`
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.14

require (
github.com/PuerkitoBio/goquery v1.5.1
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/json-iterator/go v1.1.10
github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf
github.com/stretchr/testify v1.3.0
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/urfave/cli v1.22.3 h1:FpNT6zq26xNpHZy08emi755QwzLPs6Pukqjlc7RfOMU=
Expand All @@ -36,7 +34,6 @@ golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand Down
7 changes: 5 additions & 2 deletions testdata/parser/rss/rss_channel_item_link.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"items": [
{
"link": "http://example.org"
"link": "http://example.org",
"links": [
"http://example.org"
]
}
],
"version": "2.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"feedLink": "http://example.org",
"links": [
"http://example.org"
],
"items": [],
"feedType": "atom",
"feedVersion": "1.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"items": [
{
"link": "http://www.example.org"
"link": "http://www.example.org",
"links": [
"http://www.example.org"
]
}
],
"feedType": "atom",
"feedVersion": "0.3"
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"items": [
{
"link": "http://www.example.org"
"link": "http://www.example.org",
"links": [
"http://www.example.org"
]
}
],
"feedType": "atom",
"feedVersion": "1.0"
}
}
5 changes: 4 additions & 1 deletion testdata/translator/atom/feed_link_-_atom03_feed_link.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"link": "http://www.example.org",
"links": [
"http://www.example.org"
],
"items": [],
"feedType": "atom",
"feedVersion": "0.3"
}
}
5 changes: 4 additions & 1 deletion testdata/translator/atom/feed_link_-_atom10_feed_link.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"link": "http://www.example.org",
"links": [
"http://www.example.org"
],
"items": [],
"feedType": "atom",
"feedVersion": "1.0"
}
}
15 changes: 13 additions & 2 deletions testdata/translator/json/json10_full_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,29 @@
"updatedParsed": "2019-10-12T07:20:50.52Z",
"published": "2019-10-12T07:20:50.52Z",
"publishedParsed": "2019-10-12T07:20:50.52Z",
"links": [
"https://sample-json-feed.com",
"https://sample-json-feed.com/feed.json"
],
"items": [
{
"guid": "id",
"title": "title",
"link": "https://sample-json-feed.com/id",
"links": [
"https://sample-json-feed.com/id",
"https://sample-json-feed.com/external"
],
"content": "<p>content_html</p>",
"updated": "2019-10-12T07:20:50.52Z",
"updatedParsed": "2019-10-12T07:20:50.52Z",
"published": "2019-10-12T07:20:50.52Z",
"publishedParsed": "2019-10-12T07:20:50.52Z",
"description": "summary",
"categories": ["tag1", "tag2"],
"categories": [
"tag1",
"tag2"
],
"enclosures": [
{
"length": "100",
Expand All @@ -60,4 +71,4 @@
}
}
]
}
}
2 changes: 1 addition & 1 deletion testdata/translator/json/json10_simple_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
}
}
]
}
}
15 changes: 13 additions & 2 deletions testdata/translator/json/json11_full_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,29 @@
"updatedParsed": "2019-10-12T07:20:50.52Z",
"published": "2019-10-12T07:20:50.52Z",
"publishedParsed": "2019-10-12T07:20:50.52Z",
"links": [
"https://sample-json-feed.com",
"https://sample-json-feed.com/feed.json"
],
"items": [
{
"guid": "id",
"title": "title",
"link": "https://sample-json-feed.com/id",
"links": [
"https://sample-json-feed.com/id",
"https://sample-json-feed.com/external"
],
"content": "<p>content_html</p>",
"updated": "2019-10-12T07:20:50.52Z",
"updatedParsed": "2019-10-12T07:20:50.52Z",
"published": "2019-10-12T07:20:50.52Z",
"publishedParsed": "2019-10-12T07:20:50.52Z",
"description": "summary",
"categories": ["tag1", "tag2"],
"categories": [
"tag1",
"tag2"
],
"enclosures": [
{
"length": "100",
Expand All @@ -51,4 +62,4 @@
}
}
]
}
}
5 changes: 4 additions & 1 deletion testdata/translator/rss/feed_item_link_-_rdf_item_link.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"feedVersion": "1.0",
"items": [
{
"link": "http://example.org"
"link": "http://example.org",
"links": [
"http://example.org"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"feedVersion": "2.0",
"items": [
{
"link": "http://example.org"
"link": "http://example.org",
"links": [
"http://example.org"
]
}
]
}
7 changes: 5 additions & 2 deletions testdata/translator/rss/feed_link_-_rdf_channel_link.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"feedType": "rss",
"feedVersion": "1.0",
"items": [],
"link": "http://example.org"
}
"link": "http://example.org",
"links": [
"http://example.org"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
"feedLink": "http://example.org",
"feedType": "rss",
"feedVersion": "2.0",
"items": []
}
"items": [],
"links": [
"http://example.org"
]
}
5 changes: 4 additions & 1 deletion testdata/translator/rss/feed_link_-_rss_channel_link.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"feedType": "rss",
"feedVersion": "2.0",
"items": [],
"link": "http://example.org"
"link": "http://example.org",
"links": [
"http://example.org"
]
}
Loading

0 comments on commit 41f47c9

Please sign in to comment.