Phase 8 part 3: lost links
Each known linking page (from Bing, Plausible or added by hand) is opened once a week, at most 100 a day, to check it still links to the site: kept, gone (the page no longer has the link), page gone (404, 410 or moved elsewhere) or pointing at a 404 (our page it links to is gone). SEO → Links lists the lost ones with what happened, when last seen and what the site brought; links can be added by hand (checked at once), checked now, or forgotten. What to write next suggests a redirect for a link to a 404, and asking for a lost link back when it brought visitors. Links and What to write next now work for websites without Search Console too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+51
-1
@@ -2,16 +2,19 @@ package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"supermarket/internal/backlinks"
|
||||
"supermarket/internal/inventory"
|
||||
"supermarket/internal/next"
|
||||
"supermarket/internal/profile"
|
||||
"supermarket/internal/seo"
|
||||
"supermarket/internal/tracking"
|
||||
)
|
||||
|
||||
// What to write next (SEO → What to write next): SEO's suggestions and the
|
||||
@@ -86,6 +89,7 @@ func (s *Server) nextFor(cur seoSite, now time.Time) (list []next.Suggestion, mo
|
||||
all = append(all, ideas...)
|
||||
}
|
||||
}
|
||||
all = append(all, s.lostLinkIdeas(cur)...)
|
||||
stalled, err := next.Stalled(s.DB, cur.URL, cur.Index, now)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
@@ -120,7 +124,10 @@ func (s *Server) nextFor(cur seoSite, now time.Time) (list []next.Suggestion, mo
|
||||
}
|
||||
|
||||
func (s *Server) seoNextPage(w http.ResponseWriter, r *http.Request) {
|
||||
data, cur := s.seoBase(r)
|
||||
// Every website with an address: only some suggestions need Search
|
||||
// Console, and those are skipped without it.
|
||||
sites, cur := s.auditSites(r)
|
||||
data := map[string]any{"Sites": sites, "Current": cur, "Connected": true}
|
||||
data["Path"] = "/seo/next"
|
||||
if cur != nil {
|
||||
list, more, err := s.nextFor(*cur, time.Now())
|
||||
@@ -209,3 +216,46 @@ func (s *Server) sectionIdeas(cur seoSite) ([]next.Suggestion, error) {
|
||||
rate, _ := sc.Rate("")
|
||||
return next.SectionIdeas(pages, searches, types, competitors, cur.Index, rate), nil
|
||||
}
|
||||
|
||||
// lostLinkIdeas suggest fixing links lost or pointing at a 404: a redirect
|
||||
// for the second, a word with the linking site for the first when it
|
||||
// brought visitors.
|
||||
func (s *Server) lostLinkIdeas(cur seoSite) []next.Suggestion {
|
||||
links, err := backlinks.Links(s.DB, cur.URL)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
brought := map[string]tracking.Referrer{}
|
||||
if p, _ := profile.Load(s.DB); p != nil {
|
||||
for _, w := range p.Websites {
|
||||
if w.URL == cur.URL {
|
||||
list, _, _ := tracking.Referrers(s.DB, w, linkDays)
|
||||
for _, ref := range list {
|
||||
brought[strings.TrimPrefix(strings.ToLower(ref.Source), "www.")] = ref
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
rate, _ := s.scope(cur).Rate("")
|
||||
var out []next.Suggestion
|
||||
for _, l := range links {
|
||||
b := brought[l.Host()]
|
||||
worth := float64(b.Signups) + float64(b.Visitors)*rate
|
||||
see := next.Action{Label: "See the link", Method: "GET", URL: "/seo/links?site=" + strconv.Itoa(cur.Index) + "#lost"}
|
||||
visits := ""
|
||||
if b.Visitors > 0 {
|
||||
visits = fmt.Sprintf(" It brought %d visitors in 90 days.", b.Visitors)
|
||||
}
|
||||
switch {
|
||||
case l.Status == backlinks.StatusTarget404:
|
||||
out = append(out, next.Suggestion{Key: "link-404:" + l.Target, Kind: "Fix with a redirect", Title: l.Target,
|
||||
Why: l.Host() + " links to " + l.Target + ", which answers 404: redirect it to where the page went, and the link works again." + visits,
|
||||
Score: 0.3 + worth, Action: see})
|
||||
case l.Lost() && b.Visitors > 0:
|
||||
out = append(out, next.Suggestion{Key: "link-lost:" + l.Source, Kind: "Ask for the link back", Title: l.Host(),
|
||||
Why: l.Note + visits + " A short note to the site often gets it back.",
|
||||
Score: worth, Action: next.Action{Label: "Open their page", Method: "GET", URL: l.Source}})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user