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:
@@ -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) + "¬es=" + 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, ", ")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user