Phase 3 part 5: the next keywords

Candidates a site has no page for, from Search Console searches it ranks
weakly for, the profile's keywords and customers' problems, the signals'
search lines, and competitors' sitemaps; each checked against our own
pages. Buyer searches first. On request, Claude's web search reads the
live top 3 and types each result (big brand, marketplace, forum, small
site), and keywords are ranked by who has to be beaten. Pick, dismiss or
bring back. Schema 16.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 08:11:27 -07:00
co-authored by Claude Opus 5.5
parent 438192faba
commit c0a5ddf77f
13 changed files with 846 additions and 2 deletions
+89
View File
@@ -290,3 +290,92 @@ func (s *Server) testGitea(ctx context.Context) map[string]any {
}
return res
}
// --- The next keywords ---
func (s *Server) seoKeywordsPage(w http.ResponseWriter, r *http.Request) {
s.renderKeywords(w, r, "")
}
func (s *Server) renderKeywords(w http.ResponseWriter, r *http.Request, errMsg string) {
sites, cur := s.auditSites(r)
data := map[string]any{"Sites": sites, "Current": cur}
if cur != nil {
for _, st := range []string{seo.KeywordNew, seo.KeywordPicked, seo.KeywordDismissed} {
ks, err := seo.Keywords(s.DB, auditKey(*cur), st)
if err != nil {
s.serverError(w, err)
return
}
data[st] = ks
}
if _, err := s.researcher(); err != nil {
data["NoSearch"] = err.Error()
}
}
s.render(w, r, "seo-keywords", page{Title: "Next keywords", Nav: "seo/keywords", Error: errMsg, Data: data})
}
func (s *Server) seoKeywordsFind(w http.ResponseWriter, r *http.Request) {
_, cur := s.auditSites(r)
if cur == nil {
http.NotFound(w, r)
return
}
p, _ := profile.Load(s.DB)
ctx, cancel := context.WithTimeout(r.Context(), 5*time.Minute)
defer cancel()
if _, err := seo.FindKeywords(ctx, s.DB, auditKey(*cur), cur.Property, p, "Supermarket/"+s.Version+" (SEO)", time.Now()); err != nil {
s.renderKeywords(w, r, "Couldn't look for keywords: "+err.Error())
return
}
redirect(w, r, "/seo/keywords?site="+strconv.Itoa(cur.Index), "keywords-found")
}
func (s *Server) seoKeywordAction(w http.ResponseWriter, r *http.Request) {
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
if err != nil {
http.NotFound(w, r)
return
}
k, err := seo.GetKeyword(s.DB, id)
if err != nil {
http.NotFound(w, r)
return
}
site, ok := s.siteFor(k.Site)
if !ok {
http.NotFound(w, r)
return
}
back := "/seo/keywords?site=" + strconv.Itoa(site.Index) + "#k-" + strconv.FormatInt(id, 10)
now := time.Now()
switch r.PathValue("action") {
case "top":
rs, rerr := s.researcher()
if rerr == nil {
ctx, cancel := context.WithTimeout(r.Context(), 4*time.Minute)
defer cancel()
_, rerr = seo.ReadTop(ctx, s.DB, rs, id, site.URL, now)
}
if rerr != nil {
s.renderKeywords(w, r, "Couldn't read the top results: "+rerr.Error())
return
}
redirect(w, r, back, "top-read")
case "pick":
err = seo.SetKeywordStatus(s.DB, id, seo.KeywordPicked, now)
case "dismiss":
err = seo.SetKeywordStatus(s.DB, id, seo.KeywordDismissed, now)
case "restore":
err = seo.SetKeywordStatus(s.DB, id, seo.KeywordNew, now)
default:
http.NotFound(w, r)
return
}
if err != nil {
s.renderKeywords(w, r, err.Error())
return
}
redirect(w, r, back, "saved")
}