feat: let a page say which manifesto version it translates

This commit is contained in:
tgiachi 2026-11-15 09:57:09 +01:00
commit 0148306a64
5 changed files with 39 additions and 3 deletions

View file

@ -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, <time datetime="2026-11-12">2026-11-12</time>`)
mustContain(t, "en manifesto", readOut(t, out, "manifesto.html"), `Version 1.2, <time datetime="2026-11-14">2026-11-14</time>`)
}
// TestBuildAssetsCopied checks the assets listed in site.json.
func TestBuildAssetsCopied(t *testing.T) {
out, err := runBuild(t, baseFiles())

View file

@ -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",

View file

@ -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" {

View file

@ -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
}

View file

@ -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")})