Skip to content

Commit

Permalink
Add authors to RSS feed
Browse files Browse the repository at this point in the history
Fixes #2607.
  • Loading branch information
nickstenning committed Oct 15, 2015
1 parent 1a52538 commit aa7eb4c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions h/feeds/rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ def _feed_item_from_annotation(annotation, annotation_url):
:rtype: dict
"""
parts = util.split_user(annotation["user"])
if parts is None:
name = annotation["user"]
else:
name = parts[0]
return {
"author": {"name": name},
"title": annotation.title,
"description": annotation.description,
"pubDate": _pubDate_string_from_annotation(annotation),
Expand Down
10 changes: 10 additions & 0 deletions h/feeds/test/rss_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ def _annotation_url():
return mock.Mock(return_value='https://hypothes.is/a/id')


def test_feed_from_annotations_item_author():
"""Feed items should include the annotation's author."""
annotation = factories.Annotation(username="janebloggs")

feed = rss.feed_from_annotations(
[annotation], _annotation_url(), mock.Mock(), '', '', '')

assert feed['entries'][0]['author'] == {'name': 'janebloggs'}


def test_feed_from_annotations_pubDate():
"""It should render the pubDates of annotations correctly."""
annotation = factories.Annotation(
Expand Down
5 changes: 4 additions & 1 deletion h/templates/rss.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ render the feed to RSS XML.
-#}
<?xml version="1.0"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<rss version="2.0"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>{{ feed.title }}</title>
<link>{{ feed.html_url }}</link>
Expand All @@ -22,6 +24,7 @@ render the feed to RSS XML.
<pubDate>{{ item.pubDate }}</pubDate>
<guid isPermaLink="true">{{ item.guid }}</guid>
<link>{{ item.link }}</link>
<dc:creator><![CDATA[{{ item.author.name }}]]></dc:creator>
</item>
{% endfor %}
</channel>
Expand Down

0 comments on commit aa7eb4c

Please sign in to comment.