diff --git a/src/FeedIo/Parser/JsonParser.php b/src/FeedIo/Parser/JsonParser.php index 7840905f..0176cb47 100644 --- a/src/FeedIo/Parser/JsonParser.php +++ b/src/FeedIo/Parser/JsonParser.php @@ -71,6 +71,7 @@ public function parseItems(iterable $items, FeedInterface $feed) : JsonParser $item->setLastModified(new \DateTime($this->readOffset($dataItem, 'date_published'))); $contentHtml = $this->readOffset($dataItem, 'content_html'); $item->setDescription($this->readOffset($dataItem, 'content_text', $contentHtml)); + $item->setLink($this->readOffset($dataItem, 'url')); $feed->add($item); } diff --git a/tests/FeedIo/Parser/JsonParserTest.php b/tests/FeedIo/Parser/JsonParserTest.php index 8e934df6..a66d4b61 100644 --- a/tests/FeedIo/Parser/JsonParserTest.php +++ b/tests/FeedIo/Parser/JsonParserTest.php @@ -32,5 +32,11 @@ public function testParseContent() $parser->parse($this->getDocument(), $feed); $this->assertEquals('JSON Feed', $feed->getTitle()); + + $items = $feed->toArray()['items']; + + $this->assertCount(2, $items); + $this->assertEquals('https://jsonfeed.org/2017/05/17/announcing_json_feed', $items[0]['link']); + $this->assertNull($items[1]['link']); } } diff --git a/tests/samples/feed.json b/tests/samples/feed.json index 7139d93f..d8a9af7c 100644 --- a/tests/samples/feed.json +++ b/tests/samples/feed.json @@ -16,6 +16,12 @@ "title": "Announcing JSON Feed", "content_html": "
We — Manton Reece and Brent Simmons — have noticed that JSON has become the developers’ choice for APIs, and that developers will often go out of their way to avoid XML. JSON is simpler to read and write, and it’s less prone to bugs.
\n\nSo we developed JSON Feed, a format similar to RSS and Atom but in JSON. It reflects the lessons learned from our years of work reading and publishing feeds.
\n\nSee the spec. It’s at version 1, which may be the only version ever needed. If future versions are needed, version 1 feeds will still be valid feeds.
\n\nWe have a WordPress plugin and, coming soon, a JSON Feed Parser for Swift. As more code is written, by us and others, we’ll update the code page.
\n\nSee Mapping RSS and Atom to JSON Feed for more on the similarities between the formats.
\n\nThis website — the Markdown files and supporting resources — is up on GitHub, and you’re welcome to comment there.
\n\nThis website is also a blog, and you can subscribe to the RSS feed or the JSON feed (if your reader supports it).
\n\nWe worked with a number of people on this over the course of several months. We list them, and thank them, at the bottom of the spec. But — most importantly — Craig Hockenberry spent a little time making it look pretty. :)
", "date_published": "2017-05-17T08:02:12-07:00" + }, + { + "id": "https://jsonfeed.org/2017/05/17/announcing_json_feed", + "title": "Announcing JSON Feed", + "content_html": "We — Manton Reece and Brent Simmons — have noticed that JSON has become the developers’ choice for APIs, and that developers will often go out of their way to avoid XML. JSON is simpler to read and write, and it’s less prone to bugs.
\n\nSo we developed JSON Feed, a format similar to RSS and Atom but in JSON. It reflects the lessons learned from our years of work reading and publishing feeds.
\n\nSee the spec. It’s at version 1, which may be the only version ever needed. If future versions are needed, version 1 feeds will still be valid feeds.
\n\nWe have a WordPress plugin and, coming soon, a JSON Feed Parser for Swift. As more code is written, by us and others, we’ll update the code page.
\n\nSee Mapping RSS and Atom to JSON Feed for more on the similarities between the formats.
\n\nThis website — the Markdown files and supporting resources — is up on GitHub, and you’re welcome to comment there.
\n\nThis website is also a blog, and you can subscribe to the RSS feed or the JSON feed (if your reader supports it).
\n\nWe worked with a number of people on this over the course of several months. We list them, and thank them, at the bottom of the spec. But — most importantly — Craig Hockenberry spent a little time making it look pretty. :)
", + "date_published": "2017-05-17T08:02:12-07:00" } ] } \ No newline at end of file