From b24919b247b74f2083a7f1f686ee066271141673 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 13 Jan 2022 23:34:19 +0100 Subject: [PATCH] Support for `/rss?short` URL for short descriptions in the feeds --- CHANGELOG.md | 4 ++++ README.md | 3 +++ madblog/routes.py | 5 +++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c1e798..65e9faa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.1.6 + +- Support for `/rss?short` URL for short articles description on the RSS feed. + # 0.1.5 - Support for config.logo = false. diff --git a/README.md b/README.md index c4b9a58..29a01d6 100644 --- a/README.md +++ b/README.md @@ -123,3 +123,6 @@ $$ ## RSS syndacation RSS feeds for the blog are provided under the `/rss` URL. + +By default, the whole HTML-rendered content of an article is returned under `rss.channel.item.description`. +If you only want to include the short description of an article in the feed, use `/rss?short` instead. diff --git a/madblog/routes.py b/madblog/routes.py index cbcbef4..e1f8b1c 100644 --- a/madblog/routes.py +++ b/madblog/routes.py @@ -1,7 +1,7 @@ import os from typing import Optional -from flask import Response, send_from_directory as send_from_directory_, render_template +from flask import request, Response, send_from_directory as send_from_directory_, render_template from .app import app from .config import config @@ -46,6 +46,7 @@ def article_route(article: str): @app.route('/rss', methods=['GET']) def rss_route(): pages = app.get_pages(with_content=True, skip_header=True) + short_description = 'short' in request.args return Response(''' @@ -85,7 +86,7 @@ def rss_route(): title=page.get('title', '[No Title]'), link=page.get('uri', ''), published=page['published'].strftime('%a, %d %b %Y %H:%M:%S GMT') if 'published' in page else '', - content=page.get('content', ''), + content=page.get('description', '') if short_description else page.get('content', ''), image=page.get('image', ''), ) for page in pages