Phase 3 part 4: changes approved one at a time, as Gitea pull requests
Proposals (at most 3 waiting) for pages on page one without clicks and for the audit's title and description issues: the AI writes the title (without the site's suffix, within the pixel budget) and description from the live page and its searches. A yes syncs a working copy of the site's Gitea repository (token as a header only), finds the page's Hugo content file, sets title and description in its front matter, builds with Hugo to check the page comes out as proposed, pushes a branch and opens a pull request; it never merges. Merged changes are checked on the live site, then compared before and after from Search Console. Hugo is in the image. Schema 15. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,292 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"supermarket/internal/api/gitea"
|
||||
"supermarket/internal/profile"
|
||||
"supermarket/internal/secrets"
|
||||
"supermarket/internal/seo"
|
||||
)
|
||||
|
||||
var giteaToken = secretField{"gitea", secrets.GiteaToken, "Gitea access token",
|
||||
"In Gitea: Settings → Applications → Generate new token, with read and write access to repositories. Supermarket pushes a branch and opens a pull request; it never merges.", ""}
|
||||
|
||||
const giteaURLKey = "seo:gitea-url"
|
||||
|
||||
// giteaURL is Gitea's address: the saved one, or the Core's.
|
||||
func (s *Server) giteaURL() string {
|
||||
var u string
|
||||
if _, err := s.DB.GetJSON(giteaURLKey, &u); err == nil && u != "" {
|
||||
return u
|
||||
}
|
||||
if s.Core != nil && s.Core.Domain != "" {
|
||||
return "https://gitea." + s.Core.Domain
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (s *Server) gitea() *gitea.Client {
|
||||
tok := s.Secrets.Get(secrets.GiteaToken)
|
||||
if tok == "" || s.giteaURL() == "" {
|
||||
return nil
|
||||
}
|
||||
return gitea.New(s.giteaURL(), tok)
|
||||
}
|
||||
|
||||
// applier is the pull-request maker for a website.
|
||||
func (s *Server) applier(site seoSite) *seo.Applier {
|
||||
p, _ := profile.Load(s.DB)
|
||||
var repo, branch string
|
||||
if p != nil && site.Index < len(p.Websites) {
|
||||
repo, branch = p.Websites[site.Index].Repo, p.Websites[site.Index].Branch
|
||||
}
|
||||
author := "Supermarket <supermarket@localhost>"
|
||||
if s.Core != nil && s.Core.Email != "" {
|
||||
name := s.Core.Name
|
||||
if name == "" {
|
||||
name = "Supermarket"
|
||||
} else {
|
||||
name += " (via Supermarket)"
|
||||
}
|
||||
author = name + " <" + s.Core.Email + ">"
|
||||
}
|
||||
return &seo.Applier{Gitea: s.gitea(), Repo: repo, Branch: branch, ReposDir: filepath.Join(s.DataDir, "sites"), Author: author}
|
||||
}
|
||||
|
||||
func (s *Server) proposer() (*seo.Proposer, error) {
|
||||
c, p, err := s.draftClient()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &seo.Proposer{AI: c, Profile: p, Fetcher: seo.NewFetcher("Supermarket/" + s.Version + " (SEO)")}, nil
|
||||
}
|
||||
|
||||
// siteFor finds a change's website among the profile's.
|
||||
func (s *Server) siteFor(url string) (seoSite, bool) {
|
||||
for _, st := range s.seoSites() {
|
||||
if st.URL == url || strings.TrimRight(st.URL, "/") == strings.TrimRight(url, "/") {
|
||||
return st, true
|
||||
}
|
||||
}
|
||||
return seoSite{}, false
|
||||
}
|
||||
|
||||
type changeView struct {
|
||||
seo.Change
|
||||
Impact *seo.Impact
|
||||
}
|
||||
|
||||
func (s *Server) seoChangesPage(w http.ResponseWriter, r *http.Request) {
|
||||
s.renderChanges(w, r, "")
|
||||
}
|
||||
|
||||
func (s *Server) renderChanges(w http.ResponseWriter, r *http.Request, errMsg string) {
|
||||
sites, cur := s.auditSites(r)
|
||||
data := map[string]any{"Sites": sites, "Current": cur, "Path": "/seo/changes", "Max": seo.MaxWaiting,
|
||||
"Gitea": s.gitea() != nil}
|
||||
if cur != nil {
|
||||
list, err := seo.Changes(s.DB, auditKey(*cur), 100)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
var waiting, going, done []changeView
|
||||
for _, c := range list {
|
||||
v := changeView{Change: c}
|
||||
switch {
|
||||
case c.Status == seo.ChangeProposed:
|
||||
waiting = append(waiting, v)
|
||||
case c.Open() || c.Status == seo.ChangeFailed:
|
||||
going = append(going, v)
|
||||
default:
|
||||
v.Impact, _ = seo.ImpactOf(s.DB, c)
|
||||
done = append(done, v)
|
||||
}
|
||||
}
|
||||
data["Waiting"], data["Going"], data["Done"] = waiting, going, done
|
||||
p, _ := profile.Load(s.DB)
|
||||
data["Repo"] = ""
|
||||
if p != nil && cur.Index < len(p.Websites) {
|
||||
data["Repo"] = p.Websites[cur.Index].Repo
|
||||
}
|
||||
}
|
||||
s.render(w, r, "seo-changes", page{Title: "Changes", Nav: "seo/changes", Error: errMsg, Data: data})
|
||||
}
|
||||
|
||||
// auditKey is how audits and changes name a website.
|
||||
func auditKey(st seoSite) string { return st.URL }
|
||||
|
||||
// seoChangesSuggest proposes changes until 3 wait for a yes.
|
||||
func (s *Server) seoChangesSuggest(w http.ResponseWriter, r *http.Request) {
|
||||
_, cur := s.auditSites(r)
|
||||
if cur == nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
pr, err := s.proposer()
|
||||
if err == nil {
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 5*time.Minute)
|
||||
defer cancel()
|
||||
_, err = pr.SuggestChanges(ctx, s.DB, auditKey(*cur), cur.Property, time.Now())
|
||||
}
|
||||
if err != nil {
|
||||
s.renderChanges(w, r, "Couldn't propose changes: "+err.Error())
|
||||
return
|
||||
}
|
||||
redirect(w, r, "/seo/changes?site="+strconv.Itoa(cur.Index), "proposed")
|
||||
}
|
||||
|
||||
// seoChangeForPage proposes a change for one page (from the audit or What
|
||||
// ranks).
|
||||
func (s *Server) seoChangeForPage(w http.ResponseWriter, r *http.Request) {
|
||||
_, cur := s.auditSites(r)
|
||||
if cur == nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
page := r.PostFormValue("page")
|
||||
if !strings.HasPrefix(page, "http") {
|
||||
http.Error(w, "no page", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
c := seo.Candidate{Page: page, Why: r.PostFormValue("why"), Title: r.PostFormValue("what") != "description", Desc: r.PostFormValue("what") != "title"}
|
||||
if c.Why == "" {
|
||||
c.Why = "Asked for by you."
|
||||
}
|
||||
pr, err := s.proposer()
|
||||
if err == nil {
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 3*time.Minute)
|
||||
defer cancel()
|
||||
_, err = pr.Propose(ctx, s.DB, auditKey(*cur), cur.Property, c, time.Now())
|
||||
}
|
||||
if err != nil {
|
||||
s.renderChanges(w, r, "Couldn't propose a change: "+err.Error())
|
||||
return
|
||||
}
|
||||
redirect(w, r, "/seo/changes?site="+strconv.Itoa(cur.Index), "proposed")
|
||||
}
|
||||
|
||||
// seoChangeAction handles a change's buttons: save (edit the wording),
|
||||
// yes, no.
|
||||
func (s *Server) seoChangeAction(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
c, err := seo.GetChange(s.DB, id)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
site, ok := s.siteFor(c.Site)
|
||||
if !ok {
|
||||
s.renderChanges(w, r, "That change's website is no longer in the profile.")
|
||||
return
|
||||
}
|
||||
back := "/seo/changes?site=" + strconv.Itoa(site.Index)
|
||||
if _, has := r.PostForm["new_title"]; has && c.Status == seo.ChangeProposed {
|
||||
if err := seo.EditChange(s.DB, id, r.PostFormValue("new_title"), r.PostFormValue("new_description")); err != nil {
|
||||
s.renderChanges(w, r, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
var msg string
|
||||
switch r.PathValue("action") {
|
||||
case "save":
|
||||
msg = "saved"
|
||||
case "yes":
|
||||
if s.gitea() == nil {
|
||||
s.renderChanges(w, r, "Save a Gitea token under Settings → Search engines first.")
|
||||
return
|
||||
}
|
||||
if err := seo.Decide(s.DB, id, true, time.Now()); err != nil {
|
||||
s.renderChanges(w, r, err.Error())
|
||||
return
|
||||
}
|
||||
ap := s.applier(site)
|
||||
go func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
|
||||
defer cancel()
|
||||
if err := ap.Apply(ctx, s.DB, id); err != nil {
|
||||
s.Log.Warn("seo: making the pull request", "change", id, "err", err)
|
||||
}
|
||||
}()
|
||||
msg = "approved"
|
||||
case "no":
|
||||
if err := seo.Decide(s.DB, id, false, time.Now()); err != nil {
|
||||
s.renderChanges(w, r, err.Error())
|
||||
return
|
||||
}
|
||||
msg = "declined"
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
redirect(w, r, back, msg)
|
||||
}
|
||||
|
||||
// refreshChanges follows pull requests and checks merged changes on the
|
||||
// live site.
|
||||
func (s *Server) refreshChanges(ctx context.Context) {
|
||||
if err := seo.Refresh(ctx, s.DB, s.gitea(), seo.NewFetcher("Supermarket/"+s.Version+" (SEO)"), time.Now()); err != nil {
|
||||
s.Log.Warn("seo: following changes", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
// testGitea checks the token.
|
||||
func (s *Server) testGitea(ctx context.Context) map[string]any {
|
||||
g := s.gitea()
|
||||
if g == nil {
|
||||
return map[string]any{"Error": "Save the token first."}
|
||||
}
|
||||
who, err := g.Me(ctx)
|
||||
if err != nil {
|
||||
return map[string]any{"Error": err.Error()}
|
||||
}
|
||||
out := "The token works, as " + who + "."
|
||||
var bad []string
|
||||
for _, st := range s.seoSites() {
|
||||
p, _ := profile.Load(s.DB)
|
||||
repo := ""
|
||||
if p != nil && st.Index < len(p.Websites) {
|
||||
repo = p.Websites[st.Index].Repo
|
||||
}
|
||||
if repo == "" {
|
||||
bad = append(bad, st.URL+": no repository in the profile")
|
||||
continue
|
||||
}
|
||||
_, full, err := gitea.ParseRepo(repo)
|
||||
if err == nil {
|
||||
var rp *gitea.Repo
|
||||
if rp, err = g.GetRepo(ctx, full); err == nil && !rp.Permissions.Push {
|
||||
err = errors.New("the token can't push to it")
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
bad = append(bad, st.URL+": "+err.Error())
|
||||
} else {
|
||||
out += " " + full + " is reachable."
|
||||
}
|
||||
}
|
||||
res := map[string]any{"OK": out}
|
||||
if len(bad) > 0 {
|
||||
res["Error"] = strings.Join(bad, "; ")
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"supermarket/internal/ai"
|
||||
"supermarket/internal/profile"
|
||||
"supermarket/internal/secrets"
|
||||
"supermarket/internal/seo"
|
||||
)
|
||||
|
||||
func TestChangesPage(t *testing.T) {
|
||||
newAIClient = func(ai.Config, *secrets.Store) (ai.Client, error) {
|
||||
return cannedAI{`{"title":"Plans and prices","description":"Every plan, what it costs, and what's included, per month."}`}, nil
|
||||
}
|
||||
defer func() { newAIClient = ai.New }()
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
fmt.Fprint(w, `<html><head><title>Pricing · Us</title></head><body><h1>Pricing</h1><p>Plans and prices.</p></body></html>`)
|
||||
}))
|
||||
defer srv.Close()
|
||||
s, h := newTestServer(t, nil)
|
||||
profile.Save(s.DB, &profile.Profile{Name: "Us", Websites: []profile.Website{{URL: srv.URL}}})
|
||||
|
||||
body := do(h, http.MethodGet, "/seo/changes", nil, nil).Body.String()
|
||||
for _, want := range []string{"Nothing waiting", "save a Gitea token", "set this website's Hugo repository"} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("empty page lacks %q", want)
|
||||
}
|
||||
}
|
||||
rec := postForm(h, "/seo/changes/page?site=0", url.Values{"page": {srv.URL + "/pricing/"}, "why": {"Title too long."}})
|
||||
if rec.Code != http.StatusSeeOther {
|
||||
t.Fatalf("propose: %d %s", rec.Code, rec.Body)
|
||||
}
|
||||
body = do(h, http.MethodGet, "/seo/changes", nil, nil).Body.String()
|
||||
for _, want := range []string{`value="Plans and prices · Us"`, "now: “Pricing · Us”", "Title too long.", "Yes: open a pull request"} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("proposal lacks %q", want)
|
||||
}
|
||||
}
|
||||
cs, _ := seo.Changes(s.DB, srv.URL, 10)
|
||||
id := fmt.Sprint(cs[0].ID)
|
||||
postForm(h, "/seo/changes/"+id+"/save", url.Values{"new_title": {"Plans and prices from $5 · Us"}, "new_description": {"Edited."}})
|
||||
if c, _ := seo.GetChange(s.DB, cs[0].ID); c.NewTitle != "Plans and prices from $5 · Us" || c.NewDescription != "Edited." {
|
||||
t.Errorf("edit: %+v", c)
|
||||
}
|
||||
if rec := postForm(h, "/seo/changes/"+id+"/yes", nil); !strings.Contains(rec.Body.String(), "Save a Gitea token") {
|
||||
t.Errorf("yes without Gitea: %d", rec.Code)
|
||||
}
|
||||
postForm(h, "/seo/changes/"+id+"/no", nil)
|
||||
if c, _ := seo.GetChange(s.DB, cs[0].ID); c.Status != seo.ChangeDeclined {
|
||||
t.Errorf("no: %+v", c.Status)
|
||||
}
|
||||
if body := do(h, http.MethodGet, "/seo/changes", nil, nil).Body.String(); !strings.Contains(body, "You said no") {
|
||||
t.Error("declined change isn't listed")
|
||||
}
|
||||
// Gitea settings.
|
||||
postForm(h, "/settings/search", url.Values{"gitea_url": {"https://gitea.example.com/"}, secrets.GiteaToken: {"tok"}})
|
||||
if s.giteaURL() != "https://gitea.example.com" || s.gitea() == nil {
|
||||
t.Errorf("gitea settings: %q", s.giteaURL())
|
||||
}
|
||||
}
|
||||
+25
-1
@@ -114,6 +114,9 @@ func (s *Server) renderSearchSettings(w http.ResponseWriter, r *http.Request, er
|
||||
data := map[string]any{
|
||||
"Fields": googleFields,
|
||||
"Speed": pageSpeedKey,
|
||||
"GiteaKey": giteaToken,
|
||||
"GiteaSet": s.Secrets.Has(secrets.GiteaToken),
|
||||
"GiteaURL": s.giteaURL(),
|
||||
"SpeedSet": s.Secrets.Has(secrets.PageSpeedAPIKey),
|
||||
"Set": s.secretState(secrets.GoogleClientID, secrets.GoogleClientSecret, secrets.GoogleRefreshToken),
|
||||
"Redirect": s.callbackURL("google"),
|
||||
@@ -139,7 +142,7 @@ func (s *Server) searchSettingsSave(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err := s.saveSecrets(r, append(googleFields, pageSpeedKey)); err != nil {
|
||||
if err := s.saveSecrets(r, append(googleFields, pageSpeedKey, giteaToken)); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
@@ -152,6 +155,17 @@ func (s *Server) searchSettingsSave(w http.ResponseWriter, r *http.Request) {
|
||||
gauth.token = ""
|
||||
gauth.mu.Unlock()
|
||||
}
|
||||
if _, has := r.PostForm["gitea_url"]; has {
|
||||
u := strings.TrimRight(strings.TrimSpace(r.PostFormValue("gitea_url")), "/")
|
||||
if u != "" && !strings.HasPrefix(u, "https://") && !strings.HasPrefix(u, "http://") {
|
||||
s.renderSearchSettings(w, r, "Gitea's address must start with https://")
|
||||
return
|
||||
}
|
||||
if err := s.DB.PutJSON(giteaURLKey, u); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
if _, has := r.PostForm["min_clicks"]; has {
|
||||
f := r.PostFormValue
|
||||
clicks, _ := strconv.Atoi(f("min_clicks"))
|
||||
@@ -226,6 +240,9 @@ func (s *Server) RunSEO(ctx context.Context) {
|
||||
if err := seo.RecoverAudits(s.DB); err != nil {
|
||||
s.Log.Error("seo: recovering audits", "err", err)
|
||||
}
|
||||
if err := seo.RecoverChanges(s.DB); err != nil {
|
||||
s.Log.Error("seo: recovering changes", "err", err)
|
||||
}
|
||||
tick := time.NewTicker(30 * time.Minute)
|
||||
defer tick.Stop()
|
||||
for {
|
||||
@@ -246,6 +263,7 @@ func (s *Server) RunSEO(ctx context.Context) {
|
||||
}
|
||||
s.weeklyReports(ctx, time.Now())
|
||||
}
|
||||
s.refreshChanges(ctx)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
@@ -577,3 +595,9 @@ func (s *Server) weeklyAudits(now time.Time) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) giteaTest(w http.ResponseWriter, r *http.Request) {
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)
|
||||
defer cancel()
|
||||
s.fragment(w, "sources", "test-result", s.testGitea(ctx))
|
||||
}
|
||||
|
||||
@@ -161,6 +161,11 @@ func (s *Server) Handler() (http.Handler, error) {
|
||||
mux.HandleFunc("POST /settings/email/send-test", s.emailSendTest)
|
||||
mux.HandleFunc("GET /seo", s.seoPage)
|
||||
mux.HandleFunc("GET /seo/check", s.seoCheckPage)
|
||||
mux.HandleFunc("GET /seo/changes", s.seoChangesPage)
|
||||
mux.HandleFunc("POST /seo/changes/suggest", s.seoChangesSuggest)
|
||||
mux.HandleFunc("POST /seo/changes/page", s.seoChangeForPage)
|
||||
mux.HandleFunc("POST /seo/changes/{id}/{action}", s.seoChangeAction)
|
||||
mux.HandleFunc("POST /settings/search/test/gitea", s.giteaTest)
|
||||
mux.HandleFunc("GET /seo/audit", s.seoAuditPage)
|
||||
mux.HandleFunc("POST /seo/audit", s.seoAuditRun)
|
||||
mux.HandleFunc("GET /seo/audit/status", s.seoAuditStatus)
|
||||
@@ -413,6 +418,9 @@ var flashes = map[string]string{
|
||||
"google-connected": "Search Console is connected. Choose each website's property below, then sync.",
|
||||
"synced": "Synced from Search Console.",
|
||||
"report-written": "This week's report is written.",
|
||||
"proposed": "Proposed: read each one, edit it if you like, then say yes or no.",
|
||||
"approved": "Approved: Supermarket is making the pull request; it shows here in a minute.",
|
||||
"declined": "Declined.",
|
||||
"auditing": "Auditing. It reads up to 300 pages politely, so it takes a few minutes; this page updates when it's done.",
|
||||
"no-data": "There isn't two weeks of Search Console data yet.",
|
||||
"reddit-connected": "Reddit is connected.",
|
||||
|
||||
@@ -100,7 +100,7 @@ func TestEveryPageRenders(t *testing.T) {
|
||||
"/settings/ai", "/settings/accounts", "/settings/core", "/static/app.css", "/favicon.ico", "/static/favicon.png", "/static/logo.png", "/static/apple-touch-icon.png", "/search", "/crm", "/search?q=rival", "/search?q=nothing+here", "/static/htmx.min.js", "/healthz",
|
||||
"/content", "/content/1", "/content/1?dismissed=1", "/posts", "/posts?msg=drafted",
|
||||
"/content/scheduled", "/content/published",
|
||||
"/prospects", "/prospects?status=accepted", "/prospects?status=rejected", "/prospects/new", "/prospects/suppressed", "/outreach", "/outreach?tab=queued", "/outreach?tab=sent", "/outreach?tab=replied", "/outreach?tab=failed", "/settings/email", "/settings/tracking", "/settings/search", "/seo", "/seo/check", "/seo/report", "/seo/audit",
|
||||
"/prospects", "/prospects?status=accepted", "/prospects?status=rejected", "/prospects/new", "/prospects/suppressed", "/outreach", "/outreach?tab=queued", "/outreach?tab=sent", "/outreach?tab=replied", "/outreach?tab=failed", "/settings/email", "/settings/tracking", "/settings/search", "/seo", "/seo/check", "/seo/report", "/seo/audit", "/seo/changes",
|
||||
"/signals", "/signals?period=30d&channel=email", "/signals/new", "/settings/sources"} {
|
||||
rec := do(h, http.MethodGet, path, nil, nil)
|
||||
if rec.Code != http.StatusOK {
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
<a href="/seo/check" {{if eq $nav "seo/check"}}aria-current="page"{{end}}>Morning check</a>
|
||||
<a href="/seo/report" {{if eq $nav "seo/report"}}aria-current="page"{{end}}>Monday report</a>
|
||||
<a href="/seo" {{if eq $nav "seo/ranks"}}aria-current="page"{{end}}>What ranks</a>
|
||||
<a href="/seo/changes" {{if eq $nav "seo/changes"}}aria-current="page"{{end}}>Changes</a>
|
||||
<a href="/seo/audit" {{if eq $nav "seo/audit"}}aria-current="page"{{end}}>Audit</a>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
@@ -34,6 +34,18 @@
|
||||
</section>
|
||||
{{end}}
|
||||
|
||||
<section class="card" id="gitea">
|
||||
<h3>Gitea: your sites' repositories</h3>
|
||||
<p class="small">For changes you approve: Supermarket pushes a branch to the website's Hugo repository (set in the <a href="/settings/profile">profile</a>) and opens a pull request. It never merges.</p>
|
||||
<label>Gitea's address <input name="gitea_url" value="{{.GiteaURL}}" placeholder="https://gitea.example.com"></label>
|
||||
{{template "key-field" (dict "F" .GiteaKey "Set" .GiteaSet)}}
|
||||
{{if .GiteaSet}}
|
||||
<button type="button" class="secondary small" hx-post="/settings/search/test/gitea" hx-target="#test-gitea" hx-indicator="#testing-gitea">Test</button>
|
||||
<span id="testing-gitea" class="htmx-indicator">Checking…</span>
|
||||
<div id="test-gitea"></div>
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
{{if .Connected}}{{$s := .SEO}}
|
||||
<section class="card">
|
||||
<h3>The morning check and the Monday report</h3>
|
||||
|
||||
@@ -62,7 +62,11 @@
|
||||
<thead><tr><th></th><th>Issue</th><th>Page</th><th class="num">Clicks</th><th class="num">Impressions</th></tr></thead>
|
||||
<tbody>{{range $d.Shown}}<tr>
|
||||
<td><span class="badge {{if eq .Severity "error"}}failed{{else if eq .Severity "warning"}}scheduled{{end}}">{{.Severity}}</span></td>
|
||||
<td><strong>{{.Title}}</strong>{{with .Detail}}<br><span class="small">{{truncate 400 .}}</span>{{end}}</td>
|
||||
<td><strong>{{.Title}}</strong>{{with .Detail}}<br><span class="small">{{truncate 400 .}}</span>{{end}}
|
||||
{{if or (hasPrefix .Code "title-") (hasPrefix .Code "description-")}}<form method="post" action="/seo/changes/page?site={{$d.Current.Index}}" class="inline" data-busy="Writing…">
|
||||
<input type="hidden" name="page" value="{{.Page}}"><input type="hidden" name="why" value="{{.Title}}. {{.Detail}}">
|
||||
<input type="hidden" name="what" value="{{if hasPrefix .Code "title-"}}title{{else}}description{{end}}">
|
||||
<button type="submit" class="link small">Propose a fix</button></form>{{end}}</td>
|
||||
<td class="small"><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a></td>
|
||||
<td class="num">{{if .Traffic.Impressions}}{{num .Traffic.Clicks}}{{else}}<span class="muted">·</span>{{end}}</td>
|
||||
<td class="num">{{if .Traffic.Impressions}}{{num .Traffic.Impressions}}{{else}}<span class="muted">·</span>{{end}}</td>
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
{{define "content"}}{{with .Data}}{{$d := .}}
|
||||
<div class="heading">
|
||||
<h1>Changes</h1>
|
||||
{{if .Current}}<div class="buttons">
|
||||
<form method="post" action="/seo/changes/suggest?site={{.Current.Index}}" data-busy="Writing…"><button type="submit" class="secondary">Propose changes</button></form>
|
||||
</div>{{end}}
|
||||
</div>
|
||||
<p class="lede">Each change is one page's new title or description, with the number that pays for it. Say yes or no, one at a time: a yes opens a pull request on the site's Gitea repository, checked with a Hugo build. Nothing is published until you merge it. Then Supermarket checks the live page and compares the page's Search Console numbers before and after.</p>
|
||||
|
||||
{{if not .Sites}}
|
||||
<section class="card empty"><p>Add your websites to the <a href="/settings/profile">profile</a> first.</p></section>
|
||||
{{else}}
|
||||
{{if gt (len .Sites) 1}}<nav class="tabs">{{range .Sites}}<a href="/seo/changes?site={{.Index}}" {{if eq .Index $d.Current.Index}}aria-current="page"{{end}}>{{.URL}}</a>{{end}}</nav>{{end}}
|
||||
|
||||
{{if or (not .Gitea) (not .Repo)}}
|
||||
<section class="card"><p class="warn-text">Before a yes can open a pull request: {{if not .Gitea}}save a Gitea token under <a href="/settings/search">Settings → Search engines</a>{{end}}{{if and (not .Gitea) (not .Repo)}}, and {{end}}{{if not .Repo}}set this website's Hugo repository in the <a href="/settings/profile">profile</a>{{end}}. You can propose and read changes already.</p></section>
|
||||
{{end}}
|
||||
|
||||
<h2>Waiting for your yes <span class="muted small">at most {{.Max}}</span></h2>
|
||||
{{range .Waiting}}
|
||||
<section class="card" id="c-{{.ID}}">
|
||||
<p><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a></p>
|
||||
<p class="small">{{.Why}}</p>
|
||||
<form method="post" action="/seo/changes/{{.ID}}/save">
|
||||
{{if .NewTitle}}
|
||||
<label>Title <span class="muted small">now: “{{.CurTitle}}”</span>
|
||||
<input name="new_title" value="{{.NewTitle}}">
|
||||
<span class="help">{{.NewTitleChars}} characters, about {{.NewTitlePixels}} px{{if gt .NewTitlePixels 600}}: <span class="warn-text">Google cuts titles off around 600 px</span>{{end}}.</span></label>
|
||||
{{else}}<input type="hidden" name="new_title" value="">{{end}}
|
||||
{{if .NewDescription}}
|
||||
<label>Description <span class="muted small">now: {{if .CurDescription}}“{{.CurDescription}}”{{else}}none{{end}}</span>
|
||||
<textarea name="new_description" rows="3">{{.NewDescription}}</textarea>
|
||||
<span class="help">{{.NewDescriptionChars}} characters, about {{.NewDescriptionPixels}} px{{if gt .NewDescriptionPixels 920}}: <span class="warn-text">Google cuts descriptions off around 920 px</span>{{end}}.</span></label>
|
||||
{{else}}<input type="hidden" name="new_description" value="">{{end}}
|
||||
<div class="actions">
|
||||
<button type="submit" formaction="/seo/changes/{{.ID}}/yes" data-busy="Approving…">Yes: open a pull request</button>
|
||||
<button type="submit" class="secondary">Save the wording</button>
|
||||
<button type="submit" class="secondary" formaction="/seo/changes/{{.ID}}/no">No</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
{{else}}
|
||||
<section class="card empty"><p>Nothing waiting. <em>Propose changes</em> writes up to {{.Max}}, for the pages on page one that aren't clicked and the audit's title and description issues.</p></section>
|
||||
{{end}}
|
||||
|
||||
{{if .Going}}
|
||||
<h2>Under way</h2>
|
||||
<table class="list">
|
||||
<thead><tr><th>Page</th><th>Change</th><th>Status</th></tr></thead>
|
||||
<tbody>{{range .Going}}<tr id="c-{{.ID}}">
|
||||
<td><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a></td>
|
||||
<td class="small">{{with .NewTitle}}Title: “{{.}}”<br>{{end}}{{with .NewDescription}}Description: “{{truncate 120 .}}”{{end}}</td>
|
||||
<td>{{if eq .Status "applying"}}<span class="badge scheduled">making the pull request…</span>
|
||||
{{else if eq .Status "pr"}}<a class="badge" href="{{.PRURL}}" target="_blank" rel="noopener noreferrer">pull request #{{.PRNumber}} open ↗</a><br><span class="small muted">{{.Note}}</span>
|
||||
{{else if eq .Status "merged"}}<span class="badge">merged {{ago .MergedAt}}</span><br><span class="small muted">waiting to see it on the live site</span>
|
||||
{{else if eq .Status "failed"}}<span class="badge failed">failed</span> <span class="small">{{.Error}}</span>
|
||||
<form method="post" action="/seo/changes/{{.ID}}/yes" class="inline"><button type="submit" class="link small">Try again</button></form>{{end}}
|
||||
{{with .Diff}}<details class="small"><summary>The diff</summary><pre class="sample">{{.}}</pre></details>{{end}}</td>
|
||||
</tr>{{end}}</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
|
||||
{{if .Done}}
|
||||
<h2>Done</h2>
|
||||
<table class="list">
|
||||
<thead><tr><th>Page</th><th>Change</th><th>Before → after</th></tr></thead>
|
||||
<tbody>{{range .Done}}<tr>
|
||||
<td><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a></td>
|
||||
<td class="small">{{with .NewTitle}}Title: “{{.}}”<br>{{end}}{{with .NewDescription}}Description: “{{truncate 120 .}}”{{end}}</td>
|
||||
<td class="small">{{if eq .Status "live"}}Live since {{ago .LiveAt}}.
|
||||
{{with .Impact}}<br>{{.Days}} days each side: clicks <strong>{{num .Before.Clicks}} → {{num .After.Clicks}}</strong>, impressions {{num .Before.Impressions}} → {{num .After.Impressions}}, click rate {{dec1 .Before.CTR}}% → {{dec1 .After.CTR}}%, position {{dec1 .Before.Position}} → {{dec1 .After.Position}}. Correlation, not proof; a title shows its effect in one to two weeks.{{else}}<br><span class="muted">The numbers after need 3 days of final Search Console data.</span>{{end}}
|
||||
{{else if eq .Status "declined"}}<span class="muted">You said no {{ago .DecidedAt}}.</span>
|
||||
{{else if eq .Status "closed"}}<span class="muted">The pull request was closed without merging.</span>{{end}}</td>
|
||||
</tr>{{end}}</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{end}}{{end}}
|
||||
@@ -34,7 +34,7 @@
|
||||
{{range .Waiting}}
|
||||
<p><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a><br><span class="small">{{.Why}}</span></p>
|
||||
{{else}}<p class="help">Nothing this week.</p>{{end}}
|
||||
<p class="help">Each one is a page that ranks on page one and isn't clicked. The exact change to make (a new title or description, with its length) and the pull request that applies it come with the next part.</p>
|
||||
<p class="help">Say yes or no to each on <a href="/seo/changes?site={{$d.Current.Index}}">Changes</a>: a yes opens a pull request.</p>
|
||||
</section>
|
||||
{{else}}
|
||||
<section class="card empty"><p>No report yet. It's written on Monday once there are two weeks of data, or now with <em>Write it now</em>.</p></section>
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
<section class="card">
|
||||
<h2>Push</h2>
|
||||
<p class="help">On page one, shown a lot, hardly clicked: Google did the hard part, and the page loses at the click. Compare its main query with its title first.</p>
|
||||
{{range .Push}}<p><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a><br><span class="small">{{.Why}}</span></p>{{else}}<p class="help">No page sits on page one with few clicks. Good, or too little data.</p>{{end}}
|
||||
{{range .Push}}<p><a href="{{.Page}}" target="_blank" rel="noopener noreferrer">{{pagePath .Page}}</a><br><span class="small">{{.Why}}</span>
|
||||
<form method="post" action="/seo/changes/page?site={{$d.Current.Index}}" class="inline" data-busy="Writing…"><input type="hidden" name="page" value="{{.Page}}"><input type="hidden" name="why" value="{{.Why}}"><button type="submit" class="link small">Propose a new title and description</button></form></p>{{else}}<p class="help">No page sits on page one with few clicks. Good, or too little data.</p>{{end}}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user