From 150af7f86882fe5b8abe0151231af9770f2d01f1 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 1 May 2023 23:18:46 +0200 Subject: [PATCH] Added `short_feed` configuration flag. --- CHANGELOG.md | 5 ++++ README.md | 7 +++++ madblog/config.py | 66 +++++++++++++++++++++++++---------------------- 3 files changed, 47 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a349f5e..2349d96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 0.2.18 + +- Added `short_feed` configuration flag to permanently disable returning the + full content of the articles in the RSS feed. + ## 0.2.16 - Removed `alt` attribute from LaTeX rendered `` tags. It may generate diff --git a/README.md b/README.md index d059221..c70711f 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,8 @@ logo: /path/or/url/here language: en-US # Show/hide the header (default: true) header: true +# Enable/disable the short RSS feed (default: false) +short_feed: false categories: - category1 @@ -133,4 +135,9 @@ $$ 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. + +If you want the short feed (i.e. without the fully rendered article as a +description) to be always returned, then you can specify `short_feed=true` in +your configuration. diff --git a/madblog/config.py b/madblog/config.py index 9476ce1..9928e28 100644 --- a/madblog/config.py +++ b/madblog/config.py @@ -1,57 +1,61 @@ import os +from typing import List import yaml -from dataclasses import dataclass +from dataclasses import dataclass, field @dataclass class Config: - title = 'Blog' - description = '' - link = '/' - home_link = '/' - language = 'en-US' - logo = '/img/icon.png' + title = "Blog" + description = "" + link = "/" + home_link = "/" + language = "en-US" + logo = "/img/icon.png" header = True - content_dir = '.' - categories = None + content_dir = "." + categories: List[str] = field(default_factory=list) + short_feed = False basedir = os.path.abspath(os.path.dirname(__file__)) - templates_dir = os.path.join(basedir, 'templates') - static_dir = os.path.join(basedir, 'static') - default_css_dir = os.path.join(static_dir, 'css') - default_js_dir = os.path.join(static_dir, 'js') - default_fonts_dir = os.path.join(static_dir, 'fonts') - default_img_dir = os.path.join(static_dir, 'img') + templates_dir = os.path.join(basedir, "templates") + static_dir = os.path.join(basedir, "static") + default_css_dir = os.path.join(static_dir, "css") + default_js_dir = os.path.join(static_dir, "js") + default_fonts_dir = os.path.join(static_dir, "fonts") + default_img_dir = os.path.join(static_dir, "img") config = Config() -def init_config(content_dir='.', config_file='config.yaml'): +def init_config(content_dir=".", config_file="config.yaml"): cfg = {} config.content_dir = content_dir if os.path.isfile(config_file): - with open(config_file, 'r') as f: + with open(config_file, "r") as f: cfg = yaml.safe_load(f) - if cfg.get('title'): - config.title = cfg['title'] - if cfg.get('description'): - config.description = cfg['description'] - if cfg.get('link'): - config.link = cfg['link'] - if cfg.get('home_link'): - config.home_link = cfg['home_link'] - if cfg.get('logo') is not None: - config.logo = cfg['logo'] - if cfg.get('language'): - config.language = cfg['language'] - if cfg.get('header') is False: + if cfg.get("title"): + config.title = cfg["title"] + if cfg.get("description"): + config.description = cfg["description"] + if cfg.get("link"): + config.link = cfg["link"] + if cfg.get("home_link"): + config.home_link = cfg["home_link"] + if cfg.get("logo") is not None: + config.logo = cfg["logo"] + if cfg.get("language"): + config.language = cfg["language"] + if cfg.get("header") is False: config.header = False + if cfg.get("short_feed"): + config.short_feed = True - config.categories = cfg.get('categories', []) + config.categories = cfg.get("categories", []) # vim:sw=4:ts=4:et: