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:
2026-11-24 07:25:19 -07:00
co-authored by Claude Opus 5.5
parent 5705a9b58b
commit fdfbcd3d3d
15 changed files with 873 additions and 39 deletions
+95
View File
@@ -361,3 +361,98 @@ func since(d time.Duration) string {
return strconv.Itoa(days/7) + " weeks"
}
}
// SectionPage is a page built from sections, as Sites reads it.
type SectionPage struct {
Path, Title string
Types []string
}
// question spots searches that ask something.
var question = regexp.MustCompile(`(?i)^(how|what|why|when|where|which|who|can|does|do|is|are|should|will)\b|\?$`)
// comparing spots searches that compare or look for something else.
var comparing = regexp.MustCompile(`(?i)\b(vs\.?|versus|alternatives?|compared?|comparison)\b`)
// minSectionImpr is how many impressions a page's questions (or
// comparisons) need, together, before a section is suggested for them.
const minSectionImpr = 50
// SectionIdeas suggest a section for a page already on the site: a FAQ
// when people find it with questions and it has none, a comparison table
// when they search it against something else (an alternative, a "vs", a
// competitor by name) and it has none. Only types the site has.
func SectionIdeas(pages []SectionPage, searches map[string][]seo.QueryRow, siteTypes, competitors []string, siteIndex int, rate float64) []Suggestion {
has := func(list []string, t string) bool { return slices.Contains(list, t) }
faq := firstOf(siteTypes, "faq", "faqs", "questions")
table := firstOf(siteTypes, "comparison", "compare", "table", "matrix")
var out []Suggestion
for _, pg := range pages {
qs := searches[seo.PathKey(pg.Path)]
var asks, vs []string
askImpr, vsImpr := 0, 0
for _, q := range qs {
switch {
case question.MatchString(q.Query):
asks = append(asks, q.Query)
askImpr += q.Impressions
case comparing.MatchString(q.Query) || slices.ContainsFunc(competitors, func(c string) bool {
return c != "" && strings.Contains(strings.ToLower(q.Query), strings.ToLower(c))
}):
vs = append(vs, q.Query)
vsImpr += q.Impressions
}
}
link := func(typ string, notes string) Action {
return Action{Label: "Write the section", Method: "GET",
URL: "/sites/pages/add?site=" + strconv.Itoa(siteIndex) + "&page=" + url.QueryEscape(pg.Path) + "&type=" + url.QueryEscape(typ) + "&notes=" + url.QueryEscape(notes)}
}
if faq != "" && !has(pg.Types, faq) && askImpr >= minSectionImpr {
out = append(out, Suggestion{
Key: "section:faq:" + pg.Path, Kind: "Add a FAQ", Title: pg.Path + " " + pg.Title,
Why: fmt.Sprintf("Google shows it %s times in 90 days for questions it doesn't answer in a FAQ: %s.", seo.Thousands(askImpr), quoteList(asks, 3)),
Score: sectionScore(askImpr, rate),
Action: link(faq, "Answer the questions people search for this page: "+strings.Join(asks[:min(5, len(asks))], "; ")),
})
}
if table != "" && !has(pg.Types, table) && vsImpr >= minSectionImpr {
out = append(out, Suggestion{
Key: "section:table:" + pg.Path, Kind: "Add a comparison", Title: pg.Path + " " + pg.Title,
Why: fmt.Sprintf("Google shows it %s times in 90 days for searches that compare: %s.", seo.Thousands(vsImpr), quoteList(vs, 3)),
Score: sectionScore(vsImpr, rate),
Action: link(table, "Compare, for the searches that bring people here: "+strings.Join(vs[:min(5, len(vs))], "; ")+". Say only what the Inventory and the profile say."),
})
}
}
return out
}
// sectionScore guesses a section's worth: a few more clicks on the
// searches it answers (2% of their impressions), times the sign-up rate.
func sectionScore(impr int, rate float64) float64 {
if rate == 0 {
return float64(impr) / 20000
}
return float64(impr) * 0.02 * rate
}
func firstOf(have []string, want ...string) string {
for _, w := range want {
if slices.Contains(have, w) {
return w
}
}
return ""
}
func quoteList(qs []string, n int) string {
var out []string
for i, q := range qs {
if i == n {
out = append(out, "…")
break
}
out = append(out, "“"+q+"”")
}
return strings.Join(out, ", ")
}
+29
View File
@@ -9,6 +9,7 @@ import (
"supermarket/internal/db"
"supermarket/internal/profile"
"supermarket/internal/prospects"
"supermarket/internal/seo"
"supermarket/internal/signals"
)
@@ -88,3 +89,31 @@ func TestOwnWords(t *testing.T) {
t.Errorf("quoted: %q", got)
}
}
func TestSectionIdeas(t *testing.T) {
pages := []SectionPage{
{Path: "/freescout/", Title: "FreeScout", Types: []string{"hero", "text"}},
{Path: "/pricing/", Title: "Pricing", Types: []string{"hero", "faq"}},
}
searches := map[string][]seo.QueryRow{
"/freescout/": {
{Query: "how to install freescout", Numbers: seo.Numbers{Impressions: 40}},
{Query: "is freescout free?", Numbers: seo.Numbers{Impressions: 30}},
{Query: "freescout vs help scout", Numbers: seo.Numbers{Impressions: 20}},
{Query: "zendesk pricing per agent", Numbers: seo.Numbers{Impressions: 40}},
{Query: "freescout", Numbers: seo.Numbers{Impressions: 3000}},
},
"/pricing/": {{Query: "how much does it cost", Numbers: seo.Numbers{Impressions: 500}}},
}
got := SectionIdeas(pages, searches, []string{"hero", "text", "faq", "table"}, []string{"Zendesk"}, 0, 0)
if len(got) != 2 {
t.Fatalf("got %+v", got)
}
f, c := got[0], got[1]
if f.Kind != "Add a FAQ" || !strings.Contains(f.Why, "70 times") || !strings.Contains(f.Action.URL, "type=faq") || !strings.Contains(f.Action.URL, "page=%2Ffreescout%2F") {
t.Errorf("faq: %+v", f)
}
if c.Kind != "Add a comparison" || !strings.Contains(c.Why, "60 times") || !strings.Contains(c.Action.URL, "type=table") {
t.Errorf("comparison: %+v", c)
}
}