diff --git a/PLAN.md b/PLAN.md
index 05810c4..cb9fd40 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -1375,10 +1375,48 @@ shared theme for new sites (deferred in Phase 5).
item 1: the second app's keys, choosing the page, and posting as the
page or the profile per draft. Built against LinkedIn's documented API;
used for real once LinkedIn approves the app.
-5. **New sites from a shared theme.** A Hugo theme of sections common to
- federated-website and webcoredesktop, and creating a new site from it:
- a new Gitea repository, a first set of pages built by Part 3 of Phase 5,
- and a preview. Planned in detail when it starts.
+5. **New sites from a shared theme.** Decided with the user (2026-11-22):
+ the theme is *copied into* each new site (`themes/supermarket/`), not a
+ submodule, so each site stands alone; *the user creates* the empty
+ Gitea repository (the `write:repository` token stays enough); the theme
+ has *federated-website's look*, with each site's colors, fonts and logo
+ as settings. In three steps, a commit after each:
+ 1. **The theme**, embedded in Supermarket: base layouts, header and
+ footer, the section types both sites share (hero, text, features,
+ cards, steps, checklist, split, stats, table, faq, callout,
+ final-cta) plus federated-website's lead `form`, the stylesheet with
+ brand variables, and a README documenting each type and its fields
+ (which the catalogue reader and the page builder then use).
+ 2. **A new site**: Sites → New site takes the empty repository, the
+ site's address, name and brand (colors, font, logo); the first
+ commit (the theme, `hugo.toml`, a starter home page) goes straight to
+ the empty repository's `main`, the one exception to "always a pull
+ request", since there's nothing published yet; then the site is added
+ to the profile, read, and previewed, and its first pages (home,
+ about, a product page, contact with a lead form) are built with the
+ page builder as pull requests.
+ 3. **Theme updates**: the theme carries a version; a site whose copy is
+ older gets a pull request copying the new one in.
+
+ **Step 1 built (2026-11-22; no schema change).** `internal/theme` embeds
+ the theme (version 1): federated-website's base layout (its reveal and
+ sticky-header script; not its agent view or pricing script), a generic
+ head (title, description, canonical and Open Graph tags, favicon, the
+ brand font from Google Fonts, Plausible when `[params.plausible]` is
+ set), a header and footer driven by `hugo.toml` (logo or the site's
+ name, `main` menu with dropdowns, `[params.header] ctas`, footer
+ groups, social and legal menus, copyright), the 13 shared section types
+ (the hero without Federated's layer panel; the form posting through
+ `supermarket-leads.js`, now the theme's file and the one Part 3 uses),
+ pages that render sections then any Markdown body, a 404, and the
+ stylesheet with every brand color as a variable (the fixed violet,
+ lime and navy tints turned into `color-mix` of the brand variables).
+ `[params.brand]` sets dark, dark2, primary, accent (and hovers), font,
+ logo and favicon. The README documents each type's real fields; the
+ catalogue reader now reads `themes/*/` sections and READMEs after the
+ site's own (the site's win), and treats types `render-sections` picks
+ by name as types even before a page uses them; Lead forms knows a theme
+ site needs only the address. Tested with Hugo building every section.
**Part 1 built (2026-11-22; no schema change).** `internal/backup` makes
backups with `VACUUM INTO` (to a `.part` file, then renamed; mode 0600)
diff --git a/internal/sites/catalog.go b/internal/sites/catalog.go
index a495f91..3021267 100644
--- a/internal/sites/catalog.go
+++ b/internal/sites/catalog.go
@@ -82,25 +82,36 @@ var (
partialRef = regexp.MustCompile(`partial\s+"sections/([\w-]+)\.html"\s*(?:(\$s|\.)(?:\s|-?\}\}|\)))?`)
dollarS = regexp.MustCompile(`\$s\.([a-z]\w*)`)
bareDot = regexp.MustCompile(`(?:^|[\s(])\.([a-z]\w*)`)
+ typeTest = regexp.MustCompile(`eq \.type "([\w-]+)"`)
readmeList = regexp.MustCompile("^\\s*[-*]\\s+`([\\w-]+)`\\s+[—–-]+\\s+(.+)$")
readmeRow = regexp.MustCompile("^\\|\\s*`([\\w-]+)`\\s*\\|\\s*(.+?)\\s*\\|\\s*$")
)
// Read reads the catalogue from a working copy of the site.
func Read(dir string, pathOf PathFunc) (*Catalog, error) {
- partDir := filepath.Join(dir, "layouts", "partials", "sections")
- entries, err := os.ReadDir(partDir)
- if err != nil && !os.IsNotExist(err) {
- return nil, err
+ // The site's own layouts, then its themes' (the site's win, as in Hugo).
+ roots := []string{dir}
+ if themes, err := filepath.Glob(filepath.Join(dir, "themes", "*")); err == nil {
+ sort.Strings(themes)
+ roots = append(roots, themes...)
}
partials := map[string]string{}
- for _, e := range entries {
- if !e.IsDir() && strings.HasSuffix(e.Name(), ".html") {
+ for _, root := range roots {
+ partDir := filepath.Join(root, "layouts", "partials", "sections")
+ entries, err := os.ReadDir(partDir)
+ if err != nil && !os.IsNotExist(err) {
+ return nil, err
+ }
+ for _, e := range entries {
+ name := strings.TrimSuffix(e.Name(), ".html")
+ if e.IsDir() || !strings.HasSuffix(e.Name(), ".html") || partials[name] != "" {
+ continue
+ }
raw, err := os.ReadFile(filepath.Join(partDir, e.Name()))
if err != nil {
return nil, err
}
- partials[strings.TrimSuffix(e.Name(), ".html")] = string(raw)
+ partials[name] = string(raw)
}
}
// Partials named by another partial, or by render-sections, are
@@ -115,9 +126,16 @@ func Read(dir string, pathOf PathFunc) (*Catalog, error) {
}
}
}
- if raw, err := os.ReadFile(filepath.Join(dir, "layouts", "partials", "render-sections.html")); err == nil {
- for _, m := range partialRef.FindAllStringSubmatch(string(raw), -1) {
- referenced[m[1]] = true
+ dispatched := map[string]bool{} // types render-sections picks by name
+ for _, root := range roots {
+ if raw, err := os.ReadFile(filepath.Join(root, "layouts", "partials", "render-sections.html")); err == nil {
+ for _, m := range partialRef.FindAllStringSubmatch(string(raw), -1) {
+ referenced[m[1]] = true
+ }
+ for _, m := range typeTest.FindAllStringSubmatch(string(raw), -1) {
+ dispatched[m[1]] = true
+ }
+ break
}
}
@@ -135,7 +153,7 @@ func Read(dir string, pathOf PathFunc) (*Catalog, error) {
}
root := filepath.Join(dir, "content")
- err = filepath.WalkDir(root, func(p string, d fs.DirEntry, err error) error {
+ err := filepath.WalkDir(root, func(p string, d fs.DirEntry, err error) error {
if err != nil {
if os.IsNotExist(err) && p == root {
return fs.SkipDir
@@ -208,13 +226,18 @@ func Read(dir string, pathOf PathFunc) (*Catalog, error) {
}
for name := range partials {
- if referenced[name] && uses[name] == nil {
+ if referenced[name] && uses[name] == nil && !dispatched[name] {
c.Helpers = append(c.Helpers, name)
continue
}
get(name)
}
- docs := readmeDocs(dir)
+ docs := map[string]string{}
+ for i := len(roots) - 1; i >= 0; i-- { // the site's README wins
+ for k, v := range readmeDocs(roots[i]) {
+ docs[k] = v
+ }
+ }
for name, t := range uses {
_, has := partials[name]
t.Missing = !has
diff --git a/internal/sites/leadforms.go b/internal/sites/leadforms.go
index 449515a..28c929b 100644
--- a/internal/sites/leadforms.go
+++ b/internal/sites/leadforms.go
@@ -15,6 +15,7 @@ import (
"supermarket/internal/api/gitea"
"supermarket/internal/hugorepo"
"supermarket/internal/seo"
+ "supermarket/internal/theme"
)
// Lead forms: a site's `form` sections post to EspoCRM's Lead Capture
@@ -34,58 +35,9 @@ const LeadScriptPath = "static/js/supermarket-leads.js"
var LeadPayloadFields = []string{"First Name", "Last Name", "Email", "Account Name", "Phone", "Description"}
// leadScript defines window.leadPost(form, data), which the form's own
-// script calls in place of its fetch: it returns the fetch's promise.
-const leadScript = `/* Sends the site's lead forms to EspoCRM's Lead Capture. Written by
- Supermarket: the form posts here instead of to [params.leads] action
- directly, so its fields can be mapped onto a Lead's. */
-(function () {
- var mapped = { email: 'emailAddress', 'e-mail': 'emailAddress', phone: 'phoneNumber', tel: 'phoneNumber',
- company: 'accountName', organization: 'accountName', organisation: 'accountName', church: 'accountName' };
- function label(form, name) {
- var el = form.querySelector('[name="' + name + '"]');
- var l = el && el.id && form.querySelector('label[for="' + el.id + '"]');
- return l ? l.childNodes[0].textContent.trim() : name;
- }
- window.leadPost = function (form, data) {
- var lead = { firstName: null, lastName: null, emailAddress: null, accountName: null, phoneNumber: null };
- var notes = [];
- data.forEach(function (value, name) {
- value = String(value).trim();
- if (!value) return;
- var key = name.toLowerCase();
- if (key === 'name' || key === 'full_name' || key === 'fullname') {
- var parts = value.split(/\s+/);
- lead.lastName = parts.pop();
- lead.firstName = parts.length ? parts.join(' ') : null;
- } else if (key === 'first_name' || key === 'firstname') {
- lead.firstName = value;
- } else if (key === 'last_name' || key === 'lastname') {
- lead.lastName = value;
- } else if (mapped[key]) {
- lead[mapped[key]] = value;
- } else if (key === 'source') {
- notes.unshift('Form: ' + value);
- } else if (key === 'page') {
- notes.push('Page: ' + location.origin + value);
- } else {
- notes.push(label(form, name) + ': ' + value);
- }
- });
- if (!lead.lastName) lead.lastName = lead.emailAddress || 'Website visitor';
- var q = new URLSearchParams(location.search);
- ['utm_campaign', 'utm_source', 'utm_medium', 'utm_content'].forEach(function (k) {
- if (q.get(k)) notes.push(k + ': ' + q.get(k));
- });
- if (document.referrer) notes.push('Came from: ' + document.referrer);
- lead.description = notes.join('\n') || null;
- return fetch(form.action, {
- method: 'POST',
- headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
- body: JSON.stringify(lead)
- });
- };
-})();
-`
+// script calls in place of its fetch: it returns the fetch's promise. It's
+// the theme's, so new sites have it from the start.
+var leadScript = theme.LeadScript()
var (
captureURL = regexp.MustCompile(`^https://[^/\s]+/(?:[^\s?#]*/)?api/v1/LeadCapture/[A-Za-z0-9]+$`)
@@ -216,10 +168,14 @@ func ReadForms(wc *hugorepo.Repo, cat *Catalog) FormState {
st.Action = LeadsAction(string(raw))
}
}
- st.Script = wc.Exists(LeadScriptPath)
+ st.Script = wc.Exists(LeadScriptPath) || wc.Exists(theme.Dir+"/"+LeadScriptPath)
if raw, err := os.ReadFile(wc.Dir + "/layouts/partials/sections/form.html"); err == nil {
st.Patched = strings.Contains(string(raw), "window.leadPost")
_, st.Supported = PatchFormPartial(string(raw))
+ } else if raw, err := os.ReadFile(wc.Dir + "/" + theme.Dir + "/layouts/partials/sections/form.html"); err == nil {
+ // The theme's form already posts through the script.
+ st.Patched = strings.Contains(string(raw), "window.leadPost")
+ st.Supported = st.Patched
}
if cat != nil {
if t := cat.Type("form"); t != nil {
@@ -252,14 +208,18 @@ func ConnectForms(ctx context.Context, ap *seo.Applier, capture string, formPage
return nil, errors.New("the site's settings aren't in a TOML file (hugo.toml), which is all Supermarket can change for now")
}
partial := "layouts/partials/sections/form.html"
- raw, err := os.ReadFile(wc.Dir + "/" + partial)
- if err != nil {
+ var files []struct{ path, body string }
+ if raw, err := os.ReadFile(wc.Dir + "/" + partial); err == nil {
+ patched, ok := PatchFormPartial(string(raw))
+ if !ok {
+ return nil, errors.New("the site's form section doesn't post the way Supermarket knows (a fetch of form.action with the form's data), so it can't be connected automatically")
+ }
+ files = append(files, struct{ path, body string }{partial, patched}, struct{ path, body string }{LeadScriptPath, leadScript})
+ } else if raw, err := os.ReadFile(wc.Dir + "/" + theme.Dir + "/" + partial); err == nil && strings.Contains(string(raw), "window.leadPost") {
+ // Supermarket's theme: its form and script are ready; only the address is needed.
+ } else {
return nil, errors.New("the site has no form section (layouts/partials/sections/form.html)")
}
- patched, ok := PatchFormPartial(string(raw))
- if !ok {
- return nil, errors.New("the site's form section doesn't post the way Supermarket knows (a fetch of form.action with the form's data), so it can't be connected automatically")
- }
branch := "supermarket/lead-forms"
if err := wc.NewBranch(ctx, branch); err != nil {
return nil, err
@@ -268,9 +228,8 @@ func ConnectForms(ctx context.Context, ap *seo.Applier, capture string, formPage
if err != nil {
return nil, err
}
- for _, f := range []struct{ path, body string }{
- {cfg, SetLeadsAction(string(cfgRaw), capture)}, {partial, patched}, {LeadScriptPath, leadScript},
- } {
+ files = append(files, struct{ path, body string }{cfg, SetLeadsAction(string(cfgRaw), capture)})
+ for _, f := range files {
if err := wc.WriteFile(f.path, f.body); err != nil {
return nil, err
}
diff --git a/internal/sites/theme_test.go b/internal/sites/theme_test.go
new file mode 100644
index 0000000..fec5b04
--- /dev/null
+++ b/internal/sites/theme_test.go
@@ -0,0 +1,49 @@
+package sites
+
+import (
+ "slices"
+ "strings"
+ "testing"
+
+ "supermarket/internal/theme"
+)
+
+func TestReadThemeSite(t *testing.T) {
+ files := map[string]string{
+ "hugo.toml": "theme = 'supermarket'\n",
+ "content/_index.md": "---\ntitle: Home\nsections:\n - type: hero\n title: Hi\n - type: faq\n items: [{q: A, a: B}]\n---\n",
+ "README.md": "| `faq` | the site's own words |\n",
+ "layouts/partials/sections/faq.html": "{{ $s := . }}{{ range $s.items }}{{ .q }}{{ .a }}{{ end }}",
+ }
+ for p, b := range theme.Files() {
+ files[theme.Dir+"/"+p] = b
+ }
+ dir := write(t, files)
+ c, err := Read(dir, path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var names []string
+ for _, ty := range c.Types {
+ names = append(names, ty.Name)
+ }
+ slices.Sort(names)
+ want := []string{"callout", "cards", "checklist", "faq", "features", "final-cta", "form", "hero", "split", "stats", "steps", "table", "text"}
+ if !slices.Equal(names, want) {
+ t.Errorf("types: %v", names)
+ }
+ if !slices.Equal(c.Helpers, []string{"ctas", "head", "wrapper"}) {
+ t.Errorf("helpers: %v", c.Helpers)
+ }
+ if d := c.Type("hero").Doc; !strings.Contains(d, "`eyebrow`, `title`, `subhead`") {
+ t.Errorf("hero doc from the theme: %q", d)
+ }
+ // The site's own README and layout win over the theme's.
+ faq := c.Type("faq")
+ if faq.Doc != "the site's own words" || slices.Contains(faq.Layout, "ctas") {
+ t.Errorf("faq: %+v", faq)
+ }
+ if c.Type("form").Missing || !slices.Contains(c.Type("table").Layout, "rows") {
+ t.Errorf("form/table: %+v %+v", c.Type("form"), c.Type("table"))
+ }
+}
diff --git a/internal/theme/files/README.md b/internal/theme/files/README.md
new file mode 100644
index 0000000..d1032c0
--- /dev/null
+++ b/internal/theme/files/README.md
@@ -0,0 +1,75 @@
+# The Supermarket site theme
+
+A Hugo theme for websites made of sections, from Federated Computer's
+design system. Supermarket copies it into a site as `themes/supermarket/`;
+the site's `hugo.toml` says `theme = "supermarket"`. Anything in the site's
+own `layouts/` or `static/` takes precedence over the theme's, so a site can
+change any part of it.
+
+## How pages are built
+
+Every page's content lives in its front matter as a `sections:` list. Each
+section has a `type` and the fields that type takes. Sections alternate
+white and grey bands; `hero` opens the page as a dark band and `final-cta`
+closes it as one.
+
+Any section can take `id` (an anchor for links); without one it's made
+from `kicker` or `headline`. Most take a heading: `kicker` (a small label
+above), `headline` and `lede` (a sentence below). Buttons are `ctas`: a list
+of `label`, `url` and `style` (`primary`, `ghost`, or `text` for a quiet
+link). Text fields take Markdown inline (bold, links).
+
+| Type | Fields |
+|------|--------|
+| `hero` | `eyebrow`, `title`, `subhead`, `ctas`, `compact` (shorter). Optional `log`: lines of `tag` + `text` (`think: true` for a greyed step, `done: true` to close) typed out in a console beside the copy, titled `logTitle`; `logImage` puts a photo behind the band, credited by `logCaption` |
+| `text` | `kicker`, `headline`, `body` (Markdown), `centered`, `ctas`; `offer` adds a highlighted card below: `badge`, `text`, `ctas`. Without a headline, the body shows as a large statement |
+| `features` | `kicker`, `headline`, `lede`, `intro` (Markdown), `items` of `label` + `body` |
+| `cards` | `kicker`, `headline`, `lede`, `columns` (2 or 3), `items` of `label`, `title`, `body`, `image`, `link`, `linktext`; `visual: true` draws a panel where there's no image; `ctas` |
+| `steps` | `kicker`, `headline`, `lede`, `items` of `title` + `body` |
+| `checklist` | `kicker`, `headline`, `lede`, `items` (Markdown strings) |
+| `split` | `kicker`, `headline`, `lede`, `columns` of `title` + `items` (short lists), `ctas` |
+| `stats` | `kicker`, `headline`, `lede`, `items` of `value` + `label` (values starting with a number count up), `ctas` |
+| `table` | A comparison: `kicker`, `headline`, `lede`, `headers` (one per column of values; the last is yours, highlighted), `rows` of `label` + `cells` (one value per header), `ctas` |
+| `faq` | `kicker`, `headline`, `lede`, `items` of `q` + `a`, `ctas` |
+| `callout` | `kicker`, `headline`, `intro`, `text` |
+| `final-cta` | `headline`, `body`, `ctas` (the dark closing band) |
+| `form` | A lead form: `kicker`, `headline`, `lede`, `points` (a list beside the form), `note`, `subject` (names the lead), `submit` (the button), `success` (shown after sending), `fields` of `name`, `label`, `type` (`text`, `email`, `number`, `select`, `textarea`), `options`, `placeholder`, `hint`, `required`, `half: true` (two to a row). It posts to `[params.leads] action` (EspoCRM's Lead Capture, set up by Supermarket); while that's empty it opens an email to `[params.leads] email` |
+
+## Settings (hugo.toml)
+
+```toml
+theme = "supermarket"
+
+[params]
+ tagline = "What the company does, in a line."
+
+[params.brand]
+ logo = "/images/logo.svg" # without one, the site's title is shown
+ favicon = "/favicon.svg"
+ dark = "#001a2b" # the top bar, hero and closing band
+ dark2 = "#052b42"
+ primary = "#e0ff4f" # the main button
+ accent = "#614efa" # links and highlights
+ font = "Inter" # a Google Fonts family
+
+[params.header]
+ ctas = [{ label = "Get started", url = "/contact/", style = "primary" }]
+
+[params.footer]
+ tagline = "..."
+ place = "City, Country"
+ copyright = "© 2026 Company, Inc."
+ groups = [{ title = "Company", menu = "footer_company" }]
+
+[params.leads]
+ action = ""
+ email = "hello@example.com"
+
+[params.plausible]
+ script = "https://plausible.example.com/js/script.js"
+ domain = "example.com"
+```
+
+The top bar shows the `main` menu (`[[menu.main]]`); an entry with
+`params.dropdown = "