Phase 6 part 5, step 2: start a new site
Sites → New site fills an empty Gitea repository with the theme, a hugo.toml in the site's brand and a starter home page: checked that the repository is empty and builds with Hugo, then the first commit is pushed to its default branch. The site joins the profile, and a First pages card builds its Home, About, Contact and product pages with the page builder; About and Contact join the top menu. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package sites
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"supermarket/internal/hugorepo"
|
||||
)
|
||||
|
||||
func TestNewSiteFiles(t *testing.T) {
|
||||
n := Defaults()
|
||||
n.Repo, n.URL, n.Title, n.Tagline, n.Email = " https://gitea.example/Us/acme.git ", "https://www.acme.example/", `Acme "Widgets" & Co`, "Wïdgets, for everyone", "hi@acme.example"
|
||||
if err := n.Check(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n.Repo != "Us/acme" || n.URL != "https://www.acme.example" {
|
||||
t.Errorf("tidied: %+v", n)
|
||||
}
|
||||
f := n.Files()
|
||||
if !strings.Contains(f["hugo.toml"], `title = "Acme \"Widgets\" & Co"`) {
|
||||
t.Errorf("hugo.toml:\n%s", f["hugo.toml"])
|
||||
}
|
||||
// Hugo reads the settings and builds the site, the title as given.
|
||||
if _, err := exec.LookPath("hugo"); err == nil {
|
||||
dir := t.TempDir()
|
||||
for rel, body := range f {
|
||||
os.MkdirAll(filepath.Join(dir, filepath.Dir(rel)), 0o755)
|
||||
os.WriteFile(filepath.Join(dir, rel), []byte(body), 0o644)
|
||||
}
|
||||
out, err := hugorepo.BuildDir(context.Background(), dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(out)
|
||||
home, _ := os.ReadFile(filepath.Join(out, "index.html"))
|
||||
if !strings.Contains(string(home), "<title>Acme "Widgets" & Co — Wïdgets, for everyone</title>") {
|
||||
t.Errorf("built home: %.600s", home)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(f["content/_index.md"], `title: "Acme \"Widgets\" & Co"`) || f["themes/supermarket/VERSION"] != "1\n" {
|
||||
t.Errorf("home: %s", f["content/_index.md"])
|
||||
}
|
||||
for _, bad := range []NewSite{{Title: "x\ny"}, {Dark: "red"}, {Font: "Comic<Sans>"}, {Logo: "javascript:alert(1)"}, {URL: "https://x.example/path"}} {
|
||||
m := Defaults()
|
||||
m.Repo, m.URL, m.Title = "Us/acme", "https://acme.example", "Acme"
|
||||
if bad.Title != "" {
|
||||
m.Title = bad.Title
|
||||
}
|
||||
if bad.Dark != "" {
|
||||
m.Dark = bad.Dark
|
||||
}
|
||||
if bad.Font != "" {
|
||||
m.Font = bad.Font
|
||||
}
|
||||
if bad.Logo != "" {
|
||||
m.Logo = bad.Logo
|
||||
}
|
||||
if bad.URL != "" {
|
||||
m.URL = bad.URL
|
||||
}
|
||||
if err := m.Check(); err == nil {
|
||||
t.Errorf("accepted %+v", bad)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user