Add the motorino generator #3
6 changed files with 39 additions and 3 deletions
feat: let a page say which manifesto version it translates
commit
0148306a64
|
|
@ -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/<name>.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
|
||||
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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" {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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")})
|
||||
|
|
|
|||
Loading…
Reference in a new issue