Fix RSS format

This commit is contained in:
Yax 2025-09-24 13:05:03 +02:00
parent 21b6e3e0f1
commit 3911e59d93
2 changed files with 12 additions and 9 deletions

View file

@ -5,7 +5,7 @@
<description> <description>
<![CDATA[ <![CDATA[
<p> <p>
{{ content }} {{ content_rss }}
</p> </p>
]]> ]]>
</description> </description>

View file

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