Phase 3 part 7: Bing, IndexNow and search engine setup

SEO → Search engines: a pull request that adds the IndexNow key file, a
robots.txt naming the sitemap, and turns the sitemap on when the Hugo
config disables it (checked with a build); IndexNow submissions of pages
that go live through Changes or Briefs once the key file is served; the
sitemaps Search Console has; and, with an API key, Bing's traffic,
searches and crawl issues. NewlyLive no longer queries while a result
set holds the database's only connection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 08:45:13 -07:00
co-authored by Claude Opus 5.5
parent bf933971dd
commit 2302fb0436
18 changed files with 1061 additions and 4 deletions
+60
View File
@@ -0,0 +1,60 @@
package web
import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
"supermarket/internal/profile"
"supermarket/internal/secrets"
"supermarket/internal/seo"
)
func TestEnginesPage(t *testing.T) {
s, h := newTestServer(t, nil)
key, _ := seo.IndexNowKey(s.DB)
site := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/"+key+".txt" {
fmt.Fprint(w, key)
return
}
http.NotFound(w, r)
}))
defer site.Close()
b := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/GetRankAndTrafficStats":
w.Write([]byte(`{"d":[{"Clicks":12,"Impressions":340,"Date":"/Date(1763337600000)/"}]}`))
case "/GetQueryStats":
w.Write([]byte(`{"d":[]}`))
case "/GetCrawlIssues":
w.Write([]byte(`{"d":[{"Url":"https://us.example/old","HttpCode":404}]}`))
}
}))
defer b.Close()
bingBase = b.URL
defer func() { bingBase = "" }()
var pinged string
in := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { pinged = r.URL.Path; w.WriteHeader(200) }))
defer in.Close()
seo.IndexNowURL = in.URL
defer func() { seo.IndexNowURL = "https://api.indexnow.org/indexnow" }()
profile.Save(s.DB, &profile.Profile{Name: "Us", Websites: []profile.Website{{URL: site.URL}}})
postForm(h, "/settings/search", url.Values{secrets.BingAPIKey: {"k"}})
body := do(h, http.MethodGet, "/seo/engines", nil, nil).Body.String()
for _, want := range []string{key, "the site serves it", "340", "https://us.example/old (404)", "Connect Search Console", "Open the pull request"} {
if !strings.Contains(body, want) {
t.Errorf("page lacks %q", want)
}
}
if rec := postForm(h, "/seo/engines/ping?site=0", nil); rec.Code != http.StatusSeeOther || pinged == "" {
t.Errorf("ping: %d %q", rec.Code, pinged)
}
if body := do(h, http.MethodGet, "/seo/engines", nil, nil).Body.String(); !strings.Contains(body, "accepted (200)") {
t.Error("the ping isn't listed")
}
}