Skip to content

Commit

Permalink
RSS feeds: add default email address so that author gets populated
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Dec 23, 2024
1 parent 6dcd355 commit 3e17806
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 10 additions & 0 deletions pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,21 @@ def maybe_set(future):
if format == 'html':
entries = [microformats2.object_to_html(a) for a in activities]
return render_template('feed.html', **TEMPLATE_VARS, **locals())

elif format == 'atom':
body = atom.activities_to_atom(activities, actor=actor, title=title,
request_url=request.url)
return body, {'Content-Type': atom.CONTENT_TYPE}

elif format == 'rss':
# RSS requires email to generate an author element, so fill in blank one
# where necessary
for a in activities:
for field in fields:
if val := as1.get_object(a, field):
if as1.object_type(val) in as1.ACTOR_TYPES:
val.setdefault('email', '_@_._')

body = rss.from_activities(activities, actor=actor, title=title,
feed_url=request.url)
return body, {'Content-Type': rss.CONTENT_TYPE}
Expand Down
7 changes: 4 additions & 3 deletions tests/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,11 @@ def test_feed_rss(self):
self.assert_equals(self.EXPECTED, contents(rss.to_activities(got.text)))

# NOTE's and MENTION's authors; check for two instances
bob = '<author>- (Bob)</author>'
assert got.text.index(bob) != got.text.rindex(bob)
bob = '<author>_@_._ (Bob)</author>'
self.assertIn(bob, got.text)
self.assertNotEqual(got.text.index(bob), got.text.rindex(bob), got.text)
# COMMENT's author
self.assertIn('Dr. Eve', got.text)
self.assertIn('<author>_@_._ (Dr. Eve)</author>', got.text, got.text)

def test_nodeinfo(self):
# just check that it doesn't crash
Expand Down

0 comments on commit 3e17806

Please sign in to comment.