diff --git a/app.py b/app.py index a767619..81d4ff4 100755 --- a/app.py +++ b/app.py @@ -7,6 +7,7 @@ from flask_flatpages.utils import pygmented_markdown from flask_fontawesome import FontAwesome from datetime import datetime from fotogrid import fotogrid +from feed import generate_feed # directly support jinja within markdown blogposts @@ -67,5 +68,10 @@ def index(): return render_template('index.html', pages=sorted_pages) +@app.route('/rss') +def rss(): + return generate_feed(pages) + + if __name__ == '__main__': app.run(host='0.0.0.0') diff --git a/feed.py b/feed.py new file mode 100644 index 0000000..c813a1f --- /dev/null +++ b/feed.py @@ -0,0 +1,33 @@ +# SPDX-License-Identifier: GPL-3.0 + +from feedgen.feed import FeedGenerator +from datetime import datetime +from flask import make_response + + +def generate_feed(pages): + """ + Provide a simple RSS feed for all articles on the page. + :param pages: The paghes instance from flask-flatpages extension. + :return: flask response that should be return when calling the feed url + """ + fg = FeedGenerator() + fg.title('FdgL- Website Feed') + fg.description( + 'Neuigkeiten von den Freund*innen des geordneten Lärms e.V.') + fg.link(href='https://fdgl.rocks') + + for p in pages: + fe = fg.add_entry() + fe.title(p.meta['title']) + date = datetime.strptime(p.meta["date"] + + ' 00:00:00 +0100', "%d.%m.%Y %H:%M:%S %z") + fe.published(date) + fe.author(name=p.meta['author']) + fe.description(p.meta['description']) + fe.link(href='https://fdgl.rocks/' + p.path + '.html') + + response = make_response(fg.rss_str()) + response.headers.set('Content-Type', 'application/rss+xml') + + return response diff --git a/requirements.txt b/requirements.txt index 98b14d7..42b0807 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ flask flask_flatpages flask_fontawesome +feedgen pytest pytest-cov diff --git a/tests/test_feed.py b/tests/test_feed.py new file mode 100644 index 0000000..a100490 --- /dev/null +++ b/tests/test_feed.py @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0 +import os + + +def test_index(app, client): + print("Checking presence of: rss feed") + res = client.get("/rss") + assert res.status_code == 200