Phase 7 part 5: add a section to an existing page
Sites → Sections and pages → Add a section, on any page built from sections: choose one of the site's section types and where it goes; the AI writes it from the page, its searches, the profile and the Inventory, with the same rules as a new page. It's reviewed like a page (claims to confirm, to-dos), and the pull request inserts it into the page's file as text, so only that section is added; the build checks it. What to write next suggests a FAQ for a section page found with questions, and a comparison for one searched against something else. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+75
-33
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -126,30 +127,7 @@ func (c *Composer) Compose(ctx context.Context, in Inputs) (*Composed, error) {
|
||||
}
|
||||
p := c.Profile
|
||||
var b strings.Builder
|
||||
fmt.Fprintf(&b, "# The company\n%s: %s\n", p.Name, oneLine(p.Description))
|
||||
if p.Positioning != "" {
|
||||
fmt.Fprintf(&b, "Positioning: %s\n", oneLine(p.Positioning))
|
||||
}
|
||||
if len(p.Avoid) > 0 {
|
||||
fmt.Fprintf(&b, "Never say or do: %s\n", strings.Join(p.Avoid, "; "))
|
||||
}
|
||||
for _, pr := range p.Products {
|
||||
fmt.Fprintf(&b, "Product %s: %s", pr.Name, oneLine(pr.Description))
|
||||
if pr.Pricing != "" {
|
||||
fmt.Fprintf(&b, " Pricing: %s.", oneLine(pr.Pricing))
|
||||
}
|
||||
if len(pr.Benefits) > 0 {
|
||||
fmt.Fprintf(&b, " Benefits: %s.", strings.Join(pr.Benefits, "; "))
|
||||
}
|
||||
if pr.URL != "" {
|
||||
fmt.Fprintf(&b, " Address: %s", pr.URL)
|
||||
}
|
||||
b.WriteString("\n")
|
||||
}
|
||||
if t := p.Targets; len(t.Industries)+len(t.Roles)+len(t.CompanySizes) > 0 {
|
||||
fmt.Fprintf(&b, "Customers: %s; %s; %s\n", strings.Join(t.Industries, ", "), strings.Join(t.Roles, ", "), strings.Join(t.CompanySizes, ", "))
|
||||
}
|
||||
|
||||
b.WriteString(companyBrief(p))
|
||||
fmt.Fprintf(&b, "\n# The page\nKind: %s. %s\n", KindLabel(in.Kind), guide)
|
||||
if in.Product != nil {
|
||||
fmt.Fprintf(&b, "It's about the product %s.\n", in.Product.Name)
|
||||
@@ -242,6 +220,36 @@ Rules:
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// companyBrief is what the AI is told about the company.
|
||||
func companyBrief(p *profile.Profile) string {
|
||||
var b strings.Builder
|
||||
fmt.Fprintf(&b, "# The company\n%s: %s\n", p.Name, oneLine(p.Description))
|
||||
if p.Positioning != "" {
|
||||
fmt.Fprintf(&b, "Positioning: %s\n", oneLine(p.Positioning))
|
||||
}
|
||||
if len(p.Avoid) > 0 {
|
||||
fmt.Fprintf(&b, "Never say or do: %s\n", strings.Join(p.Avoid, "; "))
|
||||
}
|
||||
for _, pr := range p.Products {
|
||||
fmt.Fprintf(&b, "Product %s: %s", pr.Name, oneLine(pr.Description))
|
||||
if pr.Pricing != "" {
|
||||
fmt.Fprintf(&b, " Pricing: %s.", oneLine(pr.Pricing))
|
||||
}
|
||||
if len(pr.Benefits) > 0 {
|
||||
fmt.Fprintf(&b, " Benefits: %s.", strings.Join(pr.Benefits, "; "))
|
||||
}
|
||||
if pr.URL != "" {
|
||||
fmt.Fprintf(&b, " Address: %s", pr.URL)
|
||||
}
|
||||
b.WriteString("\n")
|
||||
}
|
||||
if t := p.Targets; len(t.Industries)+len(t.Roles)+len(t.CompanySizes) > 0 {
|
||||
fmt.Fprintf(&b, "Customers: %s; %s; %s\n", strings.Join(t.Industries, ", "), strings.Join(t.Roles, ", "), strings.Join(t.CompanySizes, ", "))
|
||||
}
|
||||
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func oneLine(s string) string { return strings.Join(strings.Fields(s), " ") }
|
||||
|
||||
func or(a, b string) string {
|
||||
@@ -507,7 +515,7 @@ func Push(ctx context.Context, d *db.DB, ap *seo.Applier, p *SitePage, pr bool)
|
||||
if p.Kind == "home" {
|
||||
p.Path = "/"
|
||||
}
|
||||
if strings.TrimSpace(p.Title) == "" || p.Path == "" || (p.Path == "/" && p.Kind != "home") {
|
||||
if strings.TrimSpace(p.Title) == "" || p.Path == "" || (p.Path == "/" && p.Kind != "home" && p.Kind != KindSection) {
|
||||
return errors.New("give the page a title and an address")
|
||||
}
|
||||
p.Status, p.Error = PageWorking, ""
|
||||
@@ -542,6 +550,14 @@ func push(ctx context.Context, ap *seo.Applier, p *SitePage, pr bool) error {
|
||||
}
|
||||
p.File = file
|
||||
}
|
||||
if p.Kind == KindSection {
|
||||
// The page is already there: the section goes into its file.
|
||||
file, err := wc.FindContent(p.Path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("the page %s isn't on the published branch any more", p.Path)
|
||||
}
|
||||
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)
|
||||
@@ -552,13 +568,26 @@ func push(ctx context.Context, ap *seo.Applier, p *SitePage, pr bool) error {
|
||||
if err := wc.NewBranch(ctx, p.Branch); err != nil {
|
||||
return err
|
||||
}
|
||||
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
|
||||
var body string
|
||||
if p.Kind == KindSection {
|
||||
raw, err := os.ReadFile(filepath.Join(wc.Dir, filepath.FromSlash(p.File)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
out, err := InsertSection(raw, p.Sections, p.Source.At)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
body = string(out)
|
||||
} else {
|
||||
menu := ""
|
||||
if menuWeight(p.Kind) > 0 {
|
||||
menu = "main"
|
||||
}
|
||||
var err error
|
||||
if body, err = frontMatter(p.Title, p.Description, p.Sections, menu, menuWeight(p.Kind)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := wc.WriteFile(p.File, body); err != nil {
|
||||
return err
|
||||
@@ -577,6 +606,9 @@ func push(ctx context.Context, ap *seo.Applier, p *SitePage, pr bool) error {
|
||||
p.Note = fmt.Sprintf("Checked with a build: the site builds and the page is at %s (its title: %q).", p.Path, title)
|
||||
}
|
||||
subject := fmt.Sprintf("Sites: %s %s", strings.ToLower(KindLabel(p.Kind)), p.Path)
|
||||
if p.Kind == KindSection {
|
||||
subject = "Sites: a new section on " + p.Path
|
||||
}
|
||||
if err := wc.CommitAndPush(ctx, p.Branch, subject); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -584,7 +616,11 @@ func push(ctx context.Context, ap *seo.Applier, p *SitePage, pr bool) error {
|
||||
return nil
|
||||
}
|
||||
var b strings.Builder
|
||||
fmt.Fprintf(&b, "A %s built by Supermarket from the site's own sections: **%s** at `%s`.\n\n", strings.ToLower(KindLabel(p.Kind)), p.Title, p.Path)
|
||||
if p.Kind == KindSection {
|
||||
fmt.Fprintf(&b, "One new section, written by Supermarket from one of the site's own section types, on **%s** (`%s`). Only that page's sections list changes: the section is added, nothing else is touched.\n\n", p.Title, p.Path)
|
||||
} else {
|
||||
fmt.Fprintf(&b, "A %s built by Supermarket from the site's own sections: **%s** at `%s`.\n\n", strings.ToLower(KindLabel(p.Kind)), p.Title, p.Path)
|
||||
}
|
||||
if p.Notes != "" {
|
||||
fmt.Fprintf(&b, "**What it was asked for:** %s\n\n", p.Notes)
|
||||
}
|
||||
@@ -634,6 +670,9 @@ func Content(p *SitePage) string {
|
||||
// Variant makes a copy of a page to test against it: the same sections at
|
||||
// its own address (the original's with -b, -c…), a draft until pushed.
|
||||
func Variant(d *db.DB, orig *SitePage) (*SitePage, error) {
|
||||
if orig.Kind == KindSection {
|
||||
return nil, errors.New("a section added to a page has no variants")
|
||||
}
|
||||
rootID := orig.Root()
|
||||
root := orig
|
||||
if rootID != orig.ID {
|
||||
@@ -676,6 +715,9 @@ func Variant(d *db.DB, orig *SitePage) (*SitePage, error) {
|
||||
|
||||
// Remove opens a pull request that takes a published page off the site.
|
||||
func Remove(ctx context.Context, d *db.DB, ap *seo.Applier, p *SitePage) error {
|
||||
if p.Kind == KindSection {
|
||||
return errors.New("taking this off would delete the whole page: edit the page to take the section out")
|
||||
}
|
||||
if p.Status != PageMerged {
|
||||
return errors.New("only a page that's on the site can be taken off it")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user