feat: add the RSS icon to the footer and make the news English only

- show the RSS icon in every footer, linked to /news/feed.xml
- write news in English only: the Italian pages list the same posts and link to them
- build a single feed instead of one per language
- send the language switch of the news pages to the home page of the other language
- document the English-only news in the README
This commit is contained in:
squid 2026-11-12 18:45:16 +01:00
commit 8270863f9f

View file

@ -9,7 +9,7 @@ Layout:
content/site.toml values shared by every page (contact, bitcoin address, manifesto version)
content/<lang>/lang.toml the chrome strings of one language
content/<lang>/*.html pages: front matter, then an HTML fragment
content/<lang>/news/*.md news posts: YYYY-MM-DD-slug.md, front matter, then Markdown
content/en/news/*.md news posts, English only: YYYY-MM-DD-slug.md, front matter, then Markdown
A page starts with a front matter block:
---
@ -220,10 +220,10 @@ def load_pages(lang):
return pages
def rss(lang, st, site, lang_pages):
"""RSS 2.0 feed of the news of one language: the latest posts, full text, absolute links."""
def rss(lang, st, site, all_posts):
"""RSS 2.0 feed of the news (English only): the latest posts, full text, absolute links."""
base = site["base_url"]
posts = sorted((p for p in lang_pages if p["kind"] == "post"), key=lambda p: p["date"], reverse=True)[:NEWS_IN_FEED]
posts = all_posts[:NEWS_IN_FEED]
def stamp(d):
return format_datetime(datetime.strptime(d, "%Y-%m-%d").replace(tzinfo=timezone.utc))
@ -271,17 +271,21 @@ def build():
manifesto_toc="\n".join(f'<li><a href="#{sl}">{inline(h)}</a></li>' for sl, h in toc),
manifesto_body=body)
# News are written in English only; every language lists the same posts.
posts_en = sorted((p for p in pages["en"] if p["kind"] == "post"), key=lambda p: p["date"], reverse=True)
def news_lists(lang):
posts = sorted((p for p in pages[lang] if p["kind"] == "post"), key=lambda p: p["date"], reverse=True)
posts = posts_en
mark = "" if lang == "en" else ' hreflang="en" lang="en"'
def li(p):
line = f'<li><time datetime="{p["date"]}">{p["date"]}</time> <a href="{p["path"]}">{html.escape(p["title"], quote=False)}</a>'
line = f'<li><time datetime="{p["date"]}">{p["date"]}</time> <a href="{p["path"]}"{mark}>{html.escape(p["title"], quote=False)}</a>'
if p.get("summary"):
line += ": " + html.escape(p["summary"], quote=False)
return line + "</li>"
items = "\n".join(li(p) for p in posts)
full = f"<ul>\n{items}\n</ul>" if posts else f"<p>\n{strings[lang]['news_empty']}\n</p>"
return full, items, posts[:NEWS_ON_HOME]
return full, items, posts[:NEWS_ON_HOME], mark
news = {lang: news_lists(lang) for lang in LANGS}
@ -299,14 +303,14 @@ def build():
for k in NAV:
ctx["cur_" + k] = ' aria-current="page"' if p["nav"] == k else ""
ctx["alt_url"] = alt["path"] if alt else ""
ctx["alt_switch"] = p.get("switch") or (alt["path"] if alt else strings[other]["url_news"])
ctx["alt_switch"] = p.get("switch") or (alt or by_id[("home", other)])["path"]
ctx["alt_links"] = (f'<link rel="alternate" hreflang="{other}" href="{alt["path"]}">\n'
f'<link rel="alternate" hreflang="{lang}" href="{p["path"]}">') if alt else ""
full, items, latest = news[lang]
full, items, latest, mark = news[lang]
ctx["news_list"] = full
ctx["latest_news"] = render(tpl["latest-news"], dict(ctx, news_items="\n".join(
f'<li><time datetime="{x["date"]}">{x["date"]}</time> <a href="{x["path"]}">{html.escape(x["title"], quote=False)}</a></li>'
f'<li><time datetime="{x["date"]}">{x["date"]}</time> <a href="{x["path"]}"{mark}>{html.escape(x["title"], quote=False)}</a></li>'
for x in latest)), "templates/latest-news.html") if latest else ""
if p["kind"] == "post":
@ -320,13 +324,13 @@ def build():
ctx["lead"] = render(tpl["lead-" + lead], ctx, f"templates/lead-{lead}.html")
ctx["badges"] = render(tpl["badges"], dict(ctx, doc_q=ctx["doc_url"].replace(":", "%3A").replace("/", "%2F")),
"templates/badges.html")
ctx["feed"] = render(tpl["feed"], ctx, "templates/feed.html")
ctx["header"] = render(tpl["header"], ctx, "templates/header.html")
ctx["footer"] = render(tpl["footer"], ctx, "templates/footer.html")
rel = p["path"].lstrip("/")
write(rel + "index.html" if rel == "" or rel.endswith("/") else rel, render(tpl["base"], ctx, "templates/base.html"))
for lang in LANGS:
write(strings[lang]["url_news"].lstrip("/") + "feed.xml", rss(lang, strings[lang], site, pages[lang]))
write("news/feed.xml", rss("en", strings["en"], site, posts_en))
for dest, src in ASSETS.items():
target = os.path.join(OUT, dest)