Phase 8 part 4: where to win a link
Supermarket looks at each Inventory partner's pages that list providers, hosts or partners (from their sitemap and home page) and keeps the ones that list others but not the site; once a month by itself, or on request. On request (up to 4 web searches), the AI finds lists of alternatives to a competitor, and each page is read to keep the ones that name others but not the company. Each opportunity can be marked asked, won or dismissed; it's marked won when a link from its site shows up. SEO → Links lists them; open ones join What to write next. Nothing is sent: asking is the user's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"supermarket/internal/api/sitemap"
|
||||
"supermarket/internal/backlinks"
|
||||
"supermarket/internal/inventory"
|
||||
"supermarket/internal/profile"
|
||||
"supermarket/internal/seo"
|
||||
"supermarket/internal/tracking"
|
||||
@@ -90,6 +92,18 @@ func (s *Server) renderLinks(w http.ResponseWriter, r *http.Request, errMsg stri
|
||||
}
|
||||
}
|
||||
data["Lost"], data["Counts"] = lost, counts
|
||||
opps, err := backlinks.Opportunities(s.DB, cur.URL)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
data["Opportunities"] = opps
|
||||
partners, _ := inventory.List(s.DB, inventory.Partner)
|
||||
competitors, _ := inventory.List(s.DB, inventory.Competitor)
|
||||
data["Partners"], data["Competitors"] = len(partners), competitors
|
||||
if _, err := s.researcher(); err != nil {
|
||||
data["Research"] = err.Error()
|
||||
}
|
||||
data["LinkingSites"], data["LinkCount"] = sites, len(links)
|
||||
if len(sites) > 30 {
|
||||
data["MoreSites"], data["LinkingSites"] = len(sites)-30, sites[:30]
|
||||
@@ -172,6 +186,43 @@ func (s *Server) seoLinksAction(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
redirectCounts(w, r, back, "links-checked", n)
|
||||
case "partners":
|
||||
n, err := backlinks.FindPartnerPages(ctx, s.DB, s.linkFetcher(), sitemapPages{sitemap.New("Supermarket/" + s.Version + " (link check)")}, cur.URL, now)
|
||||
if err != nil {
|
||||
s.renderLinks(w, r, err.Error())
|
||||
return
|
||||
}
|
||||
_ = s.DB.PutJSON(partnersKey(cur.URL), now)
|
||||
redirectCounts(w, r, "/seo/links?site="+strconv.Itoa(cur.Index)+"#opportunities", "partners-read", n)
|
||||
case "alternatives":
|
||||
id, _ := strconv.ParseInt(r.PostFormValue("competitor"), 10, 64)
|
||||
e, err := inventory.Get(s.DB, id)
|
||||
if err != nil || e.Relationship != inventory.Competitor {
|
||||
s.renderLinks(w, r, "Choose a competitor from the Inventory.")
|
||||
return
|
||||
}
|
||||
rs, err := s.researcher()
|
||||
if err != nil {
|
||||
s.renderLinks(w, r, err.Error())
|
||||
return
|
||||
}
|
||||
company := ""
|
||||
if p, _ := profile.Load(s.DB); p != nil {
|
||||
company = p.Name
|
||||
}
|
||||
n, _, err := backlinks.FindAlternativeLists(ctx, s.DB, rs, s.linkFetcher(), cur.URL, company, e, now)
|
||||
if err != nil {
|
||||
s.renderLinks(w, r, "Couldn't search: "+err.Error())
|
||||
return
|
||||
}
|
||||
redirectCounts(w, r, "/seo/links?site="+strconv.Itoa(cur.Index)+"#opportunities", "alternatives-read", n)
|
||||
case "opportunity":
|
||||
id, _ := strconv.ParseInt(r.PostFormValue("id"), 10, 64)
|
||||
if err := backlinks.SetStatus(s.DB, cur.URL, id, r.PostFormValue("status"), now); err != nil {
|
||||
s.renderLinks(w, r, err.Error())
|
||||
return
|
||||
}
|
||||
redirect(w, r, "/seo/links?site="+strconv.Itoa(cur.Index)+"#opportunities", "saved")
|
||||
case "forget":
|
||||
id, _ := strconv.ParseInt(r.PostFormValue("id"), 10, 64)
|
||||
if err := backlinks.Remove(s.DB, cur.URL, id); err != nil {
|
||||
@@ -197,3 +248,40 @@ func (s *Server) dailyLinkChecks(ctx context.Context) {
|
||||
cancel()
|
||||
}
|
||||
}
|
||||
|
||||
// sitemapPages lists a site's pages from its sitemap, for the partner check.
|
||||
type sitemapPages struct{ c *sitemap.Client }
|
||||
|
||||
func (s sitemapPages) AllPages(ctx context.Context, site, mapURL string) ([]string, error) {
|
||||
pages, err := s.c.AllPages(ctx, site, mapURL)
|
||||
var out []string
|
||||
for _, p := range pages {
|
||||
out = append(out, p.URL)
|
||||
}
|
||||
return out, err
|
||||
}
|
||||
|
||||
func partnersKey(site string) string { return "backlinks:partners-read:" + site }
|
||||
|
||||
// monthlyPartnerPages looks at the partners' pages once a month, and marks
|
||||
// opportunities won when their links show up.
|
||||
func (s *Server) monthlyPartnerPages(ctx context.Context) {
|
||||
now := time.Now()
|
||||
for _, site := range s.seoSites() {
|
||||
if site.URL == "" {
|
||||
continue
|
||||
}
|
||||
_, _ = backlinks.MarkWon(s.DB, site.URL, now)
|
||||
var last time.Time
|
||||
_, _ = s.DB.GetJSON(partnersKey(site.URL), &last)
|
||||
if now.Sub(last) < 30*24*time.Hour {
|
||||
continue
|
||||
}
|
||||
pctx, cancel := context.WithTimeout(ctx, 15*time.Minute)
|
||||
if _, err := backlinks.FindPartnerPages(pctx, s.DB, s.linkFetcher(), sitemapPages{sitemap.New("Supermarket/" + s.Version + " (link check)")}, site.URL, now); err != nil {
|
||||
s.Log.Warn("backlinks: partners' pages", "site", site.URL, "err", err)
|
||||
}
|
||||
cancel()
|
||||
_ = s.DB.PutJSON(partnersKey(site.URL), now)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user