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:
2026-11-22 15:27:22 -07:00
co-authored by Claude Opus 5.5
parent 5d7db5c5bf
commit 9ca09c1ffa
18 changed files with 709 additions and 7 deletions
+32 -2
View File
@@ -8,6 +8,7 @@ import (
"os"
"regexp"
"slices"
"strconv"
"strings"
"time"
@@ -235,6 +236,9 @@ Rules:
out.Path = in.Path
}
out.Path = CleanPath(out.Path)
if in.Kind == "home" {
out.Path = "/"
}
return &out, nil
}
@@ -462,6 +466,12 @@ func tag(link, campaign, content string) string {
// FrontMatter is a page's content file: YAML front matter with its title,
// description and sections, and no body.
func FrontMatter(title, description, sectionsYAML string) (string, error) {
return frontMatter(title, description, sectionsYAML, "", 0)
}
// frontMatter is FrontMatter, with the page in a menu at weight when menu
// isn't "".
func frontMatter(title, description, sectionsYAML, menu string, weight int) (string, error) {
var secs yaml.Node
if err := yaml.Unmarshal([]byte(sectionsYAML), &secs); err != nil || len(secs.Content) == 0 {
return "", errors.New("the sections aren't valid YAML")
@@ -473,6 +483,11 @@ func FrontMatter(title, description, sectionsYAML string) (string, error) {
str("date"), str(time.Now().Format("2006-01-02")),
str("sections"), secs.Content[0],
}}
if menu != "" {
m.Content = append(m.Content[:6], append([]*yaml.Node{str("menus"), {Kind: yaml.MappingNode, Content: []*yaml.Node{
str(menu), {Kind: yaml.MappingNode, Content: []*yaml.Node{str("weight"), {Kind: yaml.ScalarNode, Tag: "!!int", Value: strconv.Itoa(weight)}}},
}}}, m.Content[6:]...)...)
}
var b strings.Builder
enc := yaml.NewEncoder(&b)
enc.SetIndent(2)
@@ -489,7 +504,10 @@ func FrontMatter(title, description, sectionsYAML string) (string, error) {
// with a build, and opens a pull request if pr is set and none is open.
// The page must have been checked and its claims confirmed.
func Push(ctx context.Context, d *db.DB, ap *seo.Applier, p *SitePage, pr bool) error {
if strings.TrimSpace(p.Title) == "" || p.Path == "" || p.Path == "/" {
if p.Kind == "home" {
p.Path = "/"
}
if strings.TrimSpace(p.Title) == "" || p.Path == "" || (p.Path == "/" && p.Kind != "home") {
return errors.New("give the page a title and an address")
}
p.Status, p.Error = PageWorking, ""
@@ -516,6 +534,14 @@ func push(ctx context.Context, ap *seo.Applier, p *SitePage, pr bool) error {
return err
}
defer wc.Release()
if p.File == "" && p.Kind == "home" {
// The home page replaces the site's own.
file, err := wc.FindContent("/")
if err != nil {
file = "content/_index.md"
}
p.File = file
}
if p.File == "" {
if file, err := wc.FindContent(p.Path); err == nil {
return fmt.Errorf("the site already has a page at %s (%s): choose another address", p.Path, file)
@@ -526,7 +552,11 @@ func push(ctx context.Context, ap *seo.Applier, p *SitePage, pr bool) error {
if err := wc.NewBranch(ctx, p.Branch); err != nil {
return err
}
body, err := FrontMatter(p.Title, p.Description, p.Sections)
menu := ""
if menuWeight(p.Kind) > 0 {
menu = "main"
}
body, err := frontMatter(p.Title, p.Description, p.Sections, menu, menuWeight(p.Kind))
if err != nil {
return err
}