feat: noindex paths from the route report leave the sitemaps (tracer)
The route report takes an optional noindex list of static paths. When the key is present the stored set (golem15_seo_noindex_paths) is replaced, and the sitemap filter leaves those paths out with the reason noindex; a changed set asks the sitemap for a debounced rebuild through contract.Rebuilder. A listed noindex address without a CMS record now names sitemap_update_settings, or fix: code without the sitemap plugin.
This commit is contained in:
@@ -127,6 +127,11 @@ type Env struct {
|
||||
GenericAnchors []string
|
||||
// Keyphrases maps an address to its SEO entry's focus keyphrase.
|
||||
Keyphrases map[string]string
|
||||
// SitemapTool is the tool that edits the sitemap's Additional
|
||||
// addresses (ToolSitemapSettings while the sitemap plugin is mounted,
|
||||
// else ""): a listed noindex address without a CMS record is one of
|
||||
// them.
|
||||
SitemapTool string
|
||||
}
|
||||
|
||||
func (e *Env) record(key string) *Record {
|
||||
@@ -330,6 +335,24 @@ func hasEmptyHeading(rec *Record, level int) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// sitemapNoindex is the finding of a listed noindex page. A CMS record's
|
||||
// page is fixed with seo_set_url_seo; an address without a record is an
|
||||
// Additional address of the sitemap (or another listed address the SEO
|
||||
// plugin cannot change), fixed by removing it from the sitemap's address
|
||||
// list: env.SitemapTool, else fix code naming that list.
|
||||
func sitemapNoindex(key, file string, rec *Record, env *Env) Finding {
|
||||
f := Finding{Kind: KindSitemapNoindex, URL: key, Locale: locale(rec), Record: rec, Details: map[string]any{"file": file}}
|
||||
if rec != nil {
|
||||
f.Tool = ToolSetURLSEO
|
||||
return f
|
||||
}
|
||||
f.Details["extra"] = true
|
||||
if env != nil {
|
||||
f.Tool = env.SitemapTool
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
// checkSitemaps compares the sitemaps with what the crawl found:
|
||||
// sitemap_error for a listed address that does not answer 200,
|
||||
// sitemap_noindex for a listed noindex page, sitemap_blocked for a listed
|
||||
@@ -352,7 +375,7 @@ func checkSitemaps(res *Result, env *Env) []Finding {
|
||||
case p.Resp.Err != "" || p.Resp.Status != 200:
|
||||
out = append(out, Finding{Kind: KindSitemapError, URL: key, Locale: locale(rec), Record: rec, Tool: ToolSetURLSEO, Details: map[string]any{"status": p.Resp.Status, "file": file}})
|
||||
case env.noindex(p):
|
||||
out = append(out, Finding{Kind: KindSitemapNoindex, URL: key, Locale: locale(rec), Record: rec, Tool: ToolSetURLSEO, Details: map[string]any{"file": file}})
|
||||
out = append(out, sitemapNoindex(key, file, rec, env))
|
||||
}
|
||||
}
|
||||
if robots != "" && res.fetcher != nil {
|
||||
|
||||
@@ -203,3 +203,50 @@ func TestEnvNoindex(t *testing.T) {
|
||||
t.Fatal("nil env and record helpers")
|
||||
}
|
||||
}
|
||||
|
||||
// TestSitemapNoindexTool pins G1 (SC-3, D-14): a listed noindex page with
|
||||
// a CMS record names seo_set_url_seo; one without a record (an Additional
|
||||
// address of the sitemap) names the sitemap's settings tool while the
|
||||
// sitemap plugin is mounted, and fix: code naming the sitemap's address
|
||||
// list otherwise.
|
||||
func TestSitemapNoindexTool(t *testing.T) {
|
||||
res := &Result{
|
||||
Pages: map[string]*Page{
|
||||
"/cms": okPage("/cms", &PageFacts{Robots: "noindex"}),
|
||||
"/extra": okPage("/extra", &PageFacts{Robots: "noindex"}),
|
||||
},
|
||||
Listed: map[string]string{"/cms": "/sitemap-pages-1.xml", "/extra": "/sitemap-pages-1.xml"},
|
||||
}
|
||||
rec := &Record{Type: "seo-page", ID: "1"}
|
||||
lookup := func(key string) *Record {
|
||||
if key == "/cms" {
|
||||
return rec
|
||||
}
|
||||
return nil
|
||||
}
|
||||
find := func(env *Env, key string) Finding {
|
||||
t.Helper()
|
||||
for _, f := range checkSitemaps(res, env) {
|
||||
if f.Kind == KindSitemapNoindex && f.URL == key {
|
||||
return f
|
||||
}
|
||||
}
|
||||
t.Fatalf("no sitemap_noindex on %s", key)
|
||||
return Finding{}
|
||||
}
|
||||
mounted := &Env{Lookup: lookup, SitemapTool: ToolSitemapSettings}
|
||||
if fix, tool, _ := Route(find(mounted, "/cms")); fix != models.FixTool || tool != ToolSetURLSEO {
|
||||
t.Fatalf("CMS record: %s %q", fix, tool)
|
||||
}
|
||||
extra := find(mounted, "/extra")
|
||||
if fix, tool, _ := Route(extra); fix != models.FixTool || tool != "sitemap_update_settings" || extra.Details["extra"] != true {
|
||||
t.Fatalf("Additional address with the sitemap mounted: %s %q %v", fix, tool, extra.Details)
|
||||
}
|
||||
if _, ok := find(mounted, "/cms").Details["extra"]; ok {
|
||||
t.Fatal("a CMS record's finding is marked extra")
|
||||
}
|
||||
alone := &Env{Lookup: lookup}
|
||||
if fix, tool, what := Route(find(alone, "/extra")); fix != models.FixCode || tool != "" || what != "the address list of the sitemap that names this page" {
|
||||
t.Fatalf("Additional address without the sitemap: %s %q %q", fix, tool, what)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ const (
|
||||
ToolUpdatePage = "seo_update_page"
|
||||
ToolCreatePage = "seo_create_page"
|
||||
ToolUpdateSettings = "seo_update_settings"
|
||||
// ToolSitemapSettings is the sitemap plugin's settings tool, which
|
||||
// edits its Additional addresses.
|
||||
ToolSitemapSettings = "sitemap_update_settings"
|
||||
)
|
||||
|
||||
// Record is the CMS record behind a crawled page: its content type, id
|
||||
@@ -132,6 +135,7 @@ var defaultWhat = map[string]string{
|
||||
KindGenericAnchor: "the link text in the page template",
|
||||
KindRedirectedLink: "the link in the page template",
|
||||
KindOrphanPage: "a link to this page from the site navigation or another page",
|
||||
KindSitemapNoindex: "the address list of the sitemap that names this page",
|
||||
}
|
||||
|
||||
// Fingerprint identifies a finding across crawls: the kind, the address,
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"git.golem15.com/golem15/sm-seo-plugin/classes"
|
||||
"git.golem15.com/golem15/sm-seo-plugin/classes/schema"
|
||||
"git.golem15.com/golem15/sm-seo-plugin/models"
|
||||
"git.golem15.com/golem15/sm-sitemap-plugin/contract"
|
||||
"git.golem15.com/golem15/summercms/modules/conga"
|
||||
"git.golem15.com/golem15/summercms/modules/diary"
|
||||
"git.golem15.com/golem15/summercms/modules/lagoon"
|
||||
@@ -16,6 +17,20 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// SitemapTool is ToolSitemapSettings while the application publishes the
|
||||
// sitemap plugin's contract.Listing (the sitemap plugin is mounted), else
|
||||
// "".
|
||||
func SitemapTool(svc *classes.Service) string {
|
||||
app := svc.App()
|
||||
if app == nil {
|
||||
return ""
|
||||
}
|
||||
if _, ok := app.Lookup[contract.Listing](); ok {
|
||||
return ToolSitemapSettings
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// CrawlKind is the River kind of the crawl job.
|
||||
const CrawlKind = "golem15.seo.crawl"
|
||||
|
||||
@@ -264,7 +279,7 @@ func finish(ctx context.Context, svc *classes.Service, db *gorm.DB, row models.C
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
findings := Check(res, &Env{Lookup: Lookup(ctx, svc, tx), Staging: svc.Staging(), GenericAnchors: limits.GenericAnchors, Keyphrases: keyphrases})
|
||||
findings := Check(res, &Env{Lookup: Lookup(ctx, svc, tx), Staging: svc.Staging(), GenericAnchors: limits.GenericAnchors, Keyphrases: keyphrases, SitemapTool: SitemapTool(svc)})
|
||||
cms, err := svc.Issues(classes.WithTx(ctx, tx))
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user