From dbf4712af45720af80dca27e72bce164fbe47442 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Thu, 17 Nov 2022 07:58:08 -0800 Subject: [PATCH] switch HTML feed to template for #265 --- pages.py | 21 +++++++++------------ templates/feed.html | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 templates/feed.html diff --git a/pages.py b/pages.py index a4ffb2e..f93254d 100644 --- a/pages.py +++ b/pages.py @@ -113,7 +113,7 @@ def following(domain): def feed(domain): format = request.args.get('format', 'html') if format not in ('html', 'atom', 'rss'): - error(f'format {format} not supported; expected html, atom, or rss') + error(f'format {format} not supported; expected html, atom, or rss') as2_activities, _, _ = Activity.query( Activity.domain == domain, Activity.direction == 'in' @@ -130,21 +130,18 @@ def feed(domain): 'url': f'https://{domain}', } title = f'Bridgy Fed feed for {domain}' - extra = '' - if not as1_activities: - extra += '\n

Nothing yet. Follow more people, check back soon!

' if format == 'html': - return microformats2.activities_to_html(as1_activities, extra=extra, - body_class='h-feed') + entries = [microformats2.object_to_html(a) for a in as1_activities] + return render_template('feed.html', **locals()) elif format == 'atom': - body = atom.activities_to_atom(as1_activities, actor=actor, title=title, - request_url=request.url) - return body, {'Content-Type': atom.CONTENT_TYPE} + body = atom.activities_to_atom(as1_activities, actor=actor, title=title, + request_url=request.url) + return body, {'Content-Type': atom.CONTENT_TYPE} elif format == 'rss': - body = rss.from_activities(as1_activities, actor=actor, title=title, - feed_url=request.url) - return body, {'Content-Type': rss.CONTENT_TYPE} + body = rss.from_activities(as1_activities, actor=actor, title=title, + feed_url=request.url) + return body, {'Content-Type': rss.CONTENT_TYPE} @app.get('/responses') # deprecated diff --git a/templates/feed.html b/templates/feed.html new file mode 100644 index 0000000..3b09182 --- /dev/null +++ b/templates/feed.html @@ -0,0 +1,21 @@ +{% extends "base.html" %} + +{% block title %}{{ domain }}'s feed - Bridgy Fed{% endblock %} + +{% block content %} + +

+ 🌐 {{ domain }}'s feed +

+
+ + +
+{% for e in entries %} + {{ e|safe }} +{% else %} + Nothing yet. Follow more people, check back soon! +{% endfor %} +
+ +{% endblock %}