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>
50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
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"))
|
|
}
|
|
}
|