From 3911e59d9382d37a47f248e899f673508a1c4f9f Mon Sep 17 00:00:00 2001 From: Yax Date: Wed, 24 Sep 2025 13:05:03 +0200 Subject: [PATCH] Fix RSS format --- layout/rss_item.xml | 2 +- makesite.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/layout/rss_item.xml b/layout/rss_item.xml index a70eb61..0d443a4 100644 --- a/layout/rss_item.xml +++ b/layout/rss_item.xml @@ -5,7 +5,7 @@ -{{ content }} +{{ content_rss }}

]]>
diff --git a/makesite.py b/makesite.py index 977ea6e..75210e7 100755 --- a/makesite.py +++ b/makesite.py @@ -101,9 +101,7 @@ def read_headers(text): def rfc_2822_format(date_str): """Convert yyyy-mm-dd date string to RFC 2822 format date string.""" d = datetime.datetime.strptime(date_str, "%Y-%m-%d") - weekday = FRENCH_WEEKDAYS[d.weekday()] - month = FRENCH_MONTHS[d.month - 1] - return f"{weekday}, {d.day:02d} {month} {d.year} {d.strftime('%H:%M:%S')} +0000" + return d.replace(tzinfo=datetime.timezone.utc).strftime('%a, %d %b %Y %H:%M:%S %z') def slugify(value): @@ -119,7 +117,7 @@ def slugify(value): return re.sub("[-\s]+", "-", value) -def read_content(filename): +def read_content(filename, params): """Read content and metadata from file into a dictionary.""" # Read file content. text = fread(filename) @@ -156,6 +154,7 @@ def read_content(filename): content.update( { "content": text, + "content_rss": fix_relative_links(params["site_url"], text), "rfc_2822_date": rfc_2822_format(content["date"]), "summary": summary, } @@ -164,6 +163,10 @@ def read_content(filename): return content +def fix_relative_links(site_url, text): + return text.replace("src=\"/images/20", "src=\"" + site_url + "/images/20") + + def clean_html_tag(text): """Remove HTML tags.""" while True: @@ -207,7 +210,7 @@ def make_posts( for posix_path in Path(src).glob(src_pattern): src_path = str(posix_path) - content = read_content(src_path) + content = read_content(src_path, params) # render text / summary for basic fields content["content"] = render(content["content"], **params) @@ -301,7 +304,7 @@ def make_notes( for posix_path in Path(src).glob(src_pattern): src_path = str(posix_path) - content = read_content(src_path) + content = read_content(src_path, params) # render text / summary for basic fields content["content"] = render(content["content"], **params) @@ -539,7 +542,6 @@ def main(param_file): **params ) - # Create notes. notes = make_notes( "notes", @@ -557,7 +559,8 @@ def main(param_file): archive_title_layout, None, **params - ) + ) + # Test parameter to be set temporarily by unit tests. _test = None