From 0148306a6470136bb5aff79314dbd613adef497f Mon Sep 17 00:00:00 2001 From: tgiachi Date: Sun, 15 Nov 2026 09:57:09 +0100 Subject: [PATCH] feat: let a page say which manifesto version it translates --- README.md | 2 +- internal/build/build_test.go | 11 +++++++++++ internal/build/fixture_test.go | 2 +- internal/build/pages.go | 6 ++++++ internal/content/pages.go | 7 ++++++- internal/content/pages_test.go | 14 ++++++++++++++ 6 files changed, 39 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b329962..af5a634 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ The text of the news. A news file `news/name.md` is published as `/news/YYYY/MM/name.html`, with the year and the month of `Date` as written. Every category gets a page, `/news/category/.html`. -Pages: `Title`, `ID` (the same in every language, it links the translations), `Description`, and optionally `Layout` (`page`, `bare` or `manifesto`), `Note` and `Switch`. +Pages: `Title`, `ID` (the same in every language, it links the translations), `Description`, and optionally `Layout` (`page`, `bare` or `manifesto`), `Note`, `Switch` (`lang=/path, lang=/path`, overrides the language links) and `ManifestoVersion` and `ManifestoDate` (a translation of an older manifesto says which version it translates). ### Placeholders diff --git a/internal/build/build_test.go b/internal/build/build_test.go index 6766732..f72bc87 100644 --- a/internal/build/build_test.go +++ b/internal/build/build_test.go @@ -262,6 +262,17 @@ func TestBuildManifestoLayoutRewritesEmDash(t *testing.T) { } } +// TestBuildManifestoVersionOverride checks that a translation can say which +// version of the manifesto it translates, while the other pages use the current one. +func TestBuildManifestoVersionOverride(t *testing.T) { + out, err := runBuild(t, baseFiles()) + if err != nil { + t.Fatal(err) + } + mustContain(t, "es manifesto", readOut(t, out, "es/manifesto.html"), `Version 1.0, `) + mustContain(t, "en manifesto", readOut(t, out, "manifesto.html"), `Version 1.2, `) +} + // TestBuildAssetsCopied checks the assets listed in site.json. func TestBuildAssetsCopied(t *testing.T) { out, err := runBuild(t, baseFiles()) diff --git a/internal/build/fixture_test.go b/internal/build/fixture_test.go index 37a0f0c..be54cee 100644 --- a/internal/build/fixture_test.go +++ b/internal/build/fixture_test.go @@ -101,7 +101,7 @@ func baseFiles() map[string]string { "content/it/cronologia-manifesto.md": page("history", "Cronologia", "", "Versioni.\n"), "content/it/persone.md": page("people", "Persone", "", "Io.\n"), "content/it/servizi.md": page("services", "Servizi", "", "Scrivi a {{contact_shown}}.\n"), - "content/es/manifesto.md": page("manifesto", "Manifiesto", "Layout: manifesto\nNote: Traduccion de la version 1.0.\n", "## 01 — Antifascistas\n\nTexto.\n"), + "content/es/manifesto.md": page("manifesto", "Manifiesto", "Layout: manifesto\nNote: Traduccion de la version 1.0.\nManifestoVersion: 1.0\nManifestoDate: 2026-11-12\n", "## 01 — Antifascistas\n\nTexto.\n"), "news/gnu-linux-day-2026.md": "Title: GNU/Linux Day 2026\nAuthor: Matteo Bini\nDate: 2026-09-18T17:00:45+0200\nCategories: Linux Day, FLUG\n-\nThe programme is out. See [people](/people.html).\n", "news/shop.md": "Title: A shop\nAuthor: squid\nDate: 2026-11-14T12:00:00+0100\nCategories: FLUG\nDescription: About the shop.\n-\nThere is a shop.\n", diff --git a/internal/build/pages.go b/internal/build/pages.go index 133da41..421e578 100644 --- a/internal/build/pages.go +++ b/internal/build/pages.go @@ -35,6 +35,12 @@ func (b *builder) renderPage(p content.Page) error { d.lead = "home" } ctx := b.documentContext(d) + if p.ManifestoVersion != "" { + ctx["manifesto_version"] = render.Escape(p.ManifestoVersion) + } + if p.ManifestoDate != "" { + ctx["manifesto_date"] = render.Escape(p.ManifestoDate) + } source := p.Body if p.Layout == "manifesto" { diff --git a/internal/content/pages.go b/internal/content/pages.go index 35cfba1..bc7ecea 100644 --- a/internal/content/pages.go +++ b/internal/content/pages.go @@ -28,6 +28,10 @@ type Page struct { Layout string // Switch overrides the address of the language links, by language code. Switch map[string]string + // ManifestoVersion and ManifestoDate, when set, replace the current + // manifesto version and date on this page: a translation of an older + // version says which one it translates. + ManifestoVersion, ManifestoDate string // Source is the file the page was read from, relative to the site. Source string // Body is the Markdown after the header. @@ -35,7 +39,7 @@ type Page struct { } // pageKeys are the keys a page header may have. -var pageKeys = []string{"Title", "ID", "Description", "Layout", "Note", "Switch"} +var pageKeys = []string{"Title", "ID", "Description", "Layout", "Note", "Switch", "ManifestoVersion", "ManifestoDate"} // layouts are the values of the Layout key; the first is the default. var layouts = []string{"page", "bare", "manifesto"} @@ -147,6 +151,7 @@ func loadPage(file, source, defaultLang, lang, rel string) (Page, error) { Lang: lang, ID: h.Get("ID"), Path: PagePath(defaultLang, lang, rel), Title: h.Get("Title"), Description: h.Get("Description"), Note: h.Get("Note"), Layout: layout, Switch: switches, Source: source, Body: body, + ManifestoVersion: h.Get("ManifestoVersion"), ManifestoDate: h.Get("ManifestoDate"), }, nil } diff --git a/internal/content/pages_test.go b/internal/content/pages_test.go index 3c9a4ec..8a9554f 100644 --- a/internal/content/pages_test.go +++ b/internal/content/pages_test.go @@ -69,6 +69,20 @@ func TestLoadPages(t *testing.T) { } } +// TestLoadPagesManifestoVersion checks the keys of a translation of an older manifesto. +func TestLoadPagesManifestoVersion(t *testing.T) { + dir := writeFiles(t, map[string]string{ + "content/es/m.md": "Title: M\nID: manifesto\nDescription: d\nLayout: manifesto\nManifestoVersion: 1.0\nManifestoDate: 2026-11-12\n-\nB\n", + }) + pages, err := LoadPages(dir, []string{"es"}) + if err != nil { + t.Fatal(err) + } + if len(pages) != 1 || pages[0].ManifestoVersion != "1.0" || pages[0].ManifestoDate != "2026-11-12" { + t.Errorf("pages = %+v, want ManifestoVersion 1.0 and ManifestoDate 2026-11-12", pages) + } +} + // TestLoadPagesRejectsEmDash checks that an em dash in a page is an error. func TestLoadPagesRejectsEmDash(t *testing.T) { dir := writeFiles(t, map[string]string{"content/en/x.md": pageFile("", "Words — more words.\n")})