Files
supermarket/internal/theme/theme.go
T
davidandClaude Opus 5.5 5d7db5c5bf Phase 6 part 5, step 1: a shared site theme
internal/theme embeds a Hugo theme from federated-website's look and the
13 section types both sites share, with the header, footer, colors, font
and logo set per site in hugo.toml, and a README of each type's fields.
The catalogue reader reads themes' sections and READMEs after the site's
own; lead forms know a theme site needs only the Lead Capture address.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:14:24 -07:00

58 lines
1.4 KiB
Go

// Package theme is the Hugo theme new sites are made with: federated-
// website's look and sections, made generic, with each site's brand as
// settings. Supermarket copies it into a site as themes/supermarket/.
package theme
import (
"embed"
"io/fs"
"sort"
"strconv"
"strings"
)
// Version is the theme's version, written into the site's copy
// (themes/supermarket/VERSION) so an older copy can be updated. Raise it
// whenever the files change.
const Version = 1
// Dir is where the theme goes in a site.
const Dir = "themes/supermarket"
// Name is the theme's name in hugo.toml.
const Name = "supermarket"
//go:embed all:files
var files embed.FS
// Files are the theme's files: path (inside the theme) → content,
// VERSION included.
func Files() map[string]string {
out := map[string]string{"VERSION": strconv.Itoa(Version) + "\n"}
_ = fs.WalkDir(files, "files", func(p string, d fs.DirEntry, err error) error {
if err != nil || d.IsDir() {
return err
}
raw, err := files.ReadFile(p)
if err != nil {
return err
}
out[strings.TrimPrefix(p, "files/")] = string(raw)
return nil
})
return out
}
// Paths are the theme's file paths, sorted.
func Paths() []string {
var ps []string
for p := range Files() {
ps = append(ps, p)
}
sort.Strings(ps)
return ps
}
// LeadScript is the lead forms' script (static/js/supermarket-leads.js).
func LeadScript() string { return Files()["static/js/supermarket-leads.js"] }