Skip to content

Commit 41f47c9

Browse files
authored
Support multiple links (#164)
* 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
1 parent 68eef24 commit 41f47c9

18 files changed

+148
-25
lines changed

feed.go

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Feed struct {
1717
Description string `json:"description,omitempty"`
1818
Link string `json:"link,omitempty"`
1919
FeedLink string `json:"feedLink,omitempty"`
20+
Links []string `json:"links,omitempty"`
2021
Updated string `json:"updated,omitempty"`
2122
UpdatedParsed *time.Time `json:"updatedParsed,omitempty"`
2223
Published string `json:"published,omitempty"`
@@ -50,6 +51,7 @@ type Item struct {
5051
Description string `json:"description,omitempty"`
5152
Content string `json:"content,omitempty"`
5253
Link string `json:"link,omitempty"`
54+
Links []string `json:"links,omitempty"`
5355
Updated string `json:"updated,omitempty"`
5456
UpdatedParsed *time.Time `json:"updatedParsed,omitempty"`
5557
Published string `json:"published,omitempty"`

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.14
44

55
require (
66
github.com/PuerkitoBio/goquery v1.5.1
7-
github.com/davecgh/go-spew v1.1.1 // indirect
87
github.com/json-iterator/go v1.1.10
98
github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf
109
github.com/stretchr/testify v1.3.0

go.sum

-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
2424
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
2525
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
2626
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
27-
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
28-
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
2927
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
3028
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
3129
github.com/urfave/cli v1.22.3 h1:FpNT6zq26xNpHZy08emi755QwzLPs6Pukqjlc7RfOMU=
@@ -36,7 +34,6 @@ golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLL
3634
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
3735
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
3836
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
39-
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
4037
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
4138
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
4239
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"items": [
33
{
4-
"link": "http://example.org"
4+
"link": "http://example.org",
5+
"links": [
6+
"http://example.org"
7+
]
58
}
69
],
710
"version": "2.0"
8-
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"feedLink": "http://example.org",
3+
"links": [
4+
"http://example.org"
5+
],
36
"items": [],
47
"feedType": "atom",
58
"feedVersion": "1.0"
6-
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
22
"items": [
33
{
4-
"link": "http://www.example.org"
4+
"link": "http://www.example.org",
5+
"links": [
6+
"http://www.example.org"
7+
]
58
}
69
],
710
"feedType": "atom",
811
"feedVersion": "0.3"
9-
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
22
"items": [
33
{
4-
"link": "http://www.example.org"
4+
"link": "http://www.example.org",
5+
"links": [
6+
"http://www.example.org"
7+
]
58
}
69
],
710
"feedType": "atom",
811
"feedVersion": "1.0"
9-
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"link": "http://www.example.org",
3+
"links": [
4+
"http://www.example.org"
5+
],
36
"items": [],
47
"feedType": "atom",
58
"feedVersion": "0.3"
6-
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"link": "http://www.example.org",
3+
"links": [
4+
"http://www.example.org"
5+
],
36
"items": [],
47
"feedType": "atom",
58
"feedVersion": "1.0"
6-
}
9+
}

testdata/translator/json/json10_full_expected.json

+13-2
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,29 @@
2424
"updatedParsed": "2019-10-12T07:20:50.52Z",
2525
"published": "2019-10-12T07:20:50.52Z",
2626
"publishedParsed": "2019-10-12T07:20:50.52Z",
27+
"links": [
28+
"https://sample-json-feed.com",
29+
"https://sample-json-feed.com/feed.json"
30+
],
2731
"items": [
2832
{
2933
"guid": "id",
3034
"title": "title",
3135
"link": "https://sample-json-feed.com/id",
36+
"links": [
37+
"https://sample-json-feed.com/id",
38+
"https://sample-json-feed.com/external"
39+
],
3240
"content": "<p>content_html</p>",
3341
"updated": "2019-10-12T07:20:50.52Z",
3442
"updatedParsed": "2019-10-12T07:20:50.52Z",
3543
"published": "2019-10-12T07:20:50.52Z",
3644
"publishedParsed": "2019-10-12T07:20:50.52Z",
3745
"description": "summary",
38-
"categories": ["tag1", "tag2"],
46+
"categories": [
47+
"tag1",
48+
"tag2"
49+
],
3950
"enclosures": [
4051
{
4152
"length": "100",
@@ -60,4 +71,4 @@
6071
}
6172
}
6273
]
63-
}
74+
}

testdata/translator/json/json10_simple_expected.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
}
1010
}
1111
]
12-
}
12+
}

testdata/translator/json/json11_full_expected.json

+13-2
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,29 @@
2020
"updatedParsed": "2019-10-12T07:20:50.52Z",
2121
"published": "2019-10-12T07:20:50.52Z",
2222
"publishedParsed": "2019-10-12T07:20:50.52Z",
23+
"links": [
24+
"https://sample-json-feed.com",
25+
"https://sample-json-feed.com/feed.json"
26+
],
2327
"items": [
2428
{
2529
"guid": "id",
2630
"title": "title",
2731
"link": "https://sample-json-feed.com/id",
32+
"links": [
33+
"https://sample-json-feed.com/id",
34+
"https://sample-json-feed.com/external"
35+
],
2836
"content": "<p>content_html</p>",
2937
"updated": "2019-10-12T07:20:50.52Z",
3038
"updatedParsed": "2019-10-12T07:20:50.52Z",
3139
"published": "2019-10-12T07:20:50.52Z",
3240
"publishedParsed": "2019-10-12T07:20:50.52Z",
3341
"description": "summary",
34-
"categories": ["tag1", "tag2"],
42+
"categories": [
43+
"tag1",
44+
"tag2"
45+
],
3546
"enclosures": [
3647
{
3748
"length": "100",
@@ -51,4 +62,4 @@
5162
}
5263
}
5364
]
54-
}
65+
}

testdata/translator/rss/feed_item_link_-_rdf_item_link.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
"feedVersion": "1.0",
44
"items": [
55
{
6-
"link": "http://example.org"
6+
"link": "http://example.org",
7+
"links": [
8+
"http://example.org"
9+
]
710
}
811
]
912
}

testdata/translator/rss/feed_item_link_-_rss_channel_item_link.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
"feedVersion": "2.0",
44
"items": [
55
{
6-
"link": "http://example.org"
6+
"link": "http://example.org",
7+
"links": [
8+
"http://example.org"
9+
]
710
}
811
]
912
}

testdata/translator/rss/feed_link_-_rdf_channel_link.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
"feedType": "rss",
33
"feedVersion": "1.0",
44
"items": [],
5-
"link": "http://example.org"
6-
}
5+
"link": "http://example.org",
6+
"links": [
7+
"http://example.org"
8+
]
9+
}

testdata/translator/rss/feed_link_-_rss_channel_atom_link.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818
"feedLink": "http://example.org",
1919
"feedType": "rss",
2020
"feedVersion": "2.0",
21-
"items": []
22-
}
21+
"items": [],
22+
"links": [
23+
"http://example.org"
24+
]
25+
}

testdata/translator/rss/feed_link_-_rss_channel_link.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
"feedType": "rss",
33
"feedVersion": "2.0",
44
"items": [],
5-
"link": "http://example.org"
5+
"link": "http://example.org",
6+
"links": [
7+
"http://example.org"
8+
]
69
}

0 commit comments

Comments
 (0)