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
8 changed files with 30 additions and 36 deletions

View file

@ -10,7 +10,7 @@ Sources of the kmalloc.org website: plain static HTML, no JavaScript, valid HTML
- `content/site.toml` holds the values shared by every page: contact address, Bitcoin address, manifesto version.
- `content/<lang>/lang.toml` holds the chrome strings of one language (`en`, `it`).
- `content/<lang>/*.html` are the pages: a front matter block, then an HTML fragment.
- `content/<lang>/news/` holds the news posts.
- `content/en/news/` holds the news posts. News are written in English only.
- `MANIFESTO.en.md` and `MANIFESTO.it.md` are the manifesto texts, version 1.0.
- `fonts/terminess.woff2` is Terminess (Terminus), SIL Open Font License, subset to Latin.
- `badges/` holds the official W3C badges, served from our own site.
@ -33,7 +33,7 @@ A page starts with a front matter block, then the HTML fragment:
## News
A post is a Markdown file named `YYYY-MM-DD-slug.md` in `content/<lang>/news/`:
A post is a Markdown file named `YYYY-MM-DD-slug.md` in `content/en/news/`:
---
title: Hello
@ -43,7 +43,7 @@ A post is a Markdown file named `YYYY-MM-DD-slug.md` in `content/<lang>/news/`:
## A heading
The post is published at `/news/slug.html` (`/it/news/slug.html` for Italian). A post with the same file name in both languages is linked as a translation. The news index, the latest three posts on the home page and an RSS 2.0 feed (`/news/feed.xml`, `/it/news/feed.xml`, the latest 20 posts with full text) are built from the files. Every page links its feed in the head. No em dashes: the build refuses them.
The post is published at `/news/slug.html`. News are English only: the Italian pages list the same posts and link to them. The news index, the latest three posts on the home pages and an RSS 2.0 feed (`/news/feed.xml`, the latest 20 posts with full text) are built from the files. Every page links the feed in the head and shows the RSS icon in the footer. No em dashes: the build refuses them.
## Publishing

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)

View file

@ -6,7 +6,7 @@ home_link = "/it/"
url_manifesto = "/it/manifesto.html"
url_people = "/it/persone.html"
url_services = "/it/servizi.html"
url_news = "/it/news/"
url_news = "/news/"
nav_manifesto = "Manifesto"
nav_people = "Persone"
nav_services = "Servizi"
@ -16,6 +16,6 @@ nojs = "Questa pagina non usa JavaScript, cookie né tracker."
back = "home"
version = "Versione"
toc = "Indice"
news_p = "Novità da kmalloc.org."
news_p = "Novità da kmalloc.org, scritte in inglese."
news_all = "tutte le news"
news_empty = "Ancora nessuna news."

View file

@ -1,18 +0,0 @@
---
id: news
path: /it/news/
nav: news
title: kmalloc.org: News
description: Novità da kmalloc.org.
---
<h1>News</h1>
<p>
Novità da kmalloc.org.
</p>
{{news_list}}
<p>
<a href="{{url_news}}feed.xml">feed RSS</a>
</p>

View file

@ -106,6 +106,10 @@ code {
height: auto;
}
svg {
vertical-align: middle;
}
@media print {
:root {
--bg: #fff;
@ -115,7 +119,7 @@ code {
--link: #000;
}
header, .badges {
header, .badges, .feed {
display: none;
}

3
templates/feed.html Normal file
View file

@ -0,0 +1,3 @@
<p class="feed">
<a href="{{url_news}}feed.xml" title="RSS"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="28" height="28" role="img" aria-label="RSS"><rect width="32" height="32" rx="6" fill="#D9480F"/><circle cx="9" cy="23" r="3" fill="#fff"/><path d="M6 14a12 12 0 0 1 12 12M6 6a20 20 0 0 1 20 20" fill="none" stroke="#fff" stroke-width="3"/></svg></a>
</p>

View file

@ -3,5 +3,6 @@
<p>
{{nojs}}
</p>
{{feed}}
{{badges}}
</footer>