kmalloc.org/build.py
squid a93adca996 feat: add kmalloc.org website generator, manifesto and logo sources
Static site generator (plain HTML, no JavaScript) with the English and Italian
manifesto 1.0, the Terminess subset font, the W3C badges and the shrike logo set.
2026-11-12 17:18:33 +01:00

548 lines
21 KiB
Python

#!/usr/bin/env python3
"""Build the kmalloc.org static site (plain HTML, no JavaScript) from the manifesto sources.
Usage: build.py <output-dir> (writes index.html, manifesto.html, it/index.html, it/manifesto.html)"""
import html, os, re, sys
HERE = os.path.dirname(os.path.abspath(__file__))
OUT = sys.argv[1]
CSS = """@font-face {
font-family: "Terminess";
src: url("/fonts/terminess.woff2") format("woff2");
font-display: swap;
}
:root {
--bg: #F9F7ED;
--surface: #F1EDE0;
--border: #D9D3C2;
--text: #111417;
--muted: #5b564a;
--accent: #D9480F;
--link: #b13a0b;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #111417;
--surface: #1b1f23;
--border: #5b564a;
--text: #F9F7ED;
--muted: #8a8473;
--link: #f0683a;
}
}
body {
margin: 0 auto;
max-width: 40em;
padding: 1em;
background-color: var(--bg);
color: var(--text);
font-family: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
line-height: 1.6;
}
h1, h2, h3 {
margin: 2em 0 .5em;
font-family: "Terminess", ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
font-weight: normal;
line-height: 1.25;
}
a {
color: var(--link);
}
a:visited {
color: var(--muted);
}
a:hover, header a[aria-current] {
color: var(--text);
}
a:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
header {
border-bottom: 1px solid var(--border);
line-height: 2;
}
header a[aria-current] {
text-decoration: none;
}
footer {
margin-top: 3em;
border-top: 1px solid var(--border);
color: var(--muted);
font-size: .875em;
}
blockquote {
margin: 1.5em 0;
padding: 0 1em;
border-left: 4px solid var(--accent);
}
code {
background-color: var(--surface);
color: var(--text);
font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
font-size: .9375em;
overflow-wrap: anywhere;
}
.hero {
margin: .5em 0 .4em;
font-size: 3em;
line-height: 1.1;
}
@media (max-width: 30em) {
.hero {
font-size: 2em;
}
}
.logo {
width: 7em;
height: auto;
}
@media print {
:root {
--bg: #fff;
--border: #000;
--text: #000;
--muted: #000;
--link: #000;
}
header, .badges {
display: none;
}
a[href^="http"]::after {
content: " <" attr(href) ">";
}
h1, h2, h3 {
page-break-after: avoid;
}
}"""
SERVICES = [
# (url, name, en, it)
("https://git.kmalloc.org/", "git", "code hosting (Forgejo)", "repository di codice (Forgejo)"),
("https://social.kmalloc.org/@squid", "social", "Mastodon, accounts on approval", "Mastodon, account su approvazione"),
("https://lists.kmalloc.org/", "lists", "mailing lists (Mailman 3)", "liste di posta (Mailman 3)"),
("https://chat.kmalloc.org/", "chat", "XMPP, web client", "XMPP, client web"),
("https://element.kmalloc.org/", "matrix", "Matrix, Element web client", "Matrix, client web Element"),
("https://meet.kmalloc.org/", "meet", "video conferences (Jitsi Meet)", "videoconferenze (Jitsi Meet)"),
("https://webmail.kmalloc.org/", "webmail", "email on our own server", "posta sul nostro server"),
]
MANIFESTO_VERSION = "1.0"
CONTACT = "squid@kmalloc.org"
CONTACT_SHOWN = CONTACT.replace("@", " (at) ") # shown instead of a mailto link, against address harvesters
BTC = "bc1qsj5qadrzlqmfwcru4fwuqvftg833te5f9mja2c"
SERVICE_PAGES = [
# id, name, url, EN text, IT text
("mail", "Email", "https://webmail.kmalloc.org/",
"An address @kmalloc.org on our own mail server, with webmail and support for any standard mail client. IMAP: mail.kmalloc.org, port 993 (TLS). SMTP submission: mail.kmalloc.org, port 465 (TLS). Outgoing mail is signed with DKIM and protected by SPF and DMARC.",
"Un indirizzo @kmalloc.org sul nostro server di posta, con webmail e supporto per qualsiasi client di posta standard. IMAP: mail.kmalloc.org, porta 993 (TLS). Invio SMTP: mail.kmalloc.org, porta 465 (TLS). La posta in uscita è firmata con DKIM e protetta da SPF e DMARC."),
("lists", "Mailing lists", "https://lists.kmalloc.org/",
"Mailing lists with web archives (Mailman 3). Lists live under @lists.kmalloc.org. If you need one, ask.",
"Liste di posta con archivi consultabili sul web (Mailman 3). Le liste stanno sotto @lists.kmalloc.org. Se te ne serve una, chiedila."),
("git", "Git", "https://git.kmalloc.org/",
"Code hosting with Forgejo: repositories, issues and pull requests. Git over SSH uses port 2222. Reading public repositories needs no account.",
"Hosting di codice con Forgejo: repository, issue e pull request. Git via SSH usa la porta 2222. Per leggere i repository pubblici non serve un account."),
("social", "Mastodon", "https://social.kmalloc.org/",
"A Mastodon server. Your address is @name@social.kmalloc.org. You can ask for an account on the site itself: requests are approved by hand.",
"Un server Mastodon. Il tuo indirizzo è @nome@social.kmalloc.org. L'account si può chiedere direttamente sul sito: le richieste si approvano a mano."),
("chat", "XMPP chat", "https://chat.kmalloc.org/",
"Instant messaging with XMPP: address name@kmalloc.org, group rooms on conference.kmalloc.org, file sharing, and audio and video calls through our own TURN server. Use the web client or any XMPP app (server kmalloc.org, port 5222).",
"Messaggistica con XMPP: indirizzo nome@kmalloc.org, stanze di gruppo su conference.kmalloc.org, condivisione di file e chiamate audio e video con un nostro server TURN. Usa il client web o qualsiasi app XMPP (server kmalloc.org, porta 5222)."),
("matrix", "Matrix", "https://element.kmalloc.org/",
"A Matrix homeserver: address @name:kmalloc.org. Use the Element web client or any Matrix app with homeserver matrix.kmalloc.org.",
"Un homeserver Matrix: indirizzo @nome:kmalloc.org. Usa il client web Element o qualsiasi app Matrix con homeserver matrix.kmalloc.org."),
("meet", "Video conferences", "https://meet.kmalloc.org/",
"Video conferences with Jitsi Meet. Anyone with the link can join a room; creating a room needs an account.",
"Videoconferenze con Jitsi Meet. Chiunque abbia il link può entrare in una stanza; per crearne una serve un account."),
]
PEOPLE = [
# handle, display name (empty = handle only), bio EN, bio IT, links (label, url)
("squid", "",
"I'm squid. I run kmalloc.org, write code and maintain the services on this site. I have been into computers since I was ten, when I got an IBM PS/2 with a 486DX and played Gorilla, a QBasic game: ever since, I have been taking things apart to understand how they work. Outside of work: retro computing, science fiction and extreme metal.",
"Sono squid. Gestisco kmalloc.org, scrivo codice e mantengo i servizi di questo sito. Mi appassionano i computer da quando, a dieci anni, ebbi un IBM PS/2 con un 486DX e giocai a Gorilla, un gioco in QBasic: da allora smonto le cose per capire come funzionano. Fuori dal lavoro: retrocomputing, fantascienza ed extreme metal.",
[("Mastodon", "https://social.kmalloc.org/@squid"), ("git", "https://git.kmalloc.org/squid")]),
]
T = {
"en": dict(
lang="en", other="it", other_name="Italiano", other_home="/it/", other_man="/it/manifesto.html", home="/", home_link="/?lang=en", man="/manifesto.html", ppl="/people.html", other_ppl="/it/persone.html", svc="/services.html", other_svc="/it/servizi.html",
title="kmalloc.org: Technology. Freedom. Dissent.",
desc="kmalloc.org is an independent hacker space that promotes free software, privacy and an open Internet.",
tagline="Technology. Freedom. Dissent.",
identity="kmalloc.org is a hacker, antifascist, ethical space.",
intro="kmalloc.org is an independent hacker space that promotes free software, privacy and an open Internet, defending freedom of thought, the dignity of work and the right of people not to be controlled, exploited or subordinated to arbitrary powers.",
manifesto_h="Manifesto", manifesto_p="What we believe, in twelve points and a few commitments:", manifesto_a="read the manifesto",
services_h="Services", services_p="Run on our own server, with free software. Accounts are created by hand.",
nojs="This page uses no JavaScript, cookies or trackers.", back="home", toc="Contents",
man_title="kmalloc.org: Manifesto", man_desc="The kmalloc.org manifesto: free software, privacy, an open Internet, dignity at work.",
people_h="People", people_p="Who is behind kmalloc.org.", people_a="meet the people", people_title="kmalloc.org: People", people_desc="The people behind kmalloc.org.", links="Links", sections="Sections", version="Version",
svc_title="kmalloc.org: Services", svc_desc="The services run by kmalloc.org: email, git, Mastodon, XMPP, Matrix, mailing lists and video conferences. Free, by request.",
svc_intro="These services run on our own server, with free software, for people who want an alternative to the big platforms.",
at_hint="replace (at) with @", free_h="Get an account", free_p1="The services are free of charge. To ask for an account, write to", free_p2="telling us which services you want and the username you would like.",
donate_h="Support kmalloc.org", donate_p="Donations are welcome and help keep the server running. Bitcoin address:", donate_a="send a donation",
terms_h="Good to know", terms_p="Everything is run by one person on one server, with nightly encrypted backups and no guarantees of availability. Be respectful: the manifesto explains what we stand for.",
open_a="open",
),
"it": dict(
lang="it", other="en", other_name="English", other_home="/", other_man="/manifesto.html", home="/it/", home_link="/it/", man="/it/manifesto.html", ppl="/it/persone.html", other_ppl="/people.html", svc="/it/servizi.html", other_svc="/services.html",
title="kmalloc.org: Technology. Freedom. Dissent.",
desc="kmalloc.org è uno spazio hacker indipendente che promuove il software libero, la privacy e un Internet aperto.",
tagline="Technology. Freedom. Dissent.",
identity="kmalloc.org è uno spazio hacker, antifascista, etico.",
intro="kmalloc.org è uno spazio hacker indipendente che promuove il software libero, la privacy e un Internet aperto, difendendo la libertà di pensiero, la dignità del lavoro e il diritto delle persone a non essere controllate, sfruttate o subordinate a poteri arbitrari.",
manifesto_h="Manifesto", manifesto_p="Quello in cui crediamo, in dodici punti e qualche impegno:", manifesto_a="leggi il manifesto",
services_h="Servizi", services_p="Girano sul nostro server, con software libero. Gli account si creano a mano.",
nojs="Questa pagina non usa JavaScript, cookie né tracker.", back="home", toc="Indice",
man_title="kmalloc.org: Manifesto", man_desc="Il manifesto di kmalloc.org: software libero, privacy, un Internet aperto, dignità nel lavoro.",
people_h="Persone", people_p="Chi c'è dietro kmalloc.org.", people_a="conosci le persone", people_title="kmalloc.org: Persone", people_desc="Le persone dietro kmalloc.org.", links="Link", sections="Sezioni", version="Versione",
svc_title="kmalloc.org: Servizi", svc_desc="I servizi di kmalloc.org: posta, git, Mastodon, XMPP, Matrix, liste di posta e videoconferenze. Gratuiti, su richiesta.",
svc_intro="Questi servizi girano sul nostro server, con software libero, per chi vuole un'alternativa alle grandi piattaforme.",
at_hint="sostituisci (at) con @", free_h="Richiedi un account", free_p1="I servizi sono gratuiti. Per chiedere un account scrivi a", free_p2="indicando quali servizi vuoi e il nome utente che preferisci.",
donate_h="Sostieni kmalloc.org", donate_p="Le donazioni sono benvenute e aiutano a tenere acceso il server. Indirizzo Bitcoin:", donate_a="fai una donazione",
terms_h="Da sapere", terms_p="Tutto è gestito da una persona su un solo server, con backup notturni cifrati e nessuna garanzia di disponibilità. Siate rispettosi: il manifesto spiega in cosa crediamo.",
open_a="apri",
),
}
def badges(url):
q = url.replace(":", "%3A").replace("/", "%2F")
return f"""<p class="badges">
<a href="https://validator.w3.org/nu/?doc={q}"><img src="/badges/w3c-html5.png" alt="Valid HTML5" width="63" height="64"></a>
<a href="https://jigsaw.w3.org/css-validator/validator?uri={q}&amp;profile=css3svg"><img src="/badges/w3c-css.png" alt="Valid CSS" width="88" height="31"></a>
</p>"""
def nav(t, other_url, current):
"""Site menu at the top of every page: sections plus the language switch."""
cur = lambda k: ' aria-current="page"' if k == current else ""
if current == "home" and t["lang"] == "it":
other_url = "/?lang=en"
return f"""<header>
<nav aria-label="{t['sections']}">
<p>
<a href="{t['home_link']}"{cur('home')}>kmalloc.org</a>
&middot;
<a href="{t['man']}"{cur('man')}>{t['manifesto_h']}</a>
&middot;
<a href="{t['ppl']}"{cur('ppl')}>{t['people_h']}</a>
&middot;
<a href="{t['svc']}"{cur('svc')}>{t['services_h']}</a>
&middot;
<a href="{other_url}" hreflang="{t['other']}" lang="{t['other']}">{t['other_name']}</a>
</p>
</nav>
</header>"""
def page(t, title, desc, body, alt_url, here_url):
other = T[t["other"]]
return f"""<!doctype html>
<html lang="{t['lang']}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="color-scheme" content="light dark">
<meta name="robots" content="noindex, nofollow, noarchive">
<meta name="description" content="{html.escape(desc, quote=True)}">
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
<link rel="icon" href="/favicon.ico" sizes="any">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="alternate" hreflang="{other['lang']}" href="{alt_url}">
<link rel="alternate" hreflang="{t['lang']}" href="{here_url}">
<style>
{CSS}
</style>
<title>{html.escape(title)}</title>
</head>
<body>
{body}
</body>
</html>
"""
def home(t):
li = "\n".join(
f'<li><a href="{u}">{n}</a>: {html.escape(t["lang"] == "en" and en or it)}</li>'
for (u, n, en, it) in SERVICES)
body = f"""{nav(t, t['other_home'], 'home')}
<p>
<img class="logo" src="/logo-auto.svg" alt="kmalloc" width="112">
</p>
<h1 class="hero">Technology.<br>Freedom.<br>Dissent.</h1>
<p>
<strong>{html.escape(t['identity'])}</strong>
</p>
<p>
{html.escape(t['intro'])}
</p>
<p>
<strong>Allocate freedom.</strong>
</p>
<h2 id="manifesto">{t['manifesto_h']}</h2>
<p>
{t['manifesto_p']}
<a href="{t['man']}">{t['manifesto_a']}</a> ({t['version'].lower()} {MANIFESTO_VERSION}).
</p>
<h2 id="people">{t['people_h']}</h2>
<p>
{t['people_p'].rstrip('.')}:
<a href="{t['ppl']}">{t['people_a']}</a>.
</p>
<h2 id="services">{t['services_h']}</h2>
<p>
{t['services_p']}
<a href="{t['svc']}">{t['free_h'].lower()}</a>.
</p>
<ul>
{li}
</ul>
<footer>
<p>
<em>Free Your Mind&hellip; and Your Ass Will Follow.</em>
</p>
<p>
{t['nojs']}
</p>
{badges("https://kmalloc.org" + t["home"])}
</footer>"""
return page(t, t["title"], t["desc"], body, t["other_home"], t["home"])
def no_em_dash(md):
"""Replace every em dash: headings 'NN — Title' -> 'NN. Title', 'Word — Title' -> 'Word: Title',
attribution lines lose the dash, parenthetical dashes become commas."""
md = re.sub(r"^(#+ )(\d\d) — ", r"\1\2. ", md, flags=re.M)
md = re.sub(r"^(#+ [^\d\n][^—\n]*?) — ", r"\1: ", md, flags=re.M)
md = re.sub(r"^> — ", "> ", md, flags=re.M)
for a, b in ((" — where technically feasible — ", ", where technically feasible, "),
(" — dove tecnicamente possibile — ", ", dove tecnicamente possibile, "),
(" — and continues", ", and continues"),
(" — e continua", ", e continua")):
md = md.replace(a, b)
md = md.replace("kmalloc.org — ", "kmalloc.org: ")
assert "—" not in md, [l for l in md.splitlines() if "—" in l]
return md
def inline(s):
s = html.escape(s, quote=False)
s = re.sub(r"\*\*(.+?)\*\*", r"<strong>\1</strong>", s)
s = re.sub(r"(?<!\*)\*(?!\s)(.+?)(?<!\s)\*(?!\*)", r"<em>\1</em>", s)
return s
def slug(heading):
m = re.match(r"(\d\d)\b", heading)
if m: return m.group(1)
h = heading.lower()
if h.startswith(("preamble", "preambolo")): return "preamble"
if h.startswith(("our commitments", "i nostri impegni")): return "commitments"
if h.startswith(("epilogue", "epilogo")): return "epilogue"
return re.sub(r"[^a-z0-9]+", "-", h).strip("-")
def md_to_html(md):
lines = md.splitlines()
out, toc = [], []
para, quote, items = [], [], []
def flush():
nonlocal para, quote, items
if para:
out.append("<p>\n" + "\n".join(para) + "\n</p>\n"); para = []
if quote:
out.append("<blockquote>\n<p>\n" + "\n".join(quote) + "\n</p>\n</blockquote>\n"); quote = []
if items:
out.append("<ul>\n" + "\n".join(f"<li>{i}</li>" for i in items) + "\n</ul>\n"); items = []
title = ""
for raw in lines:
line = raw.rstrip("\n")
br = line.endswith(" ")
s = line.strip()
if not s:
flush(); continue
if s.startswith("# "):
flush(); title = s[2:]; continue
if s.startswith("## "):
flush(); h = s[3:]; sl = slug(h); toc.append((sl, h))
out.append(f'<h2 id="{sl}">{inline(h)}</h2>\n'); continue
if s.startswith("> "):
if para or items: flush()
quote.append(inline(s[2:]) + ("<br>" if br else "")); continue
if s.startswith("- "):
if para or quote: flush()
items.append(inline(s[2:])); continue
if quote or items: flush()
para.append(inline(s))
flush()
return title, toc, "".join(out)
def manifesto(t):
src = open(os.path.join(HERE, f"MANIFESTO.{t['lang']}.md"), encoding="utf-8").read()
title, toc, body_html = md_to_html(no_em_dash(src))
toc_html = "\n".join(f'<li><a href="#{sl}">{inline(h)}</a></li>' for sl, h in toc)
body = f"""{nav(t, t['other_man'], 'man')}
<h1>{html.escape(title)}</h1>
<p>
<strong>{t['version']} {MANIFESTO_VERSION}</strong>
</p>
<h2>{t['toc']}</h2>
<ul>
{toc_html}
</ul>
{body_html}
<footer>
<p>
<a href="{t['home_link']}">{t['back']}</a>
</p>
<p>
{t['nojs']}
</p>
{badges("https://kmalloc.org" + t["man"])}
</footer>"""
return page(t, t["man_title"], t["man_desc"], body, t["other_man"], t["man"])
def people_page(t):
cards = []
for handle, name, en, it, links in PEOPLE:
bio = en if t["lang"] == "en" else it
title = html.escape(name) + " (" + html.escape(handle) + ")" if name else html.escape(handle)
li = "\n".join(f'<li><a href="{u}">{html.escape(l)}</a></li>' for l, u in links)
cards.append(f"""<h2 id="{html.escape(handle)}">{title}</h2>
<p>
{html.escape(bio)}
</p>
<ul>
{li}
</ul>
""")
body = f"""{nav(t, t['other_ppl'], 'ppl')}
<h1>{t['people_h']}</h1>
<p>
{t['people_p']}
</p>
{"".join(cards)}
<footer>
<p>
<a href="{t['home_link']}">{t['back']}</a>
</p>
<p>
{t['nojs']}
</p>
{badges("https://kmalloc.org" + t["ppl"])}
</footer>"""
return page(t, t["people_title"], t["people_desc"], body, t["other_ppl"], t["ppl"])
def services_page(t):
en = t["lang"] == "en"
secs = []
for sid, name, url, d_en, d_it in SERVICE_PAGES:
secs.append(f"""<h2 id="{sid}">{html.escape(name)}</h2>
<p>
{html.escape(d_en if en else d_it)}
<a href="{url}">{t['open_a']}</a>.
</p>
""")
body = f"""{nav(t, t['other_svc'], 'svc')}
<h1>{t['services_h']}</h1>
<p>
{html.escape(t['svc_intro'])}
</p>
<h2 id="account">{t['free_h']}</h2>
<p>
{t['free_p1']}
<strong>{CONTACT_SHOWN}</strong>
({t['at_hint']}),
{t['free_p2']}
</p>
{"".join(secs)}
<h2 id="donate">{t['donate_h']}</h2>
<p>
{t['donate_p']}
<a href="bitcoin:{BTC}"><code>{BTC}</code></a>
</p>
<h2 id="terms">{t['terms_h']}</h2>
<p>
{html.escape(t['terms_p'])}
</p>
<footer>
<p>
<a href="{t['home_link']}">{t['back']}</a>
</p>
<p>
{t['nojs']}
</p>
{badges("https://kmalloc.org" + t["svc"])}
</footer>"""
return page(t, t["svc_title"], t["svc_desc"], body, t["other_svc"], t["svc"])
os.makedirs(os.path.join(OUT, "it"), exist_ok=True)
os.makedirs(os.path.join(OUT, "fonts"), exist_ok=True)
import shutil
os.makedirs(os.path.join(OUT, "badges"), exist_ok=True)
for b in ("w3c-html5.png", "w3c-css.png"):
shutil.copy(os.path.join(HERE, "badges", b), os.path.join(OUT, "badges", b))
shutil.copy(os.path.join(HERE, "fonts", "terminess.woff2"), os.path.join(OUT, "fonts", "terminess.woff2"))
for lang, prefix in (("en", ""), ("it", "it/")):
t = T[lang]
open(os.path.join(OUT, prefix + "index.html"), "w", encoding="utf-8").write(home(t))
open(os.path.join(OUT, prefix + "manifesto.html"), "w", encoding="utf-8").write(manifesto(t))
open(os.path.join(OUT, prefix + ("people.html" if lang == "en" else "persone.html")), "w", encoding="utf-8").write(people_page(t))
open(os.path.join(OUT, prefix + ("services.html" if lang == "en" else "servizi.html")), "w", encoding="utf-8").write(services_page(t))
open(os.path.join(OUT, "robots.txt"), "w", encoding="utf-8").write("User-agent: *\nDisallow: /\n")
print("built:", sorted(os.listdir(OUT)), sorted(os.listdir(os.path.join(OUT, "it"))))