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
+68
View File
@@ -6,6 +6,8 @@ import (
"net/url"
"slices"
"strings"
"supermarket/internal/db"
)
// What the website's pages turn visits into, from Plausible (the tracking
@@ -165,3 +167,69 @@ func moreSignups(x float64) string {
n := int(math.Round(x))
return fmt.Sprintf("about %d more %s", n, plural(n, "sign-up", "sign-ups"))
}
// SearchesByPath are the searches Google showed each page for in the last
// 90 days of data (any host of the scope, by PathKey), with their
// impressions, most first.
func SearchesByPath(d *db.DB, sc Scope) (map[string][]QueryRow, error) {
from, to, ok := period(d, sc.Property, RanksDays)
if !ok {
return nil, nil
}
cond, args := sc.where()
rows, err := d.Query(`SELECT page, query, sum(clicks), sum(impressions), sum(pos_sum) FROM gsc_query_days
WHERE `+cond+` AND date BETWEEN ? AND ? GROUP BY page, query`, append(args, from, to)...)
if err != nil {
return nil, err
}
defer rows.Close()
byPath := map[string]map[string]*QueryRow{}
for rows.Next() {
var page string
var q QueryRow
var ps float64
if err := rows.Scan(&page, &q.Query, &q.Clicks, &q.Impressions, &ps); err != nil {
return nil, err
}
k := PathKey(page)
if byPath[k] == nil {
byPath[k] = map[string]*QueryRow{}
}
if have := byPath[k][q.Query]; have != nil {
have.Clicks += q.Clicks
have.Impressions += q.Impressions
continue
}
q.Position = position(ps, q.Impressions)
byPath[k][q.Query] = &q
}
out := map[string][]QueryRow{}
for k, qs := range byPath {
for _, q := range qs {
out[k] = append(out[k], *q)
}
slices.SortFunc(out[k], func(a, b QueryRow) int {
if a.Impressions != b.Impressions {
return b.Impressions - a.Impressions
}
return strings.Compare(a.Query, b.Query)
})
}
return out, rows.Err()
}
// PageSearches are a page's searches, most impressions first.
func PageSearches(d *db.DB, sc Scope, path string, n int) ([]string, error) {
all, err := SearchesByPath(d, sc)
if err != nil {
return nil, err
}
var out []string
for i, q := range all[PathKey(path)] {
if i == n {
break
}
out = append(out, q.Query)
}
return out, nil
}