Files
supermarket/internal/web/links.go
T
davidandClaude Opus 5.5 392980aff6 Phase 8 part 1: links that bring visitors
The daily Plausible import also reads the visitors by referring site,
linking page and entry page, with their sign-ups and leads (a new
referrer_days table). Search engines, social networks, AI assistants,
email and mail filters, work apps, the company's own sites and tagged
links are told apart from links on other sites. SEO → Links lists the
sites that sent visitors in 90 days, the pages they landed on and the
sign-ups they brought, new ones first. A linking page Plausible names
in full is kept as a known backlink (a new backlinks table, for parts 2
and 3); browsers mostly send only the site, so most aren't.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 08:23:47 -07:00

51 lines
1.3 KiB
Go

package web
import (
"net/http"
"supermarket/internal/profile"
"supermarket/internal/tracking"
)
// SEO → Links: links from other sites to yours.
// linkDays is the period the Links page covers, as What ranks does.
const linkDays = 90
func (s *Server) seoLinksPage(w http.ResponseWriter, r *http.Request) {
data, cur := s.seoBase(r)
data["Path"] = "/seo/links"
data["Plausible"] = s.plausible() != nil
if cur != nil {
if p, _ := profile.Load(s.DB); p != nil {
for _, web := range p.Websites {
if web.URL != cur.URL {
continue
}
list, ok, err := tracking.Referrers(s.DB, web, linkDays)
if err != nil {
s.serverError(w, err)
return
}
data["Read"] = ok
var links []tracking.Referrer
others := map[string]int{}
for _, ref := range list {
if ref.Kind == tracking.RefLink {
links = append(links, ref)
} else {
others[ref.Kind] += ref.Visitors
}
}
data["Links"], data["Others"] = links, others
}
}
var known int
_ = s.DB.QueryRow(`SELECT count(*) FROM backlinks WHERE site = ?`, cur.URL).Scan(&known)
data["Known"] = known
}
last, _ := tracking.Last(s.DB, "referrers")
data["Last"] = last
s.render(w, r, "seo-links", page{Title: "Links", Nav: "seo/links", Data: data})
}