seo-supervisor 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/icon.png +0 -0
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +16 -3
- package/CHANGELOG.md +430 -0
- package/NOTICE +7 -0
- package/README.md +230 -25
- package/agents/seo-auditor.md +16 -0
- package/agents/seo-reviewer.md +16 -0
- package/bin/agents.mjs +194 -29
- package/bin/extras.mjs +422 -0
- package/bin/prompt.mjs +34 -14
- package/bin/seo-supervisor.mjs +386 -53
- package/commands/seo-audit.md +29 -3
- package/commands/seo-brief.md +28 -0
- package/commands/seo-connect.md +27 -0
- package/commands/seo-fix.md +24 -3
- package/commands/seo-grow.md +26 -0
- package/commands/seo-launch.md +17 -3
- package/commands/seo-review.md +13 -1
- package/commands/seo-rewrite.md +25 -0
- package/commands/seo-setup.md +17 -1
- package/commands/seo-watch.md +28 -0
- package/hooks/hooks.json +117 -0
- package/package.json +20 -7
- package/skills/seo-supervisor/NOTICE +7 -0
- package/skills/seo-supervisor/SKILL.md +302 -21
- package/skills/seo-supervisor/audience.md +61 -0
- package/skills/seo-supervisor/examples/drafts/security.md +41 -0
- package/skills/seo-supervisor/examples/hooks/README.md +28 -0
- package/skills/seo-supervisor/examples/hooks/claude-code-settings.json +15 -0
- package/skills/seo-supervisor/examples/hooks/codex-hooks.json +17 -0
- package/skills/seo-supervisor/examples/hooks/copilot-hooks.json +15 -0
- package/skills/seo-supervisor/examples/hooks/cursor-hooks.json +11 -0
- package/skills/seo-supervisor/examples/hooks/github-actions.yml +21 -0
- package/skills/seo-supervisor/examples/hooks/pre-commit +17 -0
- package/skills/seo-supervisor/examples/hooks/reading-ease.yml +24 -0
- package/skills/seo-supervisor/examples/sample-audit.json +94 -2
- package/skills/seo-supervisor/examples/sample-report.html +111 -61
- package/skills/seo-supervisor/examples/sample-report.md +147 -44
- package/skills/seo-supervisor/examples/scheduled-runs.md +89 -0
- package/skills/seo-supervisor/examples/snippets.md +648 -1
- package/skills/seo-supervisor/grow.md +342 -0
- package/skills/seo-supervisor/og-images.md +85 -0
- package/skills/seo-supervisor/page-types.md +124 -0
- package/skills/seo-supervisor/planning.md +19 -7
- package/skills/seo-supervisor/profile-template.md +41 -0
- package/skills/seo-supervisor/report-format.md +177 -10
- package/skills/seo-supervisor/rewrite.md +59 -0
- package/skills/seo-supervisor/rules/ai-search.md +65 -12
- package/skills/seo-supervisor/rules/content.md +33 -9
- package/skills/seo-supervisor/rules/crawl-index.md +33 -6
- package/skills/seo-supervisor/rules/internal-linking.md +49 -6
- package/skills/seo-supervisor/rules/launch-monitoring.md +17 -8
- package/skills/seo-supervisor/rules/media.md +13 -1
- package/skills/seo-supervisor/rules/metadata.md +41 -9
- package/skills/seo-supervisor/rules/performance.md +50 -5
- package/skills/seo-supervisor/rules/rendering.md +39 -2
- package/skills/seo-supervisor/rules/search-intent.md +32 -0
- package/skills/seo-supervisor/rules/sitemaps-robots.md +24 -12
- package/skills/seo-supervisor/rules/structured-data.md +37 -14
- package/skills/seo-supervisor/rules/trust-security.md +25 -2
- package/skills/seo-supervisor/rules/urls.md +10 -2
- package/skills/seo-supervisor/scripts/ai-answers.mjs +314 -0
- package/skills/seo-supervisor/scripts/backlinks.mjs +412 -0
- package/skills/seo-supervisor/scripts/change-check.mjs +281 -0
- package/skills/seo-supervisor/scripts/checks/agents.mjs +488 -0
- package/skills/seo-supervisor/scripts/checks/assets.mjs +404 -0
- package/skills/seo-supervisor/scripts/checks/bots.mjs +146 -0
- package/skills/seo-supervisor/scripts/checks/business-type.mjs +193 -0
- package/skills/seo-supervisor/scripts/checks/content.mjs +391 -0
- package/skills/seo-supervisor/scripts/checks/coverage.mjs +184 -0
- package/skills/seo-supervisor/scripts/checks/crawl.mjs +95 -0
- package/skills/seo-supervisor/scripts/checks/hreflang.mjs +396 -0
- package/skills/seo-supervisor/scripts/checks/hygiene.mjs +227 -0
- package/skills/seo-supervisor/scripts/checks/lighthouse.mjs +271 -0
- package/skills/seo-supervisor/scripts/checks/link-strength.mjs +59 -0
- package/skills/seo-supervisor/scripts/checks/links.mjs +360 -0
- package/skills/seo-supervisor/scripts/checks/local.mjs +101 -0
- package/skills/seo-supervisor/scripts/checks/media.mjs +194 -0
- package/skills/seo-supervisor/scripts/checks/outbound.mjs +53 -0
- package/skills/seo-supervisor/scripts/checks/page.mjs +223 -0
- package/skills/seo-supervisor/scripts/checks/probes.mjs +130 -0
- package/skills/seo-supervisor/scripts/checks/render.mjs +552 -0
- package/skills/seo-supervisor/scripts/checks/robots.mjs +144 -0
- package/skills/seo-supervisor/scripts/checks/schema.mjs +206 -0
- package/skills/seo-supervisor/scripts/checks/site-agents.mjs +79 -0
- package/skills/seo-supervisor/scripts/checks/site-content.mjs +135 -0
- package/skills/seo-supervisor/scripts/checks/site-hygiene.mjs +202 -0
- package/skills/seo-supervisor/scripts/checks/site-pages.mjs +474 -0
- package/skills/seo-supervisor/scripts/checks/site-security.mjs +102 -0
- package/skills/seo-supervisor/scripts/checks/sitemap.mjs +473 -0
- package/skills/seo-supervisor/scripts/checks/speed.mjs +267 -0
- package/skills/seo-supervisor/scripts/checks/technical.mjs +368 -0
- package/skills/seo-supervisor/scripts/checks/tls.mjs +297 -0
- package/skills/seo-supervisor/scripts/checks/trust.mjs +421 -0
- package/skills/seo-supervisor/scripts/checks/visual.mjs +1132 -0
- package/skills/seo-supervisor/scripts/checks/writing.mjs +192 -0
- package/skills/seo-supervisor/scripts/commoncrawl.mjs +452 -0
- package/skills/seo-supervisor/scripts/connect-keys.mjs +422 -0
- package/skills/seo-supervisor/scripts/content-scan.mjs +515 -158
- package/skills/seo-supervisor/scripts/crawl/catalog.mjs +1248 -0
- package/skills/seo-supervisor/scripts/crawl/fetch.mjs +362 -0
- package/skills/seo-supervisor/scripts/crawl/page.mjs +741 -0
- package/skills/seo-supervisor/scripts/crawl/queue.mjs +190 -0
- package/skills/seo-supervisor/scripts/dashboard.mjs +140 -0
- package/skills/seo-supervisor/scripts/data/ai-bots.json +38 -0
- package/skills/seo-supervisor/scripts/data/build-schema-vocab.mjs +57 -0
- package/skills/seo-supervisor/scripts/data/business-types.json +338 -0
- package/skills/seo-supervisor/scripts/data/google-rich-results.json +79 -0
- package/skills/seo-supervisor/scripts/data/schema-vocab.json +1 -0
- package/skills/seo-supervisor/scripts/deploy-check.mjs +462 -0
- package/skills/seo-supervisor/scripts/disavow.mjs +176 -0
- package/skills/seo-supervisor/scripts/doctor.mjs +174 -0
- package/skills/seo-supervisor/scripts/geo-grid.mjs +371 -0
- package/skills/seo-supervisor/scripts/google/search-console.mjs +151 -0
- package/skills/seo-supervisor/scripts/google/session.mjs +167 -0
- package/skills/seo-supervisor/scripts/google-updates.mjs +189 -0
- package/skills/seo-supervisor/scripts/google.mjs +1341 -0
- package/skills/seo-supervisor/scripts/gsc-import.mjs +298 -0
- package/skills/seo-supervisor/scripts/guard/adapters/claude-code.mjs +149 -0
- package/skills/seo-supervisor/scripts/guard/adapters/cline.mjs +28 -0
- package/skills/seo-supervisor/scripts/guard/adapters/codex.mjs +26 -0
- package/skills/seo-supervisor/scripts/guard/adapters/copilot.mjs +36 -0
- package/skills/seo-supervisor/scripts/guard/adapters/cursor.mjs +33 -0
- package/skills/seo-supervisor/scripts/guard/adapters/devin.mjs +25 -0
- package/skills/seo-supervisor/scripts/guard/adapters/edits.mjs +124 -0
- package/skills/seo-supervisor/scripts/guard/mode.mjs +37 -0
- package/skills/seo-supervisor/scripts/guard/rules.mjs +931 -0
- package/skills/seo-supervisor/scripts/guard.mjs +74 -0
- package/skills/seo-supervisor/scripts/images.mjs +408 -0
- package/skills/seo-supervisor/scripts/indexnow.mjs +300 -0
- package/skills/seo-supervisor/scripts/issues.mjs +217 -0
- package/skills/seo-supervisor/scripts/keys/authority.mjs +135 -0
- package/skills/seo-supervisor/scripts/keys/bing.mjs +239 -0
- package/skills/seo-supervisor/scripts/keys/clarity.mjs +137 -0
- package/skills/seo-supervisor/scripts/keys/dataforseo.mjs +57 -0
- package/skills/seo-supervisor/scripts/keys/googleplaces.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/http.mjs +212 -0
- package/skills/seo-supervisor/scripts/keys/matomo.mjs +138 -0
- package/skills/seo-supervisor/scripts/keys/openai.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/perplexity.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/posthog.mjs +165 -0
- package/skills/seo-supervisor/scripts/keys/semrush.mjs +25 -0
- package/skills/seo-supervisor/scripts/keys/services.mjs +41 -0
- package/skills/seo-supervisor/scripts/keys/store.mjs +140 -0
- package/skills/seo-supervisor/scripts/keys/visits.mjs +58 -0
- package/skills/seo-supervisor/scripts/keys/youtube.mjs +84 -0
- package/skills/seo-supervisor/scripts/keyword-data.mjs +316 -0
- package/skills/seo-supervisor/scripts/keyword-ideas.mjs +503 -0
- package/skills/seo-supervisor/scripts/lib/args.mjs +56 -0
- package/skills/seo-supervisor/scripts/lib/business.mjs +27 -0
- package/skills/seo-supervisor/scripts/lib/cdp.mjs +242 -0
- package/skills/seo-supervisor/scripts/lib/cli.mjs +56 -0
- package/skills/seo-supervisor/scripts/lib/csv.mjs +38 -0
- package/skills/seo-supervisor/scripts/lib/findings.mjs +100 -0
- package/skills/seo-supervisor/scripts/lib/google-client.mjs +9 -0
- package/skills/seo-supervisor/scripts/lib/html.mjs +146 -0
- package/skills/seo-supervisor/scripts/lib/http.mjs +28 -0
- package/skills/seo-supervisor/scripts/lib/image-size.mjs +78 -0
- package/skills/seo-supervisor/scripts/lib/is-main.mjs +13 -0
- package/skills/seo-supervisor/scripts/lib/net.mjs +116 -0
- package/skills/seo-supervisor/scripts/lib/proxy.mjs +47 -0
- package/skills/seo-supervisor/scripts/lib/recheck.mjs +106 -0
- package/skills/seo-supervisor/scripts/lib/redact.mjs +78 -0
- package/skills/seo-supervisor/scripts/lib/robots.mjs +73 -0
- package/skills/seo-supervisor/scripts/lib/score.mjs +266 -0
- package/skills/seo-supervisor/scripts/lib/settings-dir.mjs +81 -0
- package/skills/seo-supervisor/scripts/links-import.mjs +603 -0
- package/skills/seo-supervisor/scripts/log-scan.mjs +597 -0
- package/skills/seo-supervisor/scripts/og-card.mjs +273 -0
- package/skills/seo-supervisor/scripts/osm.mjs +359 -0
- package/skills/seo-supervisor/scripts/rdap.mjs +164 -0
- package/skills/seo-supervisor/scripts/render-report.mjs +324 -690
- package/skills/seo-supervisor/scripts/report/client.js +37 -0
- package/skills/seo-supervisor/scripts/report/diff.mjs +264 -0
- package/skills/seo-supervisor/scripts/report/findings.mjs +165 -0
- package/skills/seo-supervisor/scripts/report/format.mjs +111 -0
- package/skills/seo-supervisor/scripts/report/markdown.mjs +250 -0
- package/skills/seo-supervisor/scripts/report/model.mjs +171 -0
- package/skills/seo-supervisor/scripts/report/overview-lines.mjs +158 -0
- package/skills/seo-supervisor/scripts/report/overview.mjs +224 -0
- package/skills/seo-supervisor/scripts/report/page.mjs +127 -0
- package/skills/seo-supervisor/scripts/report/panel.mjs +172 -0
- package/skills/seo-supervisor/scripts/report/panels/ai.mjs +211 -0
- package/skills/seo-supervisor/scripts/report/panels/connections.mjs +139 -0
- package/skills/seo-supervisor/scripts/report/panels/content.mjs +204 -0
- package/skills/seo-supervisor/scripts/report/panels/data-search.mjs +379 -0
- package/skills/seo-supervisor/scripts/report/panels/data-site.mjs +44 -0
- package/skills/seo-supervisor/scripts/report/panels/links.mjs +380 -0
- package/skills/seo-supervisor/scripts/report/panels/local.mjs +221 -0
- package/skills/seo-supervisor/scripts/report/panels/site.mjs +359 -0
- package/skills/seo-supervisor/scripts/report/panels/speed-media.mjs +267 -0
- package/skills/seo-supervisor/scripts/report/sources.mjs +163 -0
- package/skills/seo-supervisor/scripts/report/styles.css +223 -0
- package/skills/seo-supervisor/scripts/report/traffic.mjs +264 -0
- package/skills/seo-supervisor/scripts/report-plan.mjs +112 -33
- package/skills/seo-supervisor/scripts/schema-check.mjs +717 -0
- package/skills/seo-supervisor/scripts/seo-crawl.mjs +1086 -638
- package/skills/seo-supervisor/scripts/seo-diff.mjs +584 -0
- package/skills/seo-supervisor/scripts/update-check.mjs +82 -0
- package/skills/seo-supervisor/site-types/content.md +34 -1
- package/skills/seo-supervisor/site-types/ecommerce.md +38 -1
- package/skills/seo-supervisor/site-types/local-business.md +96 -6
- package/skills/seo-supervisor/site-types/services.md +46 -0
- package/skills/seo-supervisor/site-types/tools.md +3 -3
- package/skills/seo-supervisor/strategy.md +232 -0
- package/skills/seo-supervisor/troubleshooting.md +56 -0
|
@@ -1,41 +1,209 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
2
|
+
// @ts-check
|
|
3
|
+
// Read-only SEO crawler: GET and HEAD only, plus a TLS handshake with --check-live.
|
|
4
|
+
// Regex HTML parsing is enough for audit evidence. Swap in a real parser if a site breaks it.
|
|
5
|
+
|
|
6
|
+
import { mkdirSync, writeFileSync, readFileSync, existsSync } from "node:fs";
|
|
7
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { fileCrawl } from "./seo-diff.mjs";
|
|
10
|
+
import { chromeProxyArgs } from "./lib/proxy.mjs";
|
|
11
|
+
import { parseArgs } from "./lib/args.mjs";
|
|
12
|
+
import { Fail, runMain, warnProxy } from "./lib/cli.mjs";
|
|
13
|
+
import { loopback } from "./lib/net.mjs";
|
|
14
|
+
import { redact, hideSecrets } from "./lib/redact.mjs";
|
|
15
|
+
import { createFindings, quote } from "./lib/findings.mjs";
|
|
16
|
+
import { RULES, CHECKS } from "./crawl/catalog.mjs";
|
|
17
|
+
import { PAGE_MAX, clean, createFetcher, isLocal, isPublic, mapOrigin, urlOr } from "./crawl/fetch.mjs";
|
|
18
|
+
import { createCrawler } from "./crawl/queue.mjs";
|
|
19
|
+
import { checkRobots, versionedNote, aiBotAccess, aiRobotRules } from "./checks/robots.mjs";
|
|
20
|
+
import { SITEMAP_KEEP, findSitemaps, checkSitemapFiles, checkSitemapEntries } from "./checks/sitemap.mjs";
|
|
21
|
+
import { probeSite } from "./checks/probes.mjs";
|
|
22
|
+
import { checkPages } from "./checks/site-pages.mjs";
|
|
23
|
+
import { checkAssets, imageList, schemaImages, mediaData } from "./checks/assets.mjs";
|
|
24
|
+
import {
|
|
25
|
+
checkLinks,
|
|
26
|
+
slashStyle,
|
|
27
|
+
oldUrls,
|
|
28
|
+
outboundLinks,
|
|
29
|
+
linkedOnce,
|
|
30
|
+
linkStrength,
|
|
31
|
+
pageWords,
|
|
32
|
+
otherSites,
|
|
33
|
+
} from "./checks/links.mjs";
|
|
34
|
+
import { compareGooglebot, aiBotProbe, readPage } from "./checks/bots.mjs";
|
|
35
|
+
import { cookiesAndPolicies, securityHeaders } from "./checks/site-security.mjs";
|
|
36
|
+
import { agentData, bingAiPrefs, landmarks } from "./checks/site-agents.mjs";
|
|
37
|
+
import {
|
|
38
|
+
pageMarkup,
|
|
39
|
+
descStartsWithTitle,
|
|
40
|
+
pageSignals,
|
|
41
|
+
shopChecks,
|
|
42
|
+
contentChecks,
|
|
43
|
+
localData,
|
|
44
|
+
} from "./checks/site-content.mjs";
|
|
45
|
+
import { hygieneChecks, markdownCheck } from "./checks/site-hygiene.mjs";
|
|
46
|
+
import { checkCoverage } from "./checks/coverage.mjs";
|
|
47
|
+
import { checkLanguages, otherSiteTargets, linksBack } from "./checks/hreflang.mjs";
|
|
48
|
+
import { checkLive } from "./checks/tls.mjs";
|
|
49
|
+
import {
|
|
50
|
+
checkSpeed,
|
|
51
|
+
sampleUrls,
|
|
52
|
+
PSI_ENDPOINT,
|
|
53
|
+
speedTrend,
|
|
54
|
+
CRUX_HISTORY_ENDPOINT,
|
|
55
|
+
labLcpBreakdown,
|
|
56
|
+
} from "./checks/speed.mjs";
|
|
57
|
+
import { findBrowser, openSession, renderPage, renderFindings, renderAll } from "./checks/render.mjs";
|
|
58
|
+
import { checkPages as browserChecks } from "./checks/visual.mjs";
|
|
59
|
+
import { checkLighthouse, findLighthouse, ALL_CAP } from "./checks/lighthouse.mjs";
|
|
60
|
+
import { trustSignals } from "./checks/trust.mjs";
|
|
61
|
+
import { checkBusinessType, detectBusinessType } from "./checks/business-type.mjs";
|
|
62
|
+
import { slowNote } from "./checks/crawl.mjs";
|
|
63
|
+
import { maskKeys } from "./checks/hygiene.mjs";
|
|
64
|
+
warnProxy(); // once, before any request
|
|
65
|
+
|
|
66
|
+
const VERSION = "2.0.0";
|
|
24
67
|
const UA = "seo-supervisor-crawler/" + VERSION;
|
|
25
68
|
|
|
26
69
|
// ---------- args ----------
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
70
|
+
// An unknown option or unusable value stops the crawl (exit 2) before anything is asked of the site.
|
|
71
|
+
// Each option in FLAGS and BOOLEANS needs its own line here, at most 100 characters wide (test/help.test.mjs).
|
|
72
|
+
const USAGE = `Usage: node seo-crawl.mjs --url http://localhost:3000 [options]
|
|
73
|
+
|
|
74
|
+
Crawls a site and writes what it finds to one JSON file. Read-only: it sends only GET and HEAD
|
|
75
|
+
requests. Point it at a local or staging server when you can; against production keep
|
|
76
|
+
--concurrency low.
|
|
77
|
+
|
|
78
|
+
Basics
|
|
79
|
+
--url <address> where the crawl starts (required), like http://localhost:3000
|
|
80
|
+
--site-origin <address> the public address canonicals and sitemaps should use,
|
|
81
|
+
like https://www.example.com
|
|
82
|
+
--trailing-slash <style> auto (the default: detect the site's style, flag a mix), always
|
|
83
|
+
or never
|
|
84
|
+
--brand <name> flag titles that repeat the brand name
|
|
85
|
+
--ignore-noindex before launch: check noindex pages as if they could be indexed
|
|
86
|
+
--banned <pattern> flag visible text that matches (banned claims, wrong names)
|
|
87
|
+
--verify <pattern> flag claims the owner hasn't confirmed yet, as decisions
|
|
88
|
+
|
|
89
|
+
Scope
|
|
90
|
+
--max <n> crawl at most n pages (default 1000)
|
|
91
|
+
--concurrency <n> requests at once (default 8 on this computer, 4 on any other server)
|
|
92
|
+
--include <paths> crawl only these sections: comma-separated path starts, like /blog/
|
|
93
|
+
(the start page is still crawled, as the way in)
|
|
94
|
+
--exclude <paths> skip these sections, like /blog/tag/
|
|
95
|
+
--include-query crawl addresses with a ?query as pages of their own
|
|
96
|
+
|
|
97
|
+
Outside checks (each contacts more than the server being crawled, so each needs the owner's yes)
|
|
98
|
+
--check-live live site only: the certificate, the http-to-https and www/bare-domain
|
|
99
|
+
redirects, and HSTS (the "always use https" header) on --site-origin
|
|
100
|
+
--outside real-user speed from Google PageSpeed Insights for up to 10 public
|
|
101
|
+
pages (set PSI_API_KEY); a Chrome or Edge render of up to 10 pages on
|
|
102
|
+
desktop and phone, with screenshots (CHROME_PATH picks the browser);
|
|
103
|
+
Chrome's back/forward cache test and lab speed; with CRUX_API_KEY,
|
|
104
|
+
the site's 25-week speed trend
|
|
105
|
+
--render all with --outside: render every indexable page (up to 200, about 5 s
|
|
106
|
+
a page) instead of 10; it prints the time it expects first
|
|
107
|
+
--lighthouse [all|<n>] with --outside: Lighthouse on 5 sample pages, on every indexable
|
|
108
|
+
page (all: up to 200, about 20 s a page) or on n of them. Install it
|
|
109
|
+
first: npx seo-supervisor --with-lighthouse, or set LIGHTHOUSE_PATH
|
|
110
|
+
--desktop with --outside: send the same pages to PageSpeed again for desktop
|
|
111
|
+
(information only)
|
|
112
|
+
--render-page <address> with --outside: render one page you pick
|
|
113
|
+
--render-steps "<steps>" what to do on that page first, like "scroll; click .more; wait 1000"
|
|
114
|
+
(it never types)
|
|
115
|
+
--clean-screenshots with --outside: also save screenshots with cookie bars and chat
|
|
116
|
+
boxes hidden
|
|
117
|
+
--ai-bot-probe with --outside: ask up to 3 pages again as AI search crawlers, to see
|
|
118
|
+
whether a firewall turns them away
|
|
119
|
+
--hreflang-other-sites with --outside: visit up to 20 language versions on other sites, to
|
|
120
|
+
see whether they link back
|
|
121
|
+
--outbound-links visit up to 100 links to other sites, to find broken ones (never
|
|
122
|
+
private or local addresses)
|
|
123
|
+
--psi-endpoint <address> send the PageSpeed requests here instead of to Google (for tests)
|
|
124
|
+
--crux-endpoint <address> send the speed-trend requests here instead of to Google (for tests)
|
|
125
|
+
|
|
126
|
+
Data inputs
|
|
127
|
+
--urls <file> old addresses or redirect sources to test: one per line, a CSV's first
|
|
128
|
+
column, or a JSON array
|
|
129
|
+
--next-manifest <file> test every fixed-path redirect in a Next.js build's
|
|
130
|
+
.next/routes-manifest.json
|
|
131
|
+
--gsc-indexing <file> Search Console's Page indexing export (its Chart.csv): Google's
|
|
132
|
+
indexed count beside the crawl's, information only
|
|
133
|
+
|
|
134
|
+
Output
|
|
135
|
+
--out <file> where the crawl is written (default seo-audit/seo-crawl.json);
|
|
136
|
+
screenshots go in screenshots/ next to it
|
|
137
|
+
--help, -h show this help`;
|
|
138
|
+
const FLAGS = [
|
|
139
|
+
"url",
|
|
140
|
+
"site-origin",
|
|
141
|
+
"trailing-slash",
|
|
142
|
+
"brand",
|
|
143
|
+
"banned",
|
|
144
|
+
"verify",
|
|
145
|
+
"urls",
|
|
146
|
+
"next-manifest",
|
|
147
|
+
"psi-endpoint",
|
|
148
|
+
"crux-endpoint",
|
|
149
|
+
"render",
|
|
150
|
+
"lighthouse",
|
|
151
|
+
"render-page",
|
|
152
|
+
"render-steps",
|
|
153
|
+
"include",
|
|
154
|
+
"exclude",
|
|
155
|
+
"gsc-indexing",
|
|
156
|
+
"max",
|
|
157
|
+
"concurrency",
|
|
158
|
+
"out",
|
|
159
|
+
];
|
|
160
|
+
const BOOLEANS = [
|
|
161
|
+
"ignore-noindex",
|
|
162
|
+
"check-live",
|
|
163
|
+
"outside",
|
|
164
|
+
"outbound-links",
|
|
165
|
+
"desktop",
|
|
166
|
+
"hreflang-other-sites",
|
|
167
|
+
"ai-bot-probe",
|
|
168
|
+
"clean-screenshots",
|
|
169
|
+
"include-query",
|
|
170
|
+
];
|
|
171
|
+
/** @type {{ args: ReturnType<typeof parseArgs>, browser: string | null } | undefined} */
|
|
172
|
+
let options;
|
|
173
|
+
await runMain(() => {
|
|
174
|
+
const a = parseArgs(process.argv.slice(2), { flags: FLAGS, booleans: BOOLEANS, positionals: 0, usage: USAGE });
|
|
175
|
+
if (typeof a.url !== "string")
|
|
176
|
+
throw new Fail(
|
|
177
|
+
`${USAGE.slice(0, USAGE.indexOf("\n"))}\n--url is required. Every option: node seo-crawl.mjs --help`,
|
|
178
|
+
);
|
|
179
|
+
const no = (k, why) => {
|
|
180
|
+
throw new Fail(`seo-crawl: --${k} ${why}`);
|
|
181
|
+
};
|
|
182
|
+
for (const k of ["url", "site-origin"])
|
|
183
|
+
if (k in a && !(URL.canParse(a[k]) && /^https?:$/.test(new URL(a[k]).protocol)))
|
|
184
|
+
no(k, `needs a full web address, like http://localhost:3000 (got “${a[k]}”).`);
|
|
185
|
+
for (const k of ["max", "concurrency"])
|
|
186
|
+
if (k in a && !/^[1-9]\d*$/.test(a[k]))
|
|
187
|
+
no(k, `needs a whole number of 1 or more, like --${k} ${k === "max" ? 1000 : 4}.`);
|
|
188
|
+
for (const k of ["banned", "verify"])
|
|
189
|
+
if (typeof a[k] === "string")
|
|
190
|
+
try {
|
|
191
|
+
new RegExp(a[k], "i");
|
|
192
|
+
} catch (e) {
|
|
193
|
+
no(k, `isn't a valid pattern (${e.message}).`);
|
|
194
|
+
}
|
|
195
|
+
// With --outside, find the browser first: a CHROME_PATH that points at nothing stops the crawl before it starts.
|
|
196
|
+
let browser = null;
|
|
197
|
+
if (a.outside)
|
|
198
|
+
try {
|
|
199
|
+
browser = findBrowser();
|
|
200
|
+
} catch (e) {
|
|
201
|
+
throw new Fail(`seo-crawl: ${e.message}`);
|
|
202
|
+
}
|
|
203
|
+
options = { args: a, browser };
|
|
204
|
+
});
|
|
205
|
+
if (!options) process.exit(); // runMain said why and set the exit code; nothing has been asked of the site yet
|
|
206
|
+
const { args, browser } = options;
|
|
39
207
|
const START = new URL(args.url);
|
|
40
208
|
const START_ORIGIN = START.origin;
|
|
41
209
|
const MAX = Number(args.max || 1000);
|
|
@@ -44,660 +212,940 @@ const BANNED = typeof args.banned === "string" ? new RegExp(args.banned, "i") :
|
|
|
44
212
|
const VERIFY = typeof args.verify === "string" ? new RegExp(args.verify, "i") : null;
|
|
45
213
|
const URL_LIST = typeof args.urls === "string" ? args.urls : null;
|
|
46
214
|
const NEXT_MANIFEST = typeof args["next-manifest"] === "string" ? args["next-manifest"] : null;
|
|
47
|
-
|
|
215
|
+
// Locally the server's own speed is the limit, so 8 at once; 4 against any other server.
|
|
216
|
+
const CONC = Number(args.concurrency || (loopback(START.hostname) ? 8 : 4));
|
|
48
217
|
const SLASH = ["always", "never"].includes(args["trailing-slash"]) ? args["trailing-slash"] : "auto";
|
|
49
218
|
const BRAND = typeof args.brand === "string" ? args.brand : "";
|
|
50
219
|
const INCLUDE_QUERY = !!args["include-query"];
|
|
220
|
+
const CHECK_LIVE = !!args["check-live"];
|
|
221
|
+
const OUTSIDE = !!args.outside; // nothing leaves the machine without it
|
|
222
|
+
const LIGHTHOUSE_ALL = args.lighthouse === "all"; // --lighthouse all, or --lighthouse=all
|
|
223
|
+
const LIGHTHOUSE = !!args.lighthouse;
|
|
224
|
+
const RENDER_ALL = args.render === "all"; // with --outside: every indexable page, not the sample
|
|
225
|
+
const DESKTOP = !!args.desktop; // a separate opt-in: it sends the sample URLs to Google a second time
|
|
51
226
|
const OUT = resolve(typeof args.out === "string" ? args.out : "seo-audit/seo-crawl.json");
|
|
52
227
|
let SITE_ORIGIN = typeof args["site-origin"] === "string" ? new URL(args["site-origin"]).origin : "";
|
|
228
|
+
// Public-origin URLs mapped onto the crawl origin. SITE_ORIGIN may still be found while the crawl runs (robots.txt's
|
|
229
|
+
// Sitemap: line, the sitemap, the home page's canonical), so every module gets this function, never the value.
|
|
230
|
+
const toCrawl = u => mapOrigin(u, SITE_ORIGIN, START_ORIGIN);
|
|
231
|
+
const { get, follow, firstBytes, fetchSitemap, xRobotsLines, blocked, slow } = createFetcher({
|
|
232
|
+
startOrigin: START_ORIGIN,
|
|
233
|
+
ua: UA,
|
|
234
|
+
toCrawl,
|
|
235
|
+
});
|
|
53
236
|
const notes = [];
|
|
237
|
+
// --include and --exclude: comma-separated path prefixes, so one crawl can cover one section such as /blog/.
|
|
238
|
+
const pathList = k =>
|
|
239
|
+
typeof args[k] === "string"
|
|
240
|
+
? args[k]
|
|
241
|
+
.split(",")
|
|
242
|
+
.map(s => s.trim())
|
|
243
|
+
.filter(Boolean)
|
|
244
|
+
.map(s => "/" + s.replace(/^\/+/, ""))
|
|
245
|
+
: [];
|
|
246
|
+
const INCLUDE = pathList("include"),
|
|
247
|
+
EXCLUDE = pathList("exclude"),
|
|
248
|
+
SECTION = INCLUDE.length > 0 || EXCLUDE.length > 0;
|
|
249
|
+
const inSection = path =>
|
|
250
|
+
(!INCLUDE.length || INCLUDE.some(p => path.startsWith(p))) && !EXCLUDE.some(p => path.startsWith(p));
|
|
251
|
+
const AI_PROBE = !!args["ai-bot-probe"];
|
|
252
|
+
const RENDER_PAGE = typeof args["render-page"] === "string" ? args["render-page"] : null;
|
|
253
|
+
const RENDER_STEPS = typeof args["render-steps"] === "string" ? args["render-steps"] : "";
|
|
254
|
+
const CLEAN_SHOTS = !!args["clean-screenshots"];
|
|
255
|
+
// Every finding's URL and detail is scrubbed of secret keys, secret query values and home folders, whichever check adds
|
|
256
|
+
// it, so no secret reaches the crawl file through another check's evidence. Notes and notChecked reasons get the same
|
|
257
|
+
// scrub on output, emails included.
|
|
258
|
+
const { findings, add, evaluated, evalRules, notChecked, skip, list } = createFindings(
|
|
259
|
+
CHECKS,
|
|
260
|
+
s => redact(maskKeys(s), { emails: false }),
|
|
261
|
+
RULES,
|
|
262
|
+
);
|
|
54
263
|
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"URL-01": ["Clean, lowercase, hyphenated URLs", "URLs & canonicals"],
|
|
64
|
-
"URL-02": ["One trailing-slash style, the other variant redirects", "URLs & canonicals"],
|
|
65
|
-
"URL-04": ["Self-referencing, absolute canonical on every indexable page", "URLs & canonicals"],
|
|
66
|
-
"URL-05": ["Every breadcrumb level is a real page", "URLs & canonicals"],
|
|
67
|
-
"URL-07": ["Old URLs redirect to live pages", "URLs & canonicals"],
|
|
68
|
-
"REND-01": ["Content is in the server HTML, not only in JavaScript", "Rendering"],
|
|
69
|
-
"REND-04": ["Links are real <a href> links", "Rendering"],
|
|
70
|
-
"CONTENT-09": ["No placeholder, test or broken-encoding text", "Headings & content"],
|
|
71
|
-
"CONTENT-10": ["No banned or unconfirmed claims on pages", "Headings & content"],
|
|
72
|
-
"META-01": ["Unique titles of a sensible length", "Metadata"],
|
|
73
|
-
"META-02": ["Unique meta descriptions of a sensible length", "Metadata"],
|
|
74
|
-
"META-03": ["Brand appears once in titles", "Metadata"],
|
|
75
|
-
"META-04": ["Open Graph tags for sharing", "Metadata"],
|
|
76
|
-
"META-05": ["Page language declared", "Metadata"],
|
|
77
|
-
"CONTENT-01": ["Exactly one H1 per page", "Headings & content"],
|
|
78
|
-
"CONTENT-02": ["Heading levels are not skipped", "Headings & content"],
|
|
79
|
-
"CONTENT-04": ["Templated pages have unique content", "Headings & content"],
|
|
80
|
-
"CONTENT-05": ["Indexable pages have substantial content", "Headings & content"],
|
|
81
|
-
"CONTENT-08": ["Images have alt text", "Headings & content"],
|
|
82
|
-
"SCHEMA-01": ["JSON-LD parses without errors", "Structured data"],
|
|
83
|
-
"SCHEMA-02": ["Organization and WebSite schema on the home page", "Structured data"],
|
|
84
|
-
"SCHEMA-03": ["Indexable pages carry structured data", "Structured data"],
|
|
85
|
-
"SCHEMA-04": ["Schema matches what the page visibly shows", "Structured data"],
|
|
86
|
-
"SCHEMA-05": ["No deprecated schema types", "Structured data"],
|
|
87
|
-
"SCHEMA-07": ["BreadcrumbList on pages below the home page", "Structured data"],
|
|
88
|
-
"MAP-01": ["XML sitemap exists and is referenced from robots.txt", "Sitemaps & robots"],
|
|
89
|
-
"MAP-02": ["Sitemap lists only canonical, indexable URLs on the right host", "Sitemaps & robots"],
|
|
90
|
-
"MAP-03": ["Indexable pages are in the sitemap", "Sitemaps & robots"],
|
|
91
|
-
"MAP-04": ["Sitemap lastmod dates are real", "Sitemaps & robots"],
|
|
92
|
-
"MAP-05": ["robots.txt blocks only junk, never CSS/JS", "Sitemaps & robots"],
|
|
93
|
-
"MAP-06": ["AI crawler policy is deliberate", "Sitemaps & robots"],
|
|
94
|
-
"MAP-07": ["llms.txt published", "Sitemaps & robots"],
|
|
95
|
-
"LINK-01": ["Pages are within three clicks of the home page", "Internal linking"],
|
|
96
|
-
"LINK-02": ["No orphan pages", "Internal linking"],
|
|
97
|
-
"LINK-05": ["Descriptive anchor text", "Internal linking"],
|
|
98
|
-
"LINK-06": ["Link counts per page stay reasonable", "Internal linking"],
|
|
99
|
-
"PERF-03": ["The first image is not lazy-loaded", "Performance"],
|
|
100
|
-
"PERF-04": ["Images reserve their space (width and height)", "Performance"],
|
|
101
|
-
"PERF-06": ["HTML documents stay lightweight", "Performance"],
|
|
102
|
-
"TRUST-01": ["HTTPS security headers are set", "Trust & security"],
|
|
103
|
-
"TRUST-02": ["security.txt published", "Trust & security"],
|
|
104
|
-
"AI-01": ["Pages are eligible for snippets and AI answers", "AI search"],
|
|
105
|
-
"REND-08": ["HTML stays under Googlebot's 2 MB limit", "Rendering"],
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
// key -> [rule, severity, title(n), why, fix]
|
|
109
|
-
const CHECKS = {
|
|
110
|
-
"robots-blocks-all": ["CRAWL-01", "blocker", () => "robots.txt blocks the whole site", "With `Disallow: /` for every crawler, search engines can't crawl any page, so nothing new gets indexed and existing pages decay.", "Allow crawling in production (`Allow: /`). Keep staging out of Google with a noindex header and a password instead."],
|
|
111
|
-
"sitemap-url-disallowed": ["CRAWL-01", "high", n => `${n} sitemap URL(s) are blocked by robots.txt`, "The sitemap asks Google to index these URLs while robots.txt forbids crawling them. Google gets contradictory signals and may index them without content.", "Either remove the Disallow rule for these paths or remove the URLs from the sitemap."],
|
|
112
|
-
"home-noindex": ["CRAWL-02", "blocker", () => "The home page is set to noindex", "A noindex home page usually means a staging or launch setting leaked into production. The whole site can drop out of search.", "Remove the noindex (meta robots or X-Robots-Tag) in production. Drive it from one environment variable."],
|
|
113
|
-
"noindex-in-sitemap": ["CRAWL-02", "high", n => `${n} sitemap URL(s) are set to noindex`, "The sitemap says “index this” and the page says “don't”. Either the page should rank and the noindex is a bug, or it shouldn't be in the sitemap.", "Decide per page type. Remove noindex from pages meant to rank, or drop noindex pages from the sitemap."],
|
|
114
|
-
"noindex-review": ["CRAWL-02", "low", n => `${n} crawled page(s) are noindex`, "Noindex is right for search, filter, account and result pages, and wrong anywhere you want traffic.", "Check each against the project's SEO profile. Keep noindex only on page types meant to stay hidden."],
|
|
115
|
-
"soft-404": ["CRAWL-05", "high", () => "Unknown URLs don't return 404 (soft 404)", "A made-up URL returned a page instead of a 404 status. Google wastes crawls on these and may index junk URLs.", "Return a real 404 status for unknown paths (and 410 for removed content). Don't redirect unknown URLs to the home page."],
|
|
116
|
-
"server-error": ["CRAWL-05", "high", n => `${n} URL(s) returned a server error (5xx)`, "Repeated 5xx responses make Google crawl less and drop pages from the index.", "Find the failing route in the server logs and fix it. A page must not fail because a slow API is down."],
|
|
117
|
-
"sitemap-bad-status": ["CRAWL-06", "high", n => `${n} sitemap URL(s) don't return 200`, "Sitemaps should only list final, working URLs. Redirects and errors in the sitemap waste crawl budget and lower trust in the sitemap.", "Generate the sitemap from the same live data the pages use, and list only the final URL of each page."],
|
|
118
|
-
"broken-internal-link": ["CRAWL-07", "high", n => `${n} internal link target(s) are broken (4xx/5xx)`, "Every broken link is a dead end for visitors and crawlers and wastes the authority passed through it.", "Fix or remove each link. Filter generated links (related, next, breadcrumbs) through the set of live pages."],
|
|
119
|
-
"redirect-chain": ["CRAWL-08", "medium", n => `${n} URL(s) redirect through more than one hop`, "Each extra hop slows crawling and loses a little signal. Chains also often end somewhere unintended.", "Point each old URL straight at its final destination in one 301/308."],
|
|
120
|
-
"link-to-redirect": ["CRAWL-08", "low", n => `${n} internal link target(s) point at a redirect`, "Linking to a redirecting URL costs a hop on every click and crawl.", "Update the links to the final URL (often a missing or extra trailing slash)."],
|
|
121
|
-
"url-format": ["URL-01", "low", n => `${n} URL(s) have uppercase letters, underscores, spaces or double slashes`, "Mixed-case and underscored URLs are easy to duplicate and hard to share.", "Use lowercase words joined by hyphens. Redirect old variants once."],
|
|
122
|
-
"trailing-slash-mixed": ["URL-02", "high", n => `${n} page(s) break the site's trailing-slash style`, "`/page` and `/page/` are different URLs to search engines. Mixing them splits ranking signals.", "Pick one style (record it in the SEO profile), configure the framework to redirect the other, and use it in every link, canonical, sitemap entry and schema URL."],
|
|
123
|
-
"slash-variant-no-redirect": ["URL-02", "high", n => `${n} page(s) answer 200 on both the slash and no-slash URL`, "Both versions return the page, so every page exists twice.", "Redirect the non-preferred variant with a 301/308 (in Next.js: `trailingSlash`)."],
|
|
124
|
-
"canonical-missing": ["URL-04", "high", n => `${n} indexable page(s) have no canonical tag`, "Without a canonical, Google picks one itself among parameter, slash and tracking variants.", "Add a self-referencing absolute canonical to every indexable page through the shared metadata helper."],
|
|
125
|
-
"canonical-multiple": ["URL-04", "high", n => `${n} page(s) declare more than one canonical`, "Conflicting canonicals are ignored.", "Emit exactly one canonical per page from one place."],
|
|
126
|
-
"canonical-not-self": ["URL-04", "medium", n => `${n} indexable page(s) canonicalize to a different URL`, "That tells Google to rank another URL instead. Right for variants, wrong for pages meant to rank.", "Check each against the profile. Pages meant to rank need a canonical to themselves, with the same trailing-slash style."],
|
|
127
|
-
"canonical-query": ["URL-04", "high", n => `${n} canonical(s) contain a query string`, "Canonicals built from the request URL leak `?utm_` and other parameters, creating duplicates.", "Build canonicals from the clean path, never from the incoming request URL."],
|
|
128
|
-
"canonical-origin": ["URL-04", "high", n => `${n} canonical(s) point at the wrong host`, "Canonicals on staging, localhost or the wrong www/https variant send signals to the wrong site.", "Set the base URL (e.g. `metadataBase`) from one production origin setting."],
|
|
129
|
-
"canonical-bad-target": ["URL-04", "high", n => `${n} canonical target(s) don't return 200`, "A canonical pointing at a redirect or error is ignored.", "Point canonicals at the final, working URL."],
|
|
130
|
-
"breadcrumb-dead-level": ["URL-05", "high", n => `${n} breadcrumb level URL(s) don't return 200`, "Every breadcrumb level except the last is a link on every page below it. A missing hub page is a broken link sitewide.", "Create a real hub page for each level, or fix the breadcrumb URL."],
|
|
131
|
-
"client-rendered": ["REND-01", "blocker", n => `${n} page(s) have almost no content in the server HTML`, "The HTML the server sends is nearly empty, so crawlers that don't run JavaScript (most AI crawlers, and Google's first pass) see a blank page.", "Server-render or pre-render page content. Only interactive widgets should depend on client JavaScript."],
|
|
132
|
-
"title-multiple": ["META-01", "high", n => `${n} page(s) have more than one <title>`, "Two titles usually mean a hard-coded layout title plus a page title, or two SEO plugins. Search engines may pick the wrong one.", "Emit the title from one place only."],
|
|
133
|
-
"href-hash": ["REND-04", "low", n => `${n} page(s) have links without a real destination (href="#", javascript:, or no href)`, "Crawlers only follow real URLs. Click-handler navigation hides pages from search engines.", "Use real `<a href>` links for navigation and `<button>` for actions."],
|
|
134
|
-
"placeholder-text": ["CONTENT-09", "high", n => `${n} page(s) show placeholder, test or broken-encoding text`, "Lorem ipsum, TODO, template tokens or mangled characters on a live page look unfinished to visitors and quality reviewers.", "Replace the text with real content and add a build check that fails on these strings."],
|
|
135
|
-
"mixed-content": ["TRUST-01", "low", n => `${n} HTTPS page(s) load resources over plain HTTP`, "Browsers block or warn about insecure resources on secure pages.", "Load every resource over HTTPS."],
|
|
136
|
-
"title-missing": ["META-01", "high", n => `${n} page(s) have no title`, "The title is the main headline in search results.", "Give every page a unique title through the shared metadata helper."],
|
|
137
|
-
"title-long": ["META-01", "medium", n => `${n} title(s) are longer than 60 characters`, "Long titles get cut off in results, often losing the brand or the key phrase.", "Keep titles under about 60 characters, main keyword first."],
|
|
138
|
-
"title-short": ["META-01", "low", n => `${n} title(s) are shorter than 20 characters`, "Very short titles waste the most visible spot in results.", "Describe the page: what it is and who it's for, in under 60 characters."],
|
|
139
|
-
"title-dup": ["META-01", "high", n => `${n} title(s) are shared by more than one page`, "Duplicate titles make pages compete with each other and look templated.", "Make each title unique, usually by including the page's specific subject."],
|
|
140
|
-
"title-brand-twice": ["META-03", "low", n => `${n} title(s) repeat the brand`, "A title template plus a title that already has the brand doubles it.", "Use an absolute title when the brand is already present, or drop it from the page title."],
|
|
141
|
-
"desc-missing": ["META-02", "medium", n => `${n} page(s) have no meta description`, "Google then writes its own snippet, often from navigation text.", "Write a unique 120–160 character description per page: what you get and why."],
|
|
142
|
-
"desc-length": ["META-02", "low", n => `${n} description(s) are outside 120–160 characters`, "Short descriptions undersell the page; long ones get cut off.", "Aim for 120–160 characters."],
|
|
143
|
-
"desc-dup": ["META-02", "medium", n => `${n} description(s) are shared by more than one page`, "Duplicate descriptions signal templated pages.", "Write a specific description for each page."],
|
|
144
|
-
"og-missing": ["META-04", "low", n => `${n} page(s) lack og:title or og:image`, "Shared links on Slack, LinkedIn and X show a bare URL instead of a card.", "Emit Open Graph and Twitter tags from the metadata helper, with a default image and per-page images for key pages."],
|
|
145
|
-
"lang-missing": ["META-05", "low", () => "Pages don't declare a language", "`<html lang>` helps search engines and screen readers.", "Set `lang` on the `<html>` element in the root layout."],
|
|
146
|
-
"h1-count": ["CONTENT-01", "high", n => `${n} page(s) don't have exactly one H1`, "The H1 states the page's topic. None leaves it unclear; several dilute it.", "Give every page one H1 matching its main topic. Logos and card titles are not H1s."],
|
|
147
|
-
"heading-skip": ["CONTENT-02", "medium", n => `${n} page(s) skip heading levels`, "Skipped levels break the outline search engines and screen readers use.", "Nest headings in order (H1 → H2 → H3). Style with CSS, not heading levels."],
|
|
148
|
-
"near-duplicate": ["CONTENT-04", "high", n => `${n} pair(s) of indexable pages share most of their main content`, "Pages that differ only by a swapped name (a city, product or tool) look like doorway or scaled content. Google can filter them out or hold down the whole site.", "Give each page its own substance: specific details, local proof, its own intro and FAQs. Merge or noindex pages that can't be made unique."],
|
|
149
|
-
"faq-reused": ["CONTENT-04", "medium", n => `${n} FAQ question(s) are reused on more than one page`, "Identical FAQs across pages add nothing unique and signal templated content.", "Give each page questions specific to it, and keep shared questions on one FAQ page."],
|
|
150
|
-
"banned-claim": ["CONTENT-10", "high", n => `${n} page(s) contain banned text`, "Banned claims (years, licences, guarantees, prices the owner has ruled out) are a legal and trust risk. Matches are leads: read the context, because an honest denial (“No, we don't work 24/7”) is fine.", "Remove or reword the claim at its source, and keep the banned list in a build check."],
|
|
151
|
-
"unconfirmed-claim": ["CONTENT-10", "needs-decision", n => `${n} page(s) contain claims the owner hasn't confirmed`, "Unconfirmed claims become false advertising if they turn out wrong.", "Ask the owner to confirm each claim. Until then, hold the text or the pages."],
|
|
152
|
-
"redirect-broken": ["URL-07", "high", n => `${n} old URL(s) end in an error instead of a live page`, "Old URLs carry backlinks, bookmarks and printed links. If they end in a 404 or a loop, that traffic and authority is lost.", "Point each old URL at its closest live page with one 301/308, covering both trailing-slash forms."],
|
|
153
|
-
"thin-page": ["CONTENT-05", "medium", n => `${n} indexable page(s) have fewer than 150 words`, "Thin pages rarely rank and can lower the site's overall quality signals.", "Add useful, specific content, merge the page into a stronger one, or noindex it until it grows."],
|
|
154
|
-
"img-alt": ["CONTENT-08", "low", n => `${n} page(s) have images without an alt attribute`, "Alt text describes images to screen readers and image search. Decorative images still need `alt=\"\"`.", "Add descriptive alt text to meaningful images and empty alt to decorative ones."],
|
|
155
|
-
"jsonld-invalid": ["SCHEMA-01", "high", n => `${n} page(s) have JSON-LD that doesn't parse`, "Invalid JSON-LD is ignored completely.", "Generate JSON-LD with JSON.stringify from data, escape `<`, and validate templates in the Rich Results Test."],
|
|
156
|
-
"org-missing": ["SCHEMA-02", "medium", () => "The home page has no Organization (or business) schema", "Organization schema identifies who runs the site and anchors every other schema node.", "Add one Organization (or the right LocalBusiness subtype) node in the root layout with a stable `@id`."],
|
|
157
|
-
"website-missing": ["SCHEMA-02", "low", () => "The home page has no WebSite schema", "WebSite schema names the site and links pages to the organization.", "Add a WebSite node with a stable `@id` and `publisher` pointing at the organization."],
|
|
158
|
-
"jsonld-none": ["SCHEMA-03", "low", n => `${n} indexable page(s) have no structured data`, "Schema tells search and AI engines what each page is.", "Add the schema type the profile assigns to each page type."],
|
|
159
|
-
"faq-not-visible": ["SCHEMA-04", "high", n => `${n} page(s) mark up FAQ questions that aren't in the page`, "Schema that describes content the page doesn't show breaks Google's guidelines and can bring a manual action.", "Build FAQPage from the same array that renders the visible FAQ, or remove it."],
|
|
160
|
-
"rating-review": ["SCHEMA-04", "needs-decision", n => `${n} page(s) carry ratings or reviews in schema`, "Ratings must come from real reviews that are visible on the page. Invented or unsourced ratings risk a manual action that removes rich results sitewide.", "Confirm each rating's source. Keep it only if real reviews are shown on the page; otherwise remove it."],
|
|
161
|
-
"deprecated-schema": ["SCHEMA-05", "low", n => `${n} page(s) use schema with no rich result (HowTo, SearchAction)`, "HowTo rich results ended in 2023 and the sitelinks search box in 2024. The markup does no harm but earns nothing.", "Remove it, or keep it knowingly. Don't promise these rich results."],
|
|
162
|
-
"breadcrumb-missing": ["SCHEMA-07", "medium", n => `${n} page(s) below the home page have no BreadcrumbList`, "Breadcrumb rich results still show in Google and clarify site structure.", "Render BreadcrumbList from the same array as the visible breadcrumb."],
|
|
163
|
-
"sitemap-missing": ["MAP-01", "high", () => "No XML sitemap found", "Without a sitemap, new and deep pages are found slowly.", "Generate `/sitemap.xml` from the live content data and reference it in robots.txt."],
|
|
164
|
-
"sitemap-not-in-robots": ["MAP-01", "low", () => "robots.txt doesn't reference the sitemap", "The `Sitemap:` line lets every crawler find it without manual submission.", "Add `Sitemap: https://…/sitemap.xml` (absolute URL) to robots.txt."],
|
|
165
|
-
"sitemap-origin": ["MAP-02", "high", n => `${n} sitemap URL(s) use a different host than the site`, "Sitemaps listing localhost, staging or the wrong www/https variant point Google at the wrong site.", "Build sitemap URLs from one production origin setting."],
|
|
166
|
-
"sitemap-noncanonical": ["MAP-02", "high", n => `${n} sitemap URL(s) canonicalize elsewhere`, "Only canonical URLs belong in the sitemap.", "List the canonical URL, or fix the page's canonical."],
|
|
167
|
-
"missing-from-sitemap": ["MAP-03", "medium", n => `${n} indexable page(s) are missing from the sitemap`, "Pages outside the sitemap are discovered and refreshed more slowly.", "Generate the sitemap from the same data as the pages so nothing is left out."],
|
|
168
|
-
"sitemap-lastmod-same": ["MAP-04", "low", () => "Every sitemap lastmod has the same date", "Identical dates usually mean the build time was used. Google learns to ignore lastmod that isn't accurate.", "Use each record's real last-updated date."],
|
|
169
|
-
"robots-missing": ["MAP-05", "medium", () => "robots.txt is missing", "Crawlers expect it; without it the sitemap isn't advertised and nothing is excluded.", "Serve robots.txt that allows crawling, blocks only junk, and lists the sitemap."],
|
|
170
|
-
"robots-blocks-assets": ["MAP-05", "medium", n => `robots.txt blocks ${n} asset path(s) needed to render pages`, "Google renders pages with their CSS and JavaScript. Blocking them can make pages look broken to Google.", "Remove Disallow rules for script, style and framework asset paths."],
|
|
171
|
-
"ai-bots-blocked": ["MAP-06", "needs-decision", n => `robots.txt blocks ${n} AI crawler(s)`, "Blocking AI crawlers can keep the site out of ChatGPT, Claude, Perplexity and Google AI answers.", "Confirm this is deliberate. A common middle ground blocks training crawlers and allows search crawlers."],
|
|
172
|
-
"llms-txt": ["MAP-07", "low", () => "No /llms.txt", "llms.txt gives AI tools a short, clean map of the site.", "Publish a Markdown llms.txt generated from the same data as the sitemap."],
|
|
173
|
-
"deep-page": ["LINK-01", "low", n => `${n} page(s) are more than three clicks from the home page`, "Deep pages are crawled less often and look less important.", "Link them from hubs or related-content blocks."],
|
|
174
|
-
"orphan": ["LINK-02", "medium", n => `${n} sitemap page(s) have no internal links pointing to them`, "A page only reachable through the sitemap looks unimportant and gets little authority.", "Link each one from its hub and from related pages."],
|
|
175
|
-
"generic-anchor": ["LINK-05", "low", n => `${n} page(s) use generic link text like “click here” or “read more”`, "Anchor text tells search engines what the target is about.", "Use descriptive anchors such as “check your DMARC record”."],
|
|
176
|
-
"too-many-links": ["LINK-06", "low", n => `${n} page(s) have more than 150 internal links`, "Huge link blocks pass little to each target and read like link farms.", "Cap related blocks and keep the footer to hubs."],
|
|
177
|
-
"lazy-lcp": ["PERF-03", "low", n => `${n} page(s) lazy-load the first image`, "If the first image is the largest element, lazy-loading it delays LCP.", "Load the hero image eagerly with high priority (`priority` / `fetchpriority=\"high\"`)."],
|
|
178
|
-
"img-dimensions": ["PERF-04", "low", n => `${n} page(s) have images without width and height`, "Images without dimensions shift the layout as they load (CLS).", "Set width and height (or an aspect-ratio box) on every image."],
|
|
179
|
-
"nosnippet": ["AI-01", "high", n => `${n} indexable page(s) block snippets (nosnippet or max-snippet:0)`, "Pages that block snippets can't appear as text snippets or be used in Google's AI Overviews and AI Mode.", "Remove nosnippet/max-snippet:0 from pages meant to be found; use data-nosnippet on specific sections instead."],
|
|
180
|
-
"html-over-2mb": ["REND-08", "high", n => `${n} page(s) send more than 2 MB of HTML`, "Googlebot reads only the first 2 MB of each HTML response. Anything after that isn't indexed.", "Move bulky inline data (hydration JSON, long lists) out of the HTML and keep head tags early."],
|
|
181
|
-
"html-size": ["PERF-06", "low", n => `${n} page(s) send more than 500 KB of HTML`, "Very large HTML slows the first render and often means inlined data that isn't needed.", "Move bulky data out of the HTML and paginate long lists."],
|
|
182
|
-
"sec-headers": ["TRUST-01", "low", n => `The site is missing ${n} recommended security header(s)`, "Security headers protect visitors and are a trust signal, especially for technical audiences.", "Add the missing headers at the server or framework level."],
|
|
183
|
-
"security-txt": ["TRUST-02", "low", () => "No /.well-known/security.txt", "security.txt tells researchers how to report vulnerabilities.", "Publish one following RFC 9116 with Contact and Expires."],
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
const findings = new Map(); // key -> {evidence:[], count}
|
|
187
|
-
function add(key, url, detail) {
|
|
188
|
-
if (!CHECKS[key]) throw new Error("unknown check " + key);
|
|
189
|
-
let f = findings.get(key);
|
|
190
|
-
if (!f) findings.set(key, (f = { evidence: [], count: 0 }));
|
|
191
|
-
f.count++;
|
|
192
|
-
if (f.evidence.length < 100) f.evidence.push(detail ? { url, detail } : { url });
|
|
193
|
-
}
|
|
194
|
-
const evaluated = new Set();
|
|
195
|
-
const evalRules = (...ids) => ids.forEach(r => evaluated.add(r));
|
|
196
|
-
|
|
197
|
-
// ---------- fetch helpers ----------
|
|
198
|
-
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
|
199
|
-
async function get(url, { manual = true, text = true } = {}) {
|
|
200
|
-
for (let attempt = 0; attempt < 2; attempt++) {
|
|
201
|
-
try {
|
|
202
|
-
const res = await fetch(url, { redirect: manual ? "manual" : "follow", headers: { "user-agent": UA, accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" }, signal: AbortSignal.timeout(20000) });
|
|
203
|
-
const ct = res.headers.get("content-type") || "";
|
|
204
|
-
let body = "";
|
|
205
|
-
if (text && res.status < 300 && /html|xml|text\/plain/.test(ct)) body = await res.text();
|
|
206
|
-
else await res.arrayBuffer().catch(() => {});
|
|
207
|
-
return { status: res.status, headers: res.headers, ct, body, location: res.headers.get("location") };
|
|
208
|
-
} catch (e) {
|
|
209
|
-
if (attempt === 1) return { status: 0, error: String(e.message || e), headers: new Headers(), ct: "", body: "" };
|
|
210
|
-
await sleep(500);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
async function follow(url) {
|
|
215
|
-
const chain = [];
|
|
216
|
-
let cur = url;
|
|
217
|
-
for (let i = 0; i < 6; i++) {
|
|
218
|
-
const r = await get(cur);
|
|
219
|
-
chain.push({ url: cur, status: r.status });
|
|
220
|
-
if (r.status >= 300 && r.status < 400 && r.location) { cur = new URL(r.location, cur).href; continue; }
|
|
221
|
-
return { ...r, chain, finalUrl: cur };
|
|
222
|
-
}
|
|
223
|
-
return { status: 0, error: "too many redirects", chain, finalUrl: cur, headers: new Headers(), ct: "", body: "" };
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// ---------- HTML helpers ----------
|
|
227
|
-
const ENT = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: " " };
|
|
228
|
-
const decode = s => s.replace(/&(#x[0-9a-f]+|#\d+|\w+);/gi, (m, e) => e[0] === "#" ? String.fromCodePoint(e[1].toLowerCase() === "x" ? parseInt(e.slice(2), 16) : parseInt(e.slice(1), 10)) : (ENT[e.toLowerCase()] ?? m));
|
|
229
|
-
function attrs(tag) {
|
|
230
|
-
const out = {};
|
|
231
|
-
const inner = tag.replace(/^<[\w-]+/, "").replace(/\/?>$/, "");
|
|
232
|
-
const re = /([^\s=\/>"']+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+)))?/g;
|
|
233
|
-
let m;
|
|
234
|
-
while ((m = re.exec(inner))) out[m[1].toLowerCase()] = decode(m[2] ?? m[3] ?? m[4] ?? "");
|
|
235
|
-
return out;
|
|
236
|
-
}
|
|
237
|
-
const tagsOf = (html, name) => [...html.matchAll(new RegExp(`<${name}\\b[^>]*>`, "gi"))].map(m => attrs(m[0]));
|
|
238
|
-
const stripNonContent = h => h.replace(/<script\b[\s\S]*?<\/script>/gi, " ").replace(/<style\b[\s\S]*?<\/style>/gi, " ").replace(/<noscript\b[\s\S]*?<\/noscript>/gi, " ").replace(/<template\b[\s\S]*?<\/template>/gi, " ").replace(/<svg\b[\s\S]*?<\/svg>/gi, " ").replace(/<!--[\s\S]*?-->/g, " ");
|
|
239
|
-
const textOf = h => decode(h.replace(/<[^>]+>/g, " ")).replace(/\s+/g, " ").trim();
|
|
240
|
-
const norm = s => s.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ").trim();
|
|
241
|
-
const FILE_EXT = /\.(pdf|png|jpe?g|gif|webp|avif|svg|ico|css|js|mjs|json|xml|txt|zip|gz|mp4|webm|mp3|woff2?|ttf|otf|csv|xlsx?|docx?|pptx?)$/i;
|
|
242
|
-
|
|
243
|
-
function jsonLdNodes(html) {
|
|
244
|
-
const nodes = [], errors = [];
|
|
245
|
-
for (const m of html.matchAll(/<script\b[^>]*type\s*=\s*["']?application\/ld\+json["']?[^>]*>([\s\S]*?)<\/script>/gi)) {
|
|
246
|
-
let data;
|
|
247
|
-
try { data = JSON.parse(m[1].trim()); } catch (e) { errors.push(String(e.message).slice(0, 120)); continue; }
|
|
248
|
-
const walk = d => { if (Array.isArray(d)) d.forEach(walk); else if (d && typeof d === "object") { if (Array.isArray(d["@graph"])) d["@graph"].forEach(walk); if (d["@type"]) nodes.push(d); } };
|
|
249
|
-
walk(data);
|
|
250
|
-
}
|
|
251
|
-
return { nodes, errors };
|
|
252
|
-
}
|
|
253
|
-
const typesOf = n => [].concat(n["@type"] || []);
|
|
254
|
-
function deepHas(obj, pred, depth = 0) {
|
|
255
|
-
if (!obj || typeof obj !== "object" || depth > 12) return false;
|
|
256
|
-
if (pred(obj)) return true;
|
|
257
|
-
return Object.values(obj).some(v => deepHas(v, pred, depth + 1));
|
|
258
|
-
}
|
|
259
|
-
const ORG_RE = /(Organization|Corporation|Business|Store|Service|Contractor|Agency|Electrician|Plumber|Locksmith|Dentist|Physician|Attorney|Restaurant|Hotel|AutoRepair|School|NGO)$/;
|
|
260
|
-
|
|
261
|
-
function ctx(text, re) {
|
|
262
|
-
const m = re.exec(text); if (!m) return null;
|
|
263
|
-
const s = Math.max(0, m.index - 60), e = Math.min(text.length, m.index + m[0].length + 60);
|
|
264
|
-
return { match: m[0], snippet: (s ? "…" : "") + text.slice(s, e) + (e < text.length ? "…" : "") };
|
|
265
|
-
}
|
|
266
|
-
function analyze(url, html, headers) {
|
|
267
|
-
const headEnd = html.search(/<\/head>/i);
|
|
268
|
-
const head = headEnd > 0 ? html.slice(0, headEnd) : html;
|
|
269
|
-
const bodyStart = html.search(/<body\b/i);
|
|
270
|
-
const bodyRaw = bodyStart >= 0 ? html.slice(bodyStart) : html;
|
|
271
|
-
const body = stripNonContent(bodyRaw);
|
|
272
|
-
const text = textOf(body);
|
|
273
|
-
const words = text ? text.split(" ").filter(w => /[\p{L}\p{N}]/u.test(w)).length : 0;
|
|
274
|
-
const metas = tagsOf(head, "meta");
|
|
275
|
-
const meta = n => metas.find(m => (m.name || m.property || "").toLowerCase() === n)?.content;
|
|
276
|
-
const titleM = head.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i);
|
|
277
|
-
const titleCount = (head.match(/<title\b/gi) || []).length;
|
|
278
|
-
const PH = /\b[Ll]orem [Ii]psum\b|\bTODO\b|\bTBD\b|\{\{\s*[\w.]+\s*\}\}|\[(?:[A-Z][A-Z _]{2,29})\]|�|\b(?:We|You|They|It|Don|Can|Isn|Won|Doesn|Didn|That|There)\?(?:ve|re|s|t|ll|d)\b/;
|
|
279
|
-
const robotsMeta = tagsOf(html, "meta").filter(m => ["robots", "googlebot"].includes((m.name || "").toLowerCase())).map(m => m.content || "").join(",").toLowerCase(); // Google honours robots meta in <body> too
|
|
280
|
-
const xRobots = (headers.get("x-robots-tag") || "").toLowerCase();
|
|
281
|
-
const canon = tagsOf(head, "link").filter(l => (l.rel || "").toLowerCase().split(/\s+/).includes("canonical")).map(l => l.href);
|
|
282
|
-
const headings = [...body.matchAll(/<h([1-6])\b[^>]*>([\s\S]*?)<\/h\1>/gi)].map(m => ({ level: +m[1], text: textOf(m[2]) }));
|
|
283
|
-
const anchors = [...body.matchAll(/<a\b([^>]*)>([\s\S]*?)<\/a>/gi)].map(m => ({ href: attrs("<a " + m[1] + ">").href, text: textOf(m[2]) }));
|
|
284
|
-
const imgs = tagsOf(body, "img");
|
|
285
|
-
const { nodes, errors } = jsonLdNodes(html);
|
|
286
|
-
const types = [...new Set(nodes.flatMap(typesOf))];
|
|
287
|
-
const faqQs = nodes.filter(n => typesOf(n).includes("FAQPage")).flatMap(n => [].concat(n.mainEntity || [])).map(q => q && q.name).filter(Boolean);
|
|
288
|
-
const crumbs = nodes.filter(n => typesOf(n).includes("BreadcrumbList")).flatMap(n => [].concat(n.itemListElement || [])).map(i => i && (typeof i.item === "string" ? i.item : i.item && (i.item["@id"] || i.item.url))).filter(Boolean);
|
|
289
|
-
const hasRating = nodes.some(n => deepHas(n, o => "aggregateRating" in o || typesOf(o).some(t => t === "AggregateRating" || t === "Review")));
|
|
290
|
-
const deprecated = [...new Set([...types.filter(t => t === "HowTo"), ...(nodes.some(n => deepHas(n, o => typesOf(o).includes("SearchAction"))) ? ["SearchAction"] : [])])];
|
|
291
|
-
const phMatch = text.match(PH);
|
|
292
|
-
const mainM = body.match(/<main\b[^>]*>([\s\S]*?)<\/main>/i);
|
|
293
|
-
const mainHtml = mainM ? mainM[1] : body.replace(/<(header|nav|footer|aside)\b[\s\S]*?<\/\1>/gi, " ");
|
|
294
|
-
const mw = textOf(mainHtml).toLowerCase().split(" ").filter(w => /[\p{L}\p{N}]/u.test(w));
|
|
295
|
-
const mainHrefs = [...mainHtml.matchAll(/<a\b([^>]*)>/gi)].map(m => attrs("<a " + m[1] + ">").href).filter(Boolean);
|
|
296
|
-
let shingles = null;
|
|
297
|
-
if (mw.length >= 50) { shingles = new Set(); for (let i = 0; i + 5 <= mw.length; i++) shingles.add(mw.slice(i, i + 5).join(" ")); }
|
|
298
|
-
const emptyRoot = /<div[^>]+id=["'](root|app|__next|__nuxt)["'][^>]*>\s*<\/div>/i.test(bodyRaw);
|
|
299
|
-
return {
|
|
300
|
-
title: titleM ? textOf(titleM[1]) : null, description: meta("description") ?? null,
|
|
301
|
-
ogTitle: meta("og:title") ?? null, ogImage: meta("og:image") ?? null,
|
|
302
|
-
lang: (html.match(/<html\b[^>]*\blang\s*=\s*["']?([\w-]+)/i) || [])[1] || null,
|
|
303
|
-
noindex: /noindex/.test(robotsMeta) || /noindex/.test(xRobots), canonicals: canon,
|
|
304
|
-
nosnippet: /nosnippet|max-snippet\s*:\s*0\b/.test(robotsMeta + "," + xRobots),
|
|
305
|
-
headings, h1Count: headings.filter(h => h.level === 1).length, words, normText: norm(text),
|
|
306
|
-
anchors, imgs, types, jsonldErrors: errors, faqQs, crumbs, hasRating, deprecated, emptyRoot,
|
|
307
|
-
mainHrefs, banned: BANNED ? ctx(text, BANNED) : null, unconfirmed: VERIFY ? ctx(text, VERIFY) : null, shingles, titleCount, placeholder: phMatch ? phMatch[0] : null,
|
|
308
|
-
hashLinks: anchors.filter(l => !l.href || l.href === "#" || /^javascript:/i.test(l.href)).length,
|
|
309
|
-
mixed: url.startsWith("https:") && /\ssrc\s*=\s*["']http:\/\//i.test(bodyRaw),
|
|
310
|
-
scripts: (html.match(/<script\b[^>]*\bsrc=/gi) || []).length, bytes: Buffer.byteLength(html),
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// ---------- robots ----------
|
|
315
|
-
function parseRobots(txt) {
|
|
316
|
-
const groups = []; let cur = null; const sitemaps = [];
|
|
317
|
-
for (const raw of txt.split(/\r?\n/)) {
|
|
318
|
-
const line = raw.replace(/#.*/, "").trim(); if (!line) continue;
|
|
319
|
-
const i = line.indexOf(":"); if (i < 0) continue;
|
|
320
|
-
const k = line.slice(0, i).trim().toLowerCase(), v = line.slice(i + 1).trim();
|
|
321
|
-
if (k === "sitemap") { sitemaps.push(v); continue; }
|
|
322
|
-
if (k === "user-agent") { if (!cur || cur.rules.length) groups.push(cur = { agents: [], rules: [] }); cur.agents.push(v.toLowerCase()); continue; }
|
|
323
|
-
if ((k === "allow" || k === "disallow") && cur) cur.rules.push({ allow: k === "allow", path: v });
|
|
324
|
-
}
|
|
325
|
-
return { groups, sitemaps };
|
|
326
|
-
}
|
|
327
|
-
const ruleRe = p => new RegExp("^" + p.replace(/[.+?^{}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\\\$$/, "$").replace(/\$$/, "$"));
|
|
328
|
-
function allowedBy(group, path) {
|
|
329
|
-
if (!group) return true;
|
|
330
|
-
let best = null;
|
|
331
|
-
for (const r of group.rules) { if (!r.path) continue; if (ruleRe(r.path).test(path) && (!best || r.path.length > best.path.length || (r.path.length === best.path.length && r.allow))) best = r; }
|
|
332
|
-
return !best || best.allow;
|
|
333
|
-
}
|
|
334
|
-
const groupFor = (robots, agent) => robots.groups.find(g => g.agents.includes(agent.toLowerCase())) || null;
|
|
335
|
-
|
|
336
|
-
// ---------- sitemap ----------
|
|
337
|
-
async function readSitemaps(urls) {
|
|
338
|
-
const entries = [], seen = new Set(), files = [];
|
|
339
|
-
const queue = [...urls];
|
|
340
|
-
while (queue.length && files.length < 60) {
|
|
341
|
-
const u = queue.shift(); if (seen.has(u)) continue; seen.add(u);
|
|
342
|
-
const r = await get(toCrawl(u), { manual: false });
|
|
343
|
-
if (r.status !== 200 || !r.body) { files.push({ url: u, status: r.status }); continue; }
|
|
344
|
-
files.push({ url: u, status: 200 });
|
|
345
|
-
if (/<sitemapindex\b/i.test(r.body)) { for (const m of r.body.matchAll(/<sitemap\b[\s\S]*?<loc>\s*([\s\S]*?)\s*<\/loc>/gi)) queue.push(decode(m[1].trim())); continue; }
|
|
346
|
-
for (const m of r.body.matchAll(/<url\b[^>]*>([\s\S]*?)<\/url>/gi)) {
|
|
347
|
-
const loc = (m[1].match(/<loc>\s*([\s\S]*?)\s*<\/loc>/i) || [])[1];
|
|
348
|
-
const lastmod = (m[1].match(/<lastmod>\s*([\s\S]*?)\s*<\/lastmod>/i) || [])[1];
|
|
349
|
-
if (loc) entries.push({ loc: decode(loc.trim()), lastmod: lastmod ? lastmod.trim() : null });
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return { entries, files };
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// ---------- URL helpers ----------
|
|
356
|
-
const isLocal = o => /^https?:\/\/(localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\])(:\d+)?$/i.test(o);
|
|
357
|
-
function toCrawl(u) { // map public-origin URLs onto the crawl origin
|
|
358
|
-
try { const x = new URL(u); if (SITE_ORIGIN && x.origin === SITE_ORIGIN && SITE_ORIGIN !== START_ORIGIN) return START_ORIGIN + x.pathname + x.search; return x.href; } catch { return u; }
|
|
359
|
-
}
|
|
360
|
-
function clean(u, base) {
|
|
361
|
-
try { const x = new URL(u, base); x.hash = ""; return x.href; } catch { return null; }
|
|
362
|
-
}
|
|
363
|
-
const pathKey = u => { const x = new URL(u); return x.pathname + x.search; };
|
|
264
|
+
// Sitemap <xhtml:link> hreflang by crawl URL, built on first use: `sm` is only read later, before the crawl starts.
|
|
265
|
+
let smHreflang;
|
|
266
|
+
const sitemapHreflang = u =>
|
|
267
|
+
(smHreflang ||= new Map(sm.entries.filter(e => e.hreflang).map(e => [clean(toCrawl(e.loc)), e.hreflang]))).get(
|
|
268
|
+
clean(u),
|
|
269
|
+
) || [];
|
|
270
|
+
// analyze()'s context (crawl/page.mjs). toCrawl and sitemapHreflang are passed as functions: their data arrives later.
|
|
271
|
+
const page = { start: START, startOrigin: START_ORIGIN, banned: BANNED, verify: VERIFY, toCrawl, sitemapHreflang };
|
|
364
272
|
|
|
365
273
|
// ---------- crawl ----------
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
const rec = { url: u, status: r.status, finalUrl: r.finalUrl, chain: r.chain, error: r.error || null, headers: r.headers };
|
|
380
|
-
pages.set(u, rec);
|
|
381
|
-
if (r.status === 200 && /html/.test(r.ct) && r.body) {
|
|
382
|
-
const a = analyze(r.finalUrl, r.body, r.headers);
|
|
383
|
-
Object.assign(rec, a, { html: true });
|
|
384
|
-
rec.links = [];
|
|
385
|
-
rec.mainLinks = new Set(a.mainHrefs.map(h => clean(h, r.finalUrl)).filter(Boolean));
|
|
386
|
-
for (const l of a.anchors) {
|
|
387
|
-
if (!l.href || /^(mailto|tel|javascript|sms):/i.test(l.href)) continue;
|
|
388
|
-
const c = clean(l.href, r.finalUrl); if (!c) continue;
|
|
389
|
-
if (new URL(c).origin !== START_ORIGIN) continue;
|
|
390
|
-
rec.links.push({ url: c, text: l.text });
|
|
391
|
-
enqueue(c, r.finalUrl);
|
|
392
|
-
}
|
|
393
|
-
for (const b of a.crumbs) enqueue(toCrawl(b), r.finalUrl);
|
|
394
|
-
for (const c of a.canonicals.slice(0, 1)) if (c) enqueue(toCrawl(new URL(c, r.finalUrl).href), r.finalUrl);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
async function runQueue() {
|
|
398
|
-
await new Promise(done => {
|
|
399
|
-
let active = 0;
|
|
400
|
-
const pump = () => {
|
|
401
|
-
while (active < CONC && queue.length && fetched < MAX) {
|
|
402
|
-
const u = queue.shift(); active++; fetched++;
|
|
403
|
-
crawlOne(u).catch(e => pages.set(u, { url: u, status: 0, error: String(e) })).finally(() => { active--; pump(); });
|
|
404
|
-
}
|
|
405
|
-
if (fetched >= MAX && queue.length) capped = true;
|
|
406
|
-
if (active === 0 && (!queue.length || fetched >= MAX)) done();
|
|
407
|
-
};
|
|
408
|
-
pump();
|
|
409
|
-
});
|
|
410
|
-
}
|
|
274
|
+
const crawler = createCrawler({
|
|
275
|
+
start: START,
|
|
276
|
+
startOrigin: START_ORIGIN,
|
|
277
|
+
max: MAX,
|
|
278
|
+
conc: CONC,
|
|
279
|
+
includeQuery: INCLUDE_QUERY,
|
|
280
|
+
inSection,
|
|
281
|
+
fetcher: { follow, xRobotsLines },
|
|
282
|
+
page,
|
|
283
|
+
toCrawl,
|
|
284
|
+
notes,
|
|
285
|
+
});
|
|
286
|
+
const { pages, queue, seen, enqueue } = crawler;
|
|
411
287
|
|
|
412
288
|
// ---------- main ----------
|
|
413
289
|
const t0 = Date.now();
|
|
414
|
-
|
|
415
|
-
const
|
|
416
|
-
const robots = robotsRes.status === 200 && robotsRes.body && !/<html/i.test(robotsRes.body) ? parseRobots(robotsRes.body) : null;
|
|
417
|
-
evalRules("CRAWL-01", "MAP-05", "MAP-06", "MAP-01");
|
|
418
|
-
const star = robots ? groupFor(robots, "*") : null;
|
|
419
|
-
if (!robots) add("robots-missing", START_ORIGIN + "/robots.txt", `status ${robotsRes.status}`);
|
|
420
|
-
else {
|
|
421
|
-
if (star && !allowedBy(star, "/")) add("robots-blocks-all", START_ORIGIN + "/robots.txt", "User-agent: * is not allowed to crawl /");
|
|
422
|
-
for (const p of ["/_next/static/x.js", "/assets/x.js", "/static/x.css", "/x.css", "/x.js"]) if (star && !allowedBy(star, p) && allowedBy(star, "/")) add("robots-blocks-assets", START_ORIGIN + "/robots.txt", `blocks ${p.replace(/x\.(js|css)$/, "")}`);
|
|
423
|
-
const AI = ["GPTBot", "OAI-SearchBot", "ChatGPT-User", "ClaudeBot", "Claude-SearchBot", "Claude-User", "anthropic-ai", "Claude-Web", "PerplexityBot", "Google-Extended", "CCBot", "Applebot-Extended", "Bytespider", "meta-externalagent"];
|
|
424
|
-
for (const bot of AI) { const g = groupFor(robots, bot); if (g && !allowedBy(g, "/")) add("ai-bots-blocked", START_ORIGIN + "/robots.txt", bot); }
|
|
425
|
-
if (!robots.sitemaps.length) add("sitemap-not-in-robots", START_ORIGIN + "/robots.txt");
|
|
426
|
-
}
|
|
427
|
-
// sitemaps
|
|
290
|
+
const robotsRes = await follow(START_ORIGIN + "/robots.txt", undefined, 5); // Google stops after 5 hops here, 10 for pages
|
|
291
|
+
const { robots, robotsDown, star } = checkRobots(robotsRes, { add, evalRules, startOrigin: START_ORIGIN });
|
|
428
292
|
const smUrls = robots && robots.sitemaps.length ? robots.sitemaps : [START_ORIGIN + "/sitemap.xml"];
|
|
429
293
|
const firstSm = smUrls[0];
|
|
430
|
-
if (!SITE_ORIGIN) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
if (
|
|
434
|
-
|
|
435
|
-
|
|
294
|
+
if (!SITE_ORIGIN) {
|
|
295
|
+
try {
|
|
296
|
+
const o = new URL(firstSm).origin;
|
|
297
|
+
if (o !== START_ORIGIN) SITE_ORIGIN = o;
|
|
298
|
+
} catch {}
|
|
299
|
+
}
|
|
300
|
+
const smListed = !!(robots && robots.sitemaps.length);
|
|
301
|
+
const sm = await findSitemaps(smUrls, smListed, {
|
|
302
|
+
startOrigin: START_ORIGIN,
|
|
303
|
+
notes,
|
|
304
|
+
fetchSitemap,
|
|
305
|
+
toCrawl,
|
|
306
|
+
conc: CONC,
|
|
307
|
+
});
|
|
308
|
+
if (!SITE_ORIGIN && sm.entries.length) {
|
|
309
|
+
try {
|
|
310
|
+
const o = new URL(sm.entries[0].loc).origin;
|
|
311
|
+
if (o !== START_ORIGIN && !isLocal(o)) SITE_ORIGIN = o;
|
|
312
|
+
} catch {}
|
|
313
|
+
}
|
|
314
|
+
checkSitemapFiles(sm, smUrls, { add, findings });
|
|
315
|
+
// The home page goes first: its canonical may give the public origin.
|
|
436
316
|
enqueue(START.href);
|
|
437
|
-
await
|
|
317
|
+
await crawler.run();
|
|
438
318
|
const home = pages.get(START.href);
|
|
439
|
-
if (!SITE_ORIGIN && home && home.canonicals && home.canonicals[0]) {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
evalRules("MAP-02", "MAP-04");
|
|
445
|
-
for (const e of sm.entries) {
|
|
446
|
-
let o; try { o = new URL(e.loc).origin; } catch { continue; }
|
|
447
|
-
if (o !== EXPECT_ORIGIN) add("sitemap-origin", e.loc, `expected ${EXPECT_ORIGIN}`);
|
|
448
|
-
const c = clean(toCrawl(e.loc)); if (!c) continue;
|
|
449
|
-
smSet.set(c, e);
|
|
450
|
-
if (new URL(c).origin === START_ORIGIN && !seen.has(c)) { seen.add(c); queue.push(c); }
|
|
451
|
-
}
|
|
452
|
-
const lm = sm.entries.map(e => (e.lastmod || "").slice(0, 10)).filter(Boolean);
|
|
453
|
-
if (lm.length >= 5 && new Set(lm).size === 1) add("sitemap-lastmod-same", firstSm, `all ${lm.length} entries: ${lm[0]}`);
|
|
454
|
-
await runQueue();
|
|
455
|
-
|
|
456
|
-
// probes: soft 404, slash variants, well-known files, security headers
|
|
457
|
-
evalRules("CRAWL-05", "URL-02", "MAP-07", "TRUST-01", "TRUST-02");
|
|
458
|
-
const probe = await follow(`${START_ORIGIN}/seo-supervisor-404-probe-${Date.now().toString(36)}`);
|
|
459
|
-
if (probe.status === 200) add("soft-404", probe.chain[0].url, probe.chain.length > 1 ? `redirected to ${probe.finalUrl} (200)` : "returned 200");
|
|
460
|
-
const llms = await get(START_ORIGIN + "/llms.txt", { manual: false });
|
|
461
|
-
if (llms.status !== 200 || /<html/i.test(llms.body || "")) add("llms-txt", START_ORIGIN + "/llms.txt", llms.status === 200 ? "returns an HTML page instead (soft 404)" : `status ${llms.status}`);
|
|
462
|
-
const sectxt = await get(START_ORIGIN + "/.well-known/security.txt", { manual: false });
|
|
463
|
-
if (sectxt.status !== 200 || /<html/i.test(sectxt.body || "")) add("security-txt", START_ORIGIN + "/.well-known/security.txt", sectxt.status === 200 ? "returns an HTML page instead (soft 404)" : `status ${sectxt.status}`);
|
|
464
|
-
if (home && home.headers) {
|
|
465
|
-
const h = home.headers, missing = [];
|
|
466
|
-
if (EXPECT_ORIGIN.startsWith("https") && START_ORIGIN.startsWith("https") && !h.get("strict-transport-security")) missing.push("Strict-Transport-Security");
|
|
467
|
-
if (!h.get("x-content-type-options")) missing.push("X-Content-Type-Options");
|
|
468
|
-
if (!h.get("referrer-policy")) missing.push("Referrer-Policy");
|
|
469
|
-
if (!h.get("content-security-policy") && !h.get("content-security-policy-report-only")) missing.push("Content-Security-Policy");
|
|
470
|
-
if (!h.get("x-frame-options") && !/frame-ancestors/i.test(h.get("content-security-policy") || "")) missing.push("X-Frame-Options or CSP frame-ancestors");
|
|
471
|
-
for (const m of missing) add("sec-headers", home.finalUrl, m);
|
|
472
|
-
if (isLocal(START_ORIGIN)) notes.push("Security headers were read from a local server; production headers set by a CDN or proxy may differ.");
|
|
319
|
+
if (!SITE_ORIGIN && home && home.canonicals && home.canonicals[0]) {
|
|
320
|
+
try {
|
|
321
|
+
const o = new URL(home.canonicals[0], home.base).origin;
|
|
322
|
+
if (o !== START_ORIGIN && !isLocal(o)) SITE_ORIGIN = o;
|
|
323
|
+
} catch {}
|
|
473
324
|
}
|
|
325
|
+
const EXPECT_ORIGIN = SITE_ORIGIN || START_ORIGIN;
|
|
326
|
+
if (SITE_ORIGIN && SITE_ORIGIN !== START_ORIGIN)
|
|
327
|
+
notes.push(`Public origin ${SITE_ORIGIN} was mapped onto ${START_ORIGIN} for crawling.`);
|
|
328
|
+
const smSet = checkSitemapEntries(sm, firstSm, {
|
|
329
|
+
add,
|
|
330
|
+
notes,
|
|
331
|
+
evalRules,
|
|
332
|
+
expectOrigin: EXPECT_ORIGIN,
|
|
333
|
+
startOrigin: START_ORIGIN,
|
|
334
|
+
toCrawl,
|
|
335
|
+
inSection,
|
|
336
|
+
crawler: { seen, queue },
|
|
337
|
+
});
|
|
338
|
+
await crawler.run();
|
|
339
|
+
const { fetched, capped } = crawler; // final from here: the queue runs no more
|
|
340
|
+
// A page over the read limit (crawl/queue.mjs) isn't read, but it's surely past Googlebot's 2 MB too (REND-08).
|
|
341
|
+
for (const p of pages.values())
|
|
342
|
+
if (p.over) add("html-over-2mb", p.finalUrl, `over ${PAGE_MAX / 1048576} MB once unpacked, so it wasn't read`);
|
|
343
|
+
// Pages a bot challenge answered instead (crawl/queue.mjs): not checked, and not reported as broken either.
|
|
344
|
+
if (crawler.challenges.length)
|
|
345
|
+
notes.push(
|
|
346
|
+
`${crawler.challenges.length} page(s) answered with a bot challenge (from Cloudflare or AWS WAF) instead of the page, e.g. ${quote(crawler.challenges[0])}, so they weren't checked. Let the crawler through (allow this machine's address, or the user agent ${UA}) or crawl a staging copy, then run it again.`,
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
// Soft 404, llms.txt, Markdown, security.txt and the home page's security headers.
|
|
350
|
+
const mdHome = await probeSite({
|
|
351
|
+
start: START,
|
|
352
|
+
startOrigin: START_ORIGIN,
|
|
353
|
+
expectOrigin: EXPECT_ORIGIN,
|
|
354
|
+
checkLive: CHECK_LIVE,
|
|
355
|
+
conc: CONC,
|
|
356
|
+
home,
|
|
357
|
+
add,
|
|
358
|
+
evalRules,
|
|
359
|
+
notes,
|
|
360
|
+
follow,
|
|
361
|
+
get,
|
|
362
|
+
pages,
|
|
363
|
+
});
|
|
474
364
|
|
|
475
365
|
// ---------- per-page checks ----------
|
|
476
|
-
evalRules(
|
|
366
|
+
evalRules(
|
|
367
|
+
"AI-01",
|
|
368
|
+
"REND-08",
|
|
369
|
+
"CONTENT-04",
|
|
370
|
+
"REND-04",
|
|
371
|
+
"CONTENT-09",
|
|
372
|
+
"CRAWL-02",
|
|
373
|
+
"CRAWL-06",
|
|
374
|
+
"CRAWL-07",
|
|
375
|
+
"CRAWL-08",
|
|
376
|
+
"URL-01",
|
|
377
|
+
"URL-04",
|
|
378
|
+
"URL-05",
|
|
379
|
+
"REND-01",
|
|
380
|
+
"META-01",
|
|
381
|
+
"META-02",
|
|
382
|
+
"META-04",
|
|
383
|
+
"META-05",
|
|
384
|
+
"CONTENT-01",
|
|
385
|
+
"CONTENT-02",
|
|
386
|
+
"CONTENT-05",
|
|
387
|
+
"CONTENT-08",
|
|
388
|
+
"SCHEMA-01",
|
|
389
|
+
"SCHEMA-02",
|
|
390
|
+
"SCHEMA-03",
|
|
391
|
+
"SCHEMA-04",
|
|
392
|
+
"SCHEMA-05",
|
|
393
|
+
"SCHEMA-07",
|
|
394
|
+
"MAP-03",
|
|
395
|
+
"LINK-01",
|
|
396
|
+
"LINK-02",
|
|
397
|
+
"LINK-05",
|
|
398
|
+
"LINK-06",
|
|
399
|
+
"PERF-03",
|
|
400
|
+
"PERF-04",
|
|
401
|
+
"PERF-06",
|
|
402
|
+
"REND-09",
|
|
403
|
+
"META-06",
|
|
404
|
+
"MEDIA-03",
|
|
405
|
+
);
|
|
477
406
|
if (BRAND) evalRules("META-03");
|
|
478
407
|
if (BANNED || VERIFY) evalRules("CONTENT-10");
|
|
479
408
|
const all = [...pages.values()];
|
|
480
|
-
const byFinal = new Map();
|
|
481
|
-
const
|
|
409
|
+
const byFinal = new Map();
|
|
410
|
+
for (const p of all) if (p.finalUrl) byFinal.set(p.finalUrl, p);
|
|
411
|
+
// One record per page: a link or canonical to a URL that redirects fetches its page again, so the direct fetch is kept.
|
|
412
|
+
const byPage = new Map();
|
|
413
|
+
for (const p of all) if (p.html && (!byPage.has(p.finalUrl) || p.url === p.finalUrl)) byPage.set(p.finalUrl, p);
|
|
414
|
+
const htmlPages = [...byPage.values()];
|
|
482
415
|
const finalOf = u => pages.get(u)?.finalUrl || u;
|
|
483
416
|
const isHome = p => new URL(p.finalUrl).pathname === "/";
|
|
484
417
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
418
|
+
const canonicalFor = p => {
|
|
419
|
+
const c = p.canonicals && p.canonicals[0];
|
|
420
|
+
return c ? (urlOr(c, p.base)?.href ?? null) : null;
|
|
421
|
+
};
|
|
422
|
+
const samePath = (a, b) => new URL(a).pathname === new URL(b).pathname;
|
|
423
|
+
const indexable = p =>
|
|
424
|
+
p.html &&
|
|
425
|
+
(IGNORE_NOINDEX || !p.noindex) &&
|
|
426
|
+
(() => {
|
|
427
|
+
const c = canonicalFor(p);
|
|
428
|
+
return !c || samePath(toCrawl(c), p.finalUrl);
|
|
429
|
+
})();
|
|
430
|
+
// The site's own hosts, with or without www: on an HTTPS site an http:// link to them costs a redirect.
|
|
431
|
+
const bareHost = h => h.replace(/^www\./, "");
|
|
432
|
+
const selfHosts = new Set([START_ORIGIN, EXPECT_ORIGIN].map(o => bareHost(new URL(o).host)));
|
|
433
|
+
const extra = {}; // data for the report, filled by the site-wide checks below
|
|
434
|
+
// Shared context for the site-wide checks. From here on only the page records' own fields, `all` (old URLs join it),
|
|
435
|
+
// extra, notes, notChecked and the finding store change.
|
|
436
|
+
const site = {
|
|
437
|
+
all,
|
|
438
|
+
pages,
|
|
439
|
+
byPage,
|
|
440
|
+
byFinal,
|
|
441
|
+
htmlPages,
|
|
442
|
+
home,
|
|
443
|
+
smSet,
|
|
444
|
+
robots,
|
|
445
|
+
star,
|
|
446
|
+
add,
|
|
447
|
+
evalRules,
|
|
448
|
+
evaluated,
|
|
449
|
+
findings,
|
|
450
|
+
notes,
|
|
451
|
+
notChecked,
|
|
452
|
+
extra,
|
|
453
|
+
ignoreNoindex: IGNORE_NOINDEX,
|
|
454
|
+
brand: BRAND,
|
|
455
|
+
start: START,
|
|
456
|
+
startOrigin: START_ORIGIN,
|
|
457
|
+
expectOrigin: EXPECT_ORIGIN,
|
|
458
|
+
conc: CONC,
|
|
459
|
+
toCrawl,
|
|
460
|
+
get,
|
|
461
|
+
follow,
|
|
462
|
+
firstBytes,
|
|
463
|
+
finalOf,
|
|
464
|
+
isHome,
|
|
465
|
+
canonicalFor,
|
|
466
|
+
samePath,
|
|
467
|
+
indexable,
|
|
468
|
+
bareHost,
|
|
469
|
+
selfHosts,
|
|
470
|
+
};
|
|
471
|
+
const { checkedPages, images, shareImages, titleWords, brandWords, acronyms, localBusiness } = checkPages(site);
|
|
472
|
+
// Runs before the Googlebot test. Each image is asked once; extra.images reuses the rows.
|
|
473
|
+
const { imageRows, imageInfo } = await checkAssets(site, { images, shareImages });
|
|
474
|
+
const { inbound } = checkLinks(site);
|
|
475
|
+
const style = await slashStyle(site, SLASH);
|
|
476
|
+
|
|
477
|
+
// ---------- old URLs / redirect sources ----------
|
|
478
|
+
const redirectSources = await oldUrls(site, { urlList: URL_LIST, nextManifest: NEXT_MANIFEST });
|
|
479
|
+
|
|
480
|
+
// ---------- live origin: certificate, http→https and other-host redirects, HSTS ----------
|
|
481
|
+
// One deeper page tests whether the other host's redirect keeps the path.
|
|
482
|
+
const live =
|
|
483
|
+
CHECK_LIVE && EXPECT_ORIGIN.startsWith("https:") && isPublic(EXPECT_ORIGIN)
|
|
484
|
+
? await checkLive(EXPECT_ORIGIN, {
|
|
485
|
+
add,
|
|
486
|
+
path: (p => p && new URL(p.finalUrl).pathname)(htmlPages.find(p => !isHome(p) && indexable(p))),
|
|
487
|
+
})
|
|
488
|
+
: null;
|
|
489
|
+
if (live) notes.push(...live.notes);
|
|
490
|
+
if (live && !live.unresolved) evalRules("TRUST-07", "URL-03");
|
|
491
|
+
else
|
|
492
|
+
for (const rule of ["TRUST-07", "URL-03"])
|
|
493
|
+
notChecked.push({
|
|
494
|
+
rule,
|
|
495
|
+
area: `${rule} ${RULES[rule][0]}`,
|
|
496
|
+
reason: live
|
|
497
|
+
? `${new URL(EXPECT_ORIGIN).hostname} doesn't resolve in DNS yet; run --check-live once the site is live.`
|
|
498
|
+
: CHECK_LIVE
|
|
499
|
+
? "--check-live needs a public https:// origin; pass --site-origin."
|
|
500
|
+
: "Pass --check-live once the site is live.",
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
// ---------- outside checks: real-user speed ----------
|
|
504
|
+
/** @typedef {{ trend?: any, lcpBreakdown?: any, note?: string }} TrendResult */
|
|
505
|
+
/** @type {{ strategy: string, samples: any[], trend?: any, lcpBreakdown?: any, desktop?: any, tablet?: any, pageTrend?: any }} */
|
|
506
|
+
let speed;
|
|
507
|
+
let speedReason = OUTSIDE
|
|
508
|
+
? "Speed data needs the public, live site; pass --site-origin."
|
|
509
|
+
: "Outside checks are off. With the owner's go-ahead, --outside fetches real-user speed data from Google PageSpeed Insights.";
|
|
510
|
+
const SPEED_ON = OUTSIDE && isPublic(EXPECT_ORIGIN),
|
|
511
|
+
PSI_AT = typeof args["psi-endpoint"] === "string" ? args["psi-endpoint"] : PSI_ENDPOINT,
|
|
512
|
+
CRUX_AT = typeof args["crux-endpoint"] === "string" ? args["crux-endpoint"] : CRUX_HISTORY_ENDPOINT;
|
|
513
|
+
const speedUrls = SPEED_ON
|
|
514
|
+
? sampleUrls(
|
|
515
|
+
htmlPages
|
|
516
|
+
.filter(p => indexable(p) && !p.clientOnly)
|
|
517
|
+
.map(p => {
|
|
518
|
+
const x = new URL(p.finalUrl);
|
|
519
|
+
return EXPECT_ORIGIN + x.pathname + x.search;
|
|
520
|
+
}),
|
|
521
|
+
)
|
|
522
|
+
: [];
|
|
523
|
+
let speedLimited = false;
|
|
524
|
+
if (SPEED_ON) {
|
|
525
|
+
const r = await checkSpeed(speedUrls, { add, endpoint: PSI_AT, key: process.env.PSI_API_KEY });
|
|
526
|
+
if (r.samples.length) speed = { strategy: "mobile", samples: r.samples };
|
|
527
|
+
notes.push(...r.notes);
|
|
528
|
+
speedLimited = r.limited;
|
|
529
|
+
// PERF-01 counts as checked only when real-user data came back for at least one page.
|
|
530
|
+
if (r.samples.some(s => s.field)) {
|
|
531
|
+
evalRules("PERF-01");
|
|
532
|
+
speedReason = null;
|
|
533
|
+
} else
|
|
534
|
+
speedReason = r.limited
|
|
535
|
+
? "PageSpeed refused the requests. Set PSI_API_KEY (a free Google Cloud API key for the PageSpeed Insights API) and re-run."
|
|
536
|
+
: "No real-user data came back for the sampled pages (too few Chrome visits, or PageSpeed failed); see the notes.";
|
|
490
537
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
538
|
+
if (speedReason) notChecked.push({ rule: "PERF-01", area: `PERF-01 ${RULES["PERF-01"][0]}`, reason: speedReason });
|
|
539
|
+
// The 25-week trend for the whole origin, only with a key (CRUX_API_KEY, or a PSI_API_KEY with the CrUX API enabled).
|
|
540
|
+
const CRUX_KEY = process.env.CRUX_API_KEY || process.env.PSI_API_KEY;
|
|
541
|
+
if (SPEED_ON && CRUX_KEY) {
|
|
542
|
+
const t = /** @type {TrendResult} */ (
|
|
543
|
+
await speedTrend(EXPECT_ORIGIN, { key: CRUX_KEY, endpoint: CRUX_AT }).catch(e => ({
|
|
544
|
+
note: `CrUX history failed (${e.message}).`,
|
|
545
|
+
}))
|
|
546
|
+
);
|
|
547
|
+
if (t.trend)
|
|
548
|
+
speed = {
|
|
549
|
+
...(speed || { strategy: "mobile", samples: [] }),
|
|
550
|
+
trend: t.trend,
|
|
551
|
+
...(t.lcpBreakdown ? { lcpBreakdown: t.lcpBreakdown } : {}),
|
|
552
|
+
};
|
|
553
|
+
if (t.note) notes.push(t.note);
|
|
496
554
|
}
|
|
497
|
-
//
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
if (p.titleCount > 1) add("title-multiple", u, `${p.titleCount} <title> tags`);
|
|
532
|
-
if (p.placeholder) add("placeholder-text", u, `“${p.placeholder}”`);
|
|
533
|
-
if (p.hashLinks) add("href-hash", u, `${p.hashLinks} link(s)`);
|
|
534
|
-
if (p.mixed) add("mixed-content", u);
|
|
535
|
-
if (!p.title) add("title-missing", u);
|
|
536
|
-
else {
|
|
537
|
-
if (p.title.length > 60) add("title-long", u, `${p.title.length} chars: ${p.title}`);
|
|
538
|
-
else if (p.title.length < 20) add("title-short", u, p.title);
|
|
539
|
-
(titleMap.get(p.title) || titleMap.set(p.title, []).get(p.title)).push(u);
|
|
540
|
-
if (BRAND && p.title.split(BRAND).length > 2) add("title-brand-twice", u, p.title);
|
|
541
|
-
}
|
|
542
|
-
if (!p.description) add("desc-missing", u);
|
|
543
|
-
else {
|
|
544
|
-
if (p.description.length < 120 || p.description.length > 160) add("desc-length", u, `${p.description.length} chars`);
|
|
545
|
-
(descMap.get(p.description) || descMap.set(p.description, []).get(p.description)).push(u);
|
|
546
|
-
}
|
|
547
|
-
if (!p.ogTitle || !p.ogImage) add("og-missing", u, [!p.ogTitle && "og:title", !p.ogImage && "og:image"].filter(Boolean).join(", "));
|
|
548
|
-
if (p.h1Count !== 1) add("h1-count", u, `${p.h1Count} H1s`);
|
|
549
|
-
const skips = []; let prev = null;
|
|
550
|
-
for (const h of p.headings) { if (prev !== null && h.level > prev + 1) skips.push(`H${prev} → H${h.level} (“${h.text.slice(0, 40)}”)`); prev = h.level; }
|
|
551
|
-
if (skips.length) add("heading-skip", u, skips.slice(0, 3).join("; "));
|
|
552
|
-
if (p.words < 150 && !(p.words < 30 && p.h1Count === 0)) add("thin-page", u, `${p.words} words`);
|
|
553
|
-
const noAlt = p.imgs.filter(i => !("alt" in i)).length;
|
|
554
|
-
if (noAlt) add("img-alt", u, `${noAlt} image(s)`);
|
|
555
|
-
const noDim = p.imgs.filter(i => !(i.width && i.height) && i["data-nimg"] !== "fill" && !/position:\s*absolute/i.test(i.style || "")).length;
|
|
556
|
-
if (noDim) add("img-dimensions", u, `${noDim} image(s)`);
|
|
557
|
-
if (p.imgs[0] && (p.imgs[0].loading || "").toLowerCase() === "lazy") add("lazy-lcp", u, p.imgs[0].src || "");
|
|
558
|
-
if (p.bytes > 2 * 1024 * 1024) add("html-over-2mb", u, `${Math.round(p.bytes / 1024)} KB`);
|
|
559
|
-
else if (p.bytes > 500 * 1024) add("html-size", u, `${Math.round(p.bytes / 1024)} KB`);
|
|
560
|
-
if (p.nosnippet) add("nosnippet", u);
|
|
561
|
-
if (p.jsonldErrors.length) add("jsonld-invalid", u, p.jsonldErrors[0]);
|
|
562
|
-
if (!p.types.length) add("jsonld-none", u);
|
|
563
|
-
if (!isHome(p) && !p.types.includes("BreadcrumbList")) add("breadcrumb-missing", u);
|
|
564
|
-
if (p.deprecated.length) add("deprecated-schema", u, p.deprecated.join(", "));
|
|
565
|
-
if (p.hasRating) add("rating-review", u);
|
|
566
|
-
const missingQ = p.faqQs.filter(q => !p.normText.includes(norm(q)));
|
|
567
|
-
if (missingQ.length) add("faq-not-visible", u, `${missingQ.length} of ${p.faqQs.length}: “${missingQ[0].slice(0, 60)}”`);
|
|
568
|
-
if (p.links.length > 150) add("too-many-links", u, `${p.links.length} links`);
|
|
569
|
-
const generic = p.links.filter(l => /^(click here|here|read more|learn more|more|this|link|details)$/i.test(l.text.trim())).length;
|
|
570
|
-
if (generic) add("generic-anchor", u, `${generic} link(s)`);
|
|
571
|
-
if (smSet.size && !smSet.has(p.url) && !smSet.has(u)) add("missing-from-sitemap", u);
|
|
572
|
-
for (const b of p.crumbs.slice(0, -1)) { const t = pages.get(clean(toCrawl(b))); if (t && t.status !== 200) add("breadcrumb-dead-level", u, `${b} → ${t.status}`); }
|
|
555
|
+
// Desktop never makes a finding or counts in the score: PERF-01 is about phones, the version Google indexes.
|
|
556
|
+
if (DESKTOP && !OUTSIDE)
|
|
557
|
+
notes.push(
|
|
558
|
+
"--desktop runs only with outside checks on (--outside): it sends the sample URLs to Google PageSpeed Insights again, for desktop. It didn't run.",
|
|
559
|
+
);
|
|
560
|
+
else if (DESKTOP && !SPEED_ON)
|
|
561
|
+
notes.push("--desktop didn't run: speed data needs the public, live site; pass --site-origin.");
|
|
562
|
+
else if (DESKTOP && speedLimited)
|
|
563
|
+
notes.push(
|
|
564
|
+
"--desktop didn't run: PageSpeed refused the phone requests, so the desktop ones weren't sent. Set PSI_API_KEY (a free Google Cloud API key for the PageSpeed Insights API) and re-run.",
|
|
565
|
+
);
|
|
566
|
+
else if (DESKTOP) {
|
|
567
|
+
const d = await checkSpeed(speedUrls, {
|
|
568
|
+
add: () => {},
|
|
569
|
+
endpoint: PSI_AT,
|
|
570
|
+
key: process.env.PSI_API_KEY,
|
|
571
|
+
strategy: "desktop",
|
|
572
|
+
});
|
|
573
|
+
const t = CRUX_KEY
|
|
574
|
+
? await speedTrend(EXPECT_ORIGIN, { key: CRUX_KEY, endpoint: CRUX_AT, formFactor: "DESKTOP" }).catch(e => ({
|
|
575
|
+
note: `CrUX history (desktop) failed (${e.message}).`,
|
|
576
|
+
}))
|
|
577
|
+
: {};
|
|
578
|
+
notes.push(...d.notes, ...(t.note ? [t.note] : []));
|
|
579
|
+
if (d.samples.length || t.trend)
|
|
580
|
+
speed = {
|
|
581
|
+
...(speed || { strategy: "mobile", samples: [] }),
|
|
582
|
+
desktop: {
|
|
583
|
+
strategy: "desktop",
|
|
584
|
+
samples: d.samples,
|
|
585
|
+
...(t.trend ? { trend: t.trend } : {}),
|
|
586
|
+
...(t.lcpBreakdown ? { lcpBreakdown: t.lcpBreakdown } : {}),
|
|
587
|
+
},
|
|
588
|
+
};
|
|
573
589
|
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
590
|
+
|
|
591
|
+
// ---------- outside checks: what JavaScript changes ----------
|
|
592
|
+
const renderSample = sampleUrls(htmlPages.filter(p => indexable(p) && !p.refreshTo).map(p => p.finalUrl)); // a meta refresh would render its target
|
|
593
|
+
// --render all: every page meant to rank (as Lighthouse's all mode takes them), capped, after the time estimate.
|
|
594
|
+
const renderEvery =
|
|
595
|
+
browser && RENDER_ALL
|
|
596
|
+
? renderAll([...new Set(htmlPages.filter(p => indexable(p) && !p.refreshTo).map(p => p.finalUrl))], {
|
|
597
|
+
log: console.log,
|
|
598
|
+
})
|
|
599
|
+
: null;
|
|
600
|
+
const renderList = renderEvery?.urls || renderSample;
|
|
601
|
+
// One Chrome behind the site's guard serves the renders (each in an isolated tab), then the phone and desktop loads.
|
|
602
|
+
// Lighthouse starts its own.
|
|
603
|
+
let sessionError = /** @type {Error | null} */ (null);
|
|
604
|
+
const session =
|
|
605
|
+
browser && (renderList.length || RENDER_PAGE)
|
|
606
|
+
? await openSession(browser, renderList[0] ?? START.href).catch(e => {
|
|
607
|
+
sessionError = e;
|
|
608
|
+
return null;
|
|
609
|
+
})
|
|
610
|
+
: null;
|
|
611
|
+
let renderFailure = null;
|
|
612
|
+
if (browser) {
|
|
613
|
+
let rendered = 0;
|
|
614
|
+
if (sessionError) renderFailure = String(sessionError.message).split("\n")[0].slice(0, 120);
|
|
615
|
+
else
|
|
616
|
+
for (const u of renderList) {
|
|
617
|
+
try {
|
|
618
|
+
const [rawRes, dom] = await Promise.all([get(u, { manual: false }), renderPage(browser, u, {}, session)]);
|
|
619
|
+
if (rawRes.status !== 200 || !rawRes.body) {
|
|
620
|
+
renderFailure ||= `the raw HTML of ${u} couldn't be fetched again`;
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
rendered++;
|
|
624
|
+
renderFindings(u, rawRes.body, dom, { add, clientRendered: !!byPage.get(u)?.clientOnly });
|
|
625
|
+
} catch (e) {
|
|
626
|
+
renderFailure ||= String(e.message).split("\n")[0].slice(0, 120);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (rendered) {
|
|
630
|
+
evalRules("REND-06");
|
|
631
|
+
notes.push(
|
|
632
|
+
`Rendered ${rendered} of ${renderList.length} ${renderEvery ? "" : "sample "}page(s) in headless ${/edge/i.test(browser) ? "Edge" : "Chrome"} and compared them with the raw HTML.${renderFailure ? ` Some failed: ${renderFailure}` : ""}`,
|
|
633
|
+
);
|
|
634
|
+
} else
|
|
635
|
+
notChecked.push({
|
|
636
|
+
rule: "REND-06",
|
|
637
|
+
area: `REND-06 ${RULES["REND-06"][0]}`,
|
|
638
|
+
reason: `The browser at ${browser} couldn't render the sample pages (${renderFailure || "no pages to render"}).`,
|
|
639
|
+
});
|
|
640
|
+
} else
|
|
641
|
+
notChecked.push({
|
|
642
|
+
rule: "REND-06",
|
|
643
|
+
area: `REND-06 ${RULES["REND-06"][0]}`,
|
|
644
|
+
reason: OUTSIDE
|
|
645
|
+
? "Chrome or Edge isn't installed (or set CHROME_PATH), so rendered pages couldn't be compared with the raw HTML."
|
|
646
|
+
: "Outside checks are off. With the owner's go-ahead, --outside renders sample pages in headless Chrome (running the site's own scripts) and compares them with the raw HTML.",
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
// ---------- outside checks: phone and desktop loads, screenshots, lab speed ----------
|
|
650
|
+
let labSpeed,
|
|
651
|
+
visualReason = OUTSIDE
|
|
652
|
+
? "Chrome or Edge isn't installed (or set CHROME_PATH), so pages couldn't be loaded at phone size."
|
|
653
|
+
: "Outside checks are off. With the owner's go-ahead, --outside loads sample pages in headless Chrome at desktop and phone size (running the site's own scripts) and saves screenshots.";
|
|
654
|
+
let bfTested = 0,
|
|
655
|
+
bfReason = OUTSIDE
|
|
656
|
+
? "Chrome or Edge isn't installed (or set CHROME_PATH)"
|
|
657
|
+
: "outside checks are off (with the owner's go-ahead, --outside runs it in headless Chrome)";
|
|
658
|
+
/** @type {{ checked: number, pages: any[], chosen: any, notes: string[] } | null} */
|
|
659
|
+
let more = null; // the render checks (REND-11), read from the same loads; their notes and data go in further down
|
|
660
|
+
if (browser) {
|
|
661
|
+
// --render-page's raw HTML is read first for the comparison.
|
|
662
|
+
let chosen = null;
|
|
663
|
+
if (RENDER_PAGE) {
|
|
664
|
+
const u = urlOr(RENDER_PAGE, START.href);
|
|
665
|
+
if (u && /^https?:$/.test(u.protocol)) {
|
|
666
|
+
const res = await get(u.href, { manual: false }).catch(() => null);
|
|
667
|
+
chosen = { url: u.href, steps: RENDER_STEPS, raw: res?.status === 200 && res.body ? res.body : null };
|
|
668
|
+
} else notes.push(`--render-page needs an http or https address; “${RENDER_PAGE}” isn't one, so it didn't run.`);
|
|
584
669
|
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
670
|
+
const failed = e => {
|
|
671
|
+
const why = String(e.message).split("\n")[0].slice(0, 160);
|
|
672
|
+
return {
|
|
673
|
+
visual: { checked: 0, lab: [], notes: [`the browser didn't start: ${why}`], bfTested: 0 },
|
|
674
|
+
more: { checked: 0, pages: [], chosen: null, notes: [`the browser didn't start for the render checks: ${why}`] },
|
|
675
|
+
};
|
|
676
|
+
};
|
|
677
|
+
const both = sessionError
|
|
678
|
+
? failed(sessionError)
|
|
679
|
+
: await browserChecks(browser, renderSample, {
|
|
680
|
+
add,
|
|
681
|
+
screenshotDir: resolve(dirname(OUT), "screenshots"),
|
|
682
|
+
rawWords: new Map(htmlPages.filter(p => !p.clientOnly).map(p => [p.finalUrl, p.words])),
|
|
683
|
+
clean: CLEAN_SHOTS,
|
|
684
|
+
chosen,
|
|
685
|
+
session,
|
|
686
|
+
}).catch(failed);
|
|
687
|
+
await session?.close();
|
|
688
|
+
const v = both.visual;
|
|
689
|
+
more = both.more;
|
|
690
|
+
if (v.lab.length) labSpeed = v.lab;
|
|
691
|
+
if (v.checked) {
|
|
692
|
+
evalRules("REND-07", "PERF-07");
|
|
693
|
+
visualReason = null;
|
|
694
|
+
notes.push(...v.notes);
|
|
695
|
+
} else
|
|
696
|
+
visualReason = `The browser at ${browser} couldn't load the sample pages (${v.notes[0] || "no pages to load"}).`;
|
|
697
|
+
bfTested = v.bfTested || 0;
|
|
698
|
+
bfReason = !renderSample.length
|
|
699
|
+
? "no page meant to rank could be tested"
|
|
700
|
+
: renderSample.length < 2
|
|
701
|
+
? "only one page could be tested, and Back needs a second page to come back from"
|
|
702
|
+
: !v.checked
|
|
703
|
+
? "the browser couldn't load the sample pages"
|
|
704
|
+
: "it timed out on every page (see the notes)";
|
|
596
705
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
706
|
+
if (visualReason)
|
|
707
|
+
for (const rule of ["REND-07", "PERF-07"])
|
|
708
|
+
notChecked.push({ rule, area: `${rule} ${RULES[rule][0]}`, reason: visualReason });
|
|
709
|
+
// PERF-10 passes only when Chrome's own test ran; without it the HTML hints can still raise a finding, but not pass it.
|
|
710
|
+
if (bfTested) evalRules("PERF-10");
|
|
711
|
+
else if (!findings.has("bfcache-no-store") && !findings.has("bfcache-unload"))
|
|
712
|
+
notChecked.push({
|
|
713
|
+
rule: "PERF-10",
|
|
714
|
+
area: `PERF-10 ${RULES["PERF-10"][0]}`,
|
|
715
|
+
reason: `Chrome's back/forward cache test didn't run: ${bfReason}.${checkedPages ? " The HTML hints (Cache-Control: no-store, inline unload handlers) found nothing." : ""}`,
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
// ---------- outside checks: Lighthouse, an optional add-on (scores only, no findings) ----------
|
|
719
|
+
let lighthouse;
|
|
720
|
+
const lighthouseBin = LIGHTHOUSE && OUTSIDE ? findLighthouse() : null;
|
|
721
|
+
if (LIGHTHOUSE && !OUTSIDE)
|
|
722
|
+
notes.push(
|
|
723
|
+
"--lighthouse runs only with outside checks on (--outside): Lighthouse loads each page and runs its scripts, analytics included. It didn't run.",
|
|
724
|
+
);
|
|
725
|
+
else if (LIGHTHOUSE && !lighthouseBin)
|
|
726
|
+
notes.push(
|
|
727
|
+
"Lighthouse isn't installed, so it didn't run. Add it with `npx seo-supervisor --with-lighthouse` (about 170 MB, outside the project), or `npm i -g lighthouse`.",
|
|
728
|
+
);
|
|
729
|
+
else if (lighthouseBin) {
|
|
730
|
+
// all: every page meant to rank, without the sample's one-per-folder pick; the estimate prints before the runs.
|
|
731
|
+
const every = [...new Set(htmlPages.filter(p => indexable(p) && !p.refreshTo).map(p => p.finalUrl))];
|
|
732
|
+
// --lighthouse 20: that many pages meant to rank, the sample first and then the rest, up to all mode's cap.
|
|
733
|
+
const asked = /^\d+$/.test(args.lighthouse) ? Math.min(Number(args.lighthouse), ALL_CAP) : 0;
|
|
734
|
+
const r = await checkLighthouse(
|
|
735
|
+
lighthouseBin,
|
|
736
|
+
LIGHTHOUSE_ALL ? every : asked ? [...new Set([...renderSample, ...every])] : renderSample,
|
|
737
|
+
{ chromePath: browser, all: LIGHTHOUSE_ALL || asked > 0, ...(asked ? { max: asked } : {}), log: console.log },
|
|
738
|
+
);
|
|
739
|
+
if (r.results.length) lighthouse = r.results;
|
|
740
|
+
notes.push(...r.notes);
|
|
606
741
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
742
|
+
// Which part of LCP takes longest: real visitors' (from the trend above), else a PageSpeed or Lighthouse lab run's.
|
|
743
|
+
const labLcp = speed?.lcpBreakdown
|
|
744
|
+
? null
|
|
745
|
+
: labLcpBreakdown([...(speed?.samples || []).map(s => ({ url: s.url, ...s.lab })), ...(lighthouse || [])]);
|
|
746
|
+
if (labLcp) speed = { ...(speed || { strategy: "mobile", samples: [] }), lcpBreakdown: labLcp };
|
|
747
|
+
|
|
748
|
+
// ---------- site-wide checks and data, in this order (data for the report goes on `extra`) ----------
|
|
749
|
+
|
|
750
|
+
// Unnamed controls, WebMCP tools, agent files and writing notes.
|
|
751
|
+
await agentData(site, UA);
|
|
752
|
+
|
|
753
|
+
// A business type guessed from the home page and the schema, and a finding when the schema is too general.
|
|
754
|
+
extra.businessType = home?.html
|
|
755
|
+
? checkBusinessType(
|
|
756
|
+
htmlPages.map(p => ({
|
|
757
|
+
url: p.finalUrl,
|
|
758
|
+
title: p.title,
|
|
759
|
+
h1: p.headings.find(h => h.level === 1)?.text,
|
|
760
|
+
text: p.bizText,
|
|
761
|
+
types: [...p.types, ...p.schemaOther],
|
|
762
|
+
})),
|
|
763
|
+
add,
|
|
764
|
+
)
|
|
765
|
+
: detectBusinessType([]);
|
|
766
|
+
|
|
767
|
+
pageMarkup(site);
|
|
768
|
+
cookiesAndPolicies(site);
|
|
769
|
+
// Other sites are visited only with --outbound-links, a separate opt-in.
|
|
770
|
+
const OUTBOUND = !!args["outbound-links"];
|
|
771
|
+
const outbound = await outboundLinks(site, OUTBOUND);
|
|
772
|
+
|
|
773
|
+
descStartsWithTitle(site);
|
|
774
|
+
|
|
775
|
+
// hreflang sources that disagree, missing versions, lang against hreflang, untranslated versions, invalid lang values,
|
|
776
|
+
// and the Translate widget as the only translation.
|
|
777
|
+
checkLanguages(
|
|
778
|
+
htmlPages.filter(p => indexable(p) && !p.clientOnly),
|
|
779
|
+
{ add, origin: EXPECT_ORIGIN },
|
|
780
|
+
);
|
|
781
|
+
|
|
782
|
+
imageList(site, { images, imageRows });
|
|
783
|
+
|
|
784
|
+
if (RENDER_ALL && !OUTSIDE)
|
|
785
|
+
notes.push(
|
|
786
|
+
"--render all runs only with outside checks on (--outside): rendering runs each page's own scripts, analytics included. It didn't run.",
|
|
787
|
+
);
|
|
788
|
+
if (renderEvery?.note) notes.push(renderEvery.note);
|
|
789
|
+
|
|
790
|
+
// Kept for seo-diff.mjs. A redirect that never ends (a loop, or more than 10 hops) has no target.
|
|
791
|
+
{
|
|
792
|
+
const body = robots ? robotsRes.body : null,
|
|
793
|
+
met = all.filter(p => p.chain?.length > 1).sort((a, b) => (a.url < b.url ? -1 : 1));
|
|
794
|
+
extra.robotsTxt = {
|
|
795
|
+
status: robotsRes.status,
|
|
796
|
+
hash: body == null ? null : createHash("sha256").update(body).digest("hex"),
|
|
797
|
+
text: body?.slice(0, 50 * 1024) ?? null,
|
|
798
|
+
};
|
|
799
|
+
extra.redirects = met
|
|
800
|
+
.slice(0, 500)
|
|
801
|
+
.map(p => ({ from: p.url, to: p.error === "too many redirects" ? null : p.finalUrl, status: p.chain[0].status }));
|
|
802
|
+
if (met.length > 500)
|
|
803
|
+
notes.push(`The crawl met ${met.length} redirects; the first 500 are kept for the next audit's comparison.`);
|
|
612
804
|
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
if (
|
|
618
|
-
const off = style === "always" ? withoutS : withS;
|
|
619
|
-
if (SLASH !== "auto" || (withS.length && withoutS.length)) for (const p of off) add("trailing-slash-mixed", p.finalUrl, `expected ${style === "always" ? "a trailing slash" : "no trailing slash"}`);
|
|
620
|
-
for (const p of styled.slice(0, 5)) {
|
|
621
|
-
const x = new URL(p.finalUrl); x.pathname = x.pathname.endsWith("/") ? x.pathname.slice(0, -1) : x.pathname + "/";
|
|
622
|
-
const r = await get(x.href);
|
|
623
|
-
if (r.status === 200) add("slash-variant-no-redirect", x.href, `and ${p.finalUrl} both return 200`);
|
|
805
|
+
|
|
806
|
+
securityHeaders(site);
|
|
807
|
+
for (const r of extra.redirects || []) {
|
|
808
|
+
r.from = hideSecrets(r.from);
|
|
809
|
+
if (r.to) r.to = hideSecrets(r.to);
|
|
624
810
|
}
|
|
811
|
+
// The browser's private-address guard can't run behind a proxy.
|
|
812
|
+
if ((browser || lighthouseBin) && chromeProxyArgs().length)
|
|
813
|
+
notes.push(
|
|
814
|
+
"A proxy is set (HTTPS_PROXY or HTTP_PROXY), so headless Chrome and Lighthouse went through it, and the guard that keeps them off private and cloud-metadata addresses didn't run for renders and Lighthouse. The proxy decides what they can reach.",
|
|
815
|
+
);
|
|
625
816
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
817
|
+
versionedNote(robots, notes);
|
|
818
|
+
checkCoverage(site, {
|
|
819
|
+
section: SECTION,
|
|
820
|
+
include: INCLUDE,
|
|
821
|
+
exclude: EXCLUDE,
|
|
822
|
+
crawler: { seen, fetched, capped },
|
|
823
|
+
sm,
|
|
824
|
+
gscIndexing: args["gsc-indexing"],
|
|
825
|
+
});
|
|
826
|
+
// Other sites' hreflang targets are visited only with --outside and --hreflang-other-sites: 20 at most, never a private
|
|
827
|
+
// address. A target must name the page back; a 404 or 410 is a bad target, anything else that isn't a page is a note.
|
|
828
|
+
{
|
|
829
|
+
const others = otherSiteTargets(
|
|
830
|
+
htmlPages.filter(p => indexable(p) && !p.clientOnly),
|
|
831
|
+
EXPECT_ORIGIN,
|
|
832
|
+
),
|
|
833
|
+
yes = !!args["hreflang-other-sites"];
|
|
834
|
+
if (others.size && OUTSIDE && yes) {
|
|
835
|
+
const list = [...others].slice(0, 20),
|
|
836
|
+
away = [];
|
|
837
|
+
for (let i = 0; i < list.length; i += CONC)
|
|
838
|
+
await Promise.all(
|
|
839
|
+
list.slice(i, i + CONC).map(async ([target, from]) => {
|
|
840
|
+
// A page on another site that trips a check is "couldn't check", never the end of the crawl.
|
|
841
|
+
const r = await follow(target),
|
|
842
|
+
there = (() => {
|
|
843
|
+
try {
|
|
844
|
+
return readPage(r, page);
|
|
845
|
+
} catch {
|
|
846
|
+
return null;
|
|
847
|
+
}
|
|
848
|
+
})();
|
|
849
|
+
if (r.status === 404 || r.status === 410)
|
|
850
|
+
for (const f of from) add("hreflang-bad-target", f.url, `${f.lang} → ${target} (status ${r.status})`);
|
|
851
|
+
else if (!there)
|
|
852
|
+
away.push(`${quote(target)} (${r.error || `status ${r.status}`})`); // quoted: the target is site text
|
|
853
|
+
else
|
|
854
|
+
for (const f of from)
|
|
855
|
+
if (!linksBack(there.hreflang, r.finalUrl, f.url, toCrawl))
|
|
856
|
+
add("hreflang-no-return", f.url, `${f.lang} → ${target} doesn't link back`);
|
|
857
|
+
}),
|
|
858
|
+
);
|
|
859
|
+
if (away.length)
|
|
860
|
+
notes.push(
|
|
861
|
+
`${away.length} hreflang target(s) on other sites couldn't be checked for a return link, e.g. ${away[0]}.`,
|
|
862
|
+
);
|
|
863
|
+
if (others.size > 20) notes.push(`hreflang on other sites: the first 20 of ${others.size} targets were checked.`);
|
|
864
|
+
} else if (others.size) {
|
|
865
|
+
if (yes)
|
|
866
|
+
notes.push(
|
|
867
|
+
"--hreflang-other-sites runs only with outside checks on (--outside), since it visits other sites. It didn't run.",
|
|
868
|
+
);
|
|
869
|
+
notChecked.push({
|
|
870
|
+
rule: "META-08",
|
|
871
|
+
area: "META-08 hreflang return links on other sites",
|
|
872
|
+
reason: `${others.size} hreflang target(s) on other sites, e.g. ${others.keys().next().value}, weren't visited to see whether they link back: that contacts other sites, so it needs outside checks on (--outside) and the owner's own yes (--hreflang-other-sites).`,
|
|
873
|
+
});
|
|
874
|
+
}
|
|
635
875
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
876
|
+
|
|
877
|
+
aiBotAccess({ robots, robotsRes, star }, { add, extra, startOrigin: START_ORIGIN });
|
|
878
|
+
bingAiPrefs(site);
|
|
879
|
+
// Comment links, Back traps, paywalls, late head tags, site identity.
|
|
880
|
+
pageSignals(site);
|
|
881
|
+
|
|
882
|
+
aiRobotRules({ robots, robotsRes }, { add, extra, startOrigin: START_ORIGIN });
|
|
883
|
+
|
|
884
|
+
// Also #fragment links.
|
|
885
|
+
linkedOnce(site, { section: SECTION, capped });
|
|
886
|
+
|
|
887
|
+
// Duplicate analytics, secret keys in pages and scripts, hidden links, app files, PDFs.
|
|
888
|
+
await hygieneChecks(site, UA);
|
|
889
|
+
|
|
890
|
+
await markdownCheck(site, { mdHome, renderSample });
|
|
891
|
+
|
|
892
|
+
linkStrength(site, { section: SECTION, capped });
|
|
893
|
+
|
|
894
|
+
// The page-words file for keyword-ideas.mjs.
|
|
895
|
+
pageWords(site, { out: OUT, stamp: t0 });
|
|
896
|
+
|
|
897
|
+
// Click-only elements and missing landmarks.
|
|
898
|
+
landmarks(site);
|
|
899
|
+
// ---------- the bot probes, the last requests to the site: a firewall may ban the address that sent them ----------
|
|
900
|
+
// The home page and up to 9 sample pages as Googlebot, then a few as AI search crawlers with --ai-bot-probe. Every
|
|
901
|
+
// other request to the site, schema images and browser loads included, has already gone.
|
|
902
|
+
const botSample = sampleUrls(htmlPages.map(p => p.url));
|
|
903
|
+
const botCompared = await compareGooglebot(site, { page, botSample });
|
|
904
|
+
await aiBotProbe(site, { page, botSample, aiProbe: AI_PROBE, outside: OUTSIDE });
|
|
905
|
+
// After every request this crawl makes: what the private-address guard stopped, and whether the crawler slowed down.
|
|
906
|
+
if (blocked.size)
|
|
907
|
+
notes.push(
|
|
908
|
+
`The crawler didn't fetch ${blocked.size} address(es) outside the crawled site that are private, local or cloud-metadata addresses: ${[
|
|
909
|
+
...blocked,
|
|
910
|
+
]
|
|
911
|
+
.slice(0, 3)
|
|
912
|
+
.map(([u, why]) => `${quote(u)} (${why})`)
|
|
913
|
+
.join("; ")}. A redirect there is reported as the redirect itself.`,
|
|
914
|
+
);
|
|
915
|
+
const slowed = slowNote(slow);
|
|
916
|
+
if (slowed) notes.push(slowed);
|
|
917
|
+
|
|
918
|
+
// Also schema placeholders and deprecated types.
|
|
919
|
+
await schemaImages(site);
|
|
920
|
+
|
|
921
|
+
shopChecks(site);
|
|
922
|
+
|
|
923
|
+
mediaData(site, { speed, lighthouse, imageInfo });
|
|
924
|
+
// Only once the phone trend came back: a site without it has no tablet or page data either. A 404 is no news.
|
|
925
|
+
if (SPEED_ON && CRUX_KEY && speed?.trend) {
|
|
926
|
+
const [tab, homeT] = /** @type {TrendResult[]} */ ([
|
|
927
|
+
await speedTrend(EXPECT_ORIGIN, { key: CRUX_KEY, endpoint: CRUX_AT, formFactor: "TABLET" }).catch(e => ({
|
|
928
|
+
note: `CrUX history (tablet) failed (${e.message}).`,
|
|
929
|
+
})),
|
|
930
|
+
await speedTrend(EXPECT_ORIGIN + "/", { key: CRUX_KEY, endpoint: CRUX_AT, page: true }).catch(e => ({
|
|
931
|
+
note: `CrUX history for the home page failed (${e.message}).`,
|
|
932
|
+
})),
|
|
933
|
+
]);
|
|
934
|
+
for (const t of [tab, homeT]) if (t.note && !/not enough Chrome visits/.test(t.note)) notes.push(t.note);
|
|
935
|
+
if (tab.trend) speed.tablet = { trend: tab.trend, ...(tab.lcpBreakdown ? { lcpBreakdown: tab.lcpBreakdown } : {}) };
|
|
936
|
+
if (homeT.trend) speed.pageTrend = { url: EXPECT_ORIGIN + "/", trend: homeT.trend };
|
|
639
937
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
938
|
+
|
|
939
|
+
// REND-11 data from the browser loads above, and --render-page's result.
|
|
940
|
+
if (RENDER_PAGE && !OUTSIDE)
|
|
941
|
+
notes.push(
|
|
942
|
+
"--render-page runs only with outside checks on (--outside): rendering runs the page's own scripts, analytics included. It didn't run.",
|
|
943
|
+
);
|
|
944
|
+
let moreReason = OUTSIDE
|
|
945
|
+
? "Chrome or Edge isn't installed (or set CHROME_PATH), so the phone menu and ads couldn't be checked."
|
|
946
|
+
: "Outside checks are off. With the owner's go-ahead, --outside loads sample pages in headless Chrome at phone size (running the site's own scripts) to try the menu button and measure ads.";
|
|
947
|
+
if (more) {
|
|
948
|
+
notes.push(...more.notes);
|
|
949
|
+
if (more.pages.length) extra.renderSample = more.pages;
|
|
950
|
+
if (more.chosen) extra.renderedPage = more.chosen;
|
|
951
|
+
if (more.checked) {
|
|
952
|
+
evalRules("REND-11");
|
|
953
|
+
moreReason = null;
|
|
954
|
+
} else
|
|
955
|
+
moreReason = `The browser at ${browser} couldn't load the sample pages at phone size (${more.notes[0] || "no pages to load"}).`;
|
|
655
956
|
}
|
|
957
|
+
if (moreReason) notChecked.push({ rule: "REND-11", area: `REND-11 ${RULES["REND-11"][0]}`, reason: moreReason });
|
|
958
|
+
|
|
959
|
+
// Descriptions against their pages, templated descriptions, stale guides, keyword use.
|
|
960
|
+
contentChecks(site, { titleWords, brandWords, acronyms });
|
|
961
|
+
|
|
962
|
+
localData(site, localBusiness);
|
|
963
|
+
|
|
964
|
+
otherSites(site, outbound);
|
|
965
|
+
|
|
966
|
+
// E-E-A-T signals for the trust view, never findings or scored; last, so the security findings are in. HTTPS counts
|
|
967
|
+
// with no open TRUST-01 or TRUST-07 finding, and is unknown without a public origin. Locally a missing security header
|
|
968
|
+
// is often one a CDN adds in production, so it doesn't count against HTTPS; a header sent but wrong still does.
|
|
969
|
+
const localHeaders = isLocal(START_ORIGIN) && findings.has("sec-headers");
|
|
970
|
+
extra.trustSignals = trustSignals(htmlPages, {
|
|
971
|
+
origin: EXPECT_ORIGIN,
|
|
972
|
+
localHeaders,
|
|
973
|
+
https: !isPublic(EXPECT_ORIGIN)
|
|
974
|
+
? null
|
|
975
|
+
: EXPECT_ORIGIN.startsWith("https:") &&
|
|
976
|
+
![...findings.keys()].some(
|
|
977
|
+
k => !(localHeaders && k === "sec-headers") && ["TRUST-01", "TRUST-07"].includes(CHECKS[k][0]),
|
|
978
|
+
),
|
|
979
|
+
orgSchema: (home?.html && home.trust.org) || htmlPages.find(p => p.trust.org)?.trust.org || null,
|
|
980
|
+
unsourcedStats: htmlPages.filter(p => p.trust.unsourcedStat).length,
|
|
981
|
+
});
|
|
656
982
|
|
|
657
983
|
// ---------- what the crawler cannot check ----------
|
|
984
|
+
// CRAWL-09 never passes here: a real Googlebot comes from Google's IP addresses, which no request from here can.
|
|
658
985
|
const NOT_CRAWLABLE = [
|
|
659
|
-
["
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
986
|
+
...(["googlebot-blocked", "googlebot-differs", "googlebot-firewall"].some(k => findings.has(k))
|
|
987
|
+
? []
|
|
988
|
+
: [
|
|
989
|
+
[
|
|
990
|
+
"CRAWL-09",
|
|
991
|
+
"Bot protection and firewall",
|
|
992
|
+
botCompared
|
|
993
|
+
? `A Googlebot user agent got the same status, robots tag, canonical, title and text as a visitor on ${botCompared} page(s)${isLocal(START_ORIGIN) ? " of the local build, where no CDN or firewall sits in between; crawl the live site to include them" : ""}. A real Googlebot comes from Google's IP addresses, which a firewall can treat differently; confirm with the live test in Search Console's URL Inspection.`
|
|
994
|
+
: "A local crawl can't see CDN or WAF behaviour toward Googlebot; check the CDN settings and URL Inspection after launch.",
|
|
995
|
+
],
|
|
996
|
+
]),
|
|
997
|
+
[
|
|
998
|
+
"CRAWL-11",
|
|
999
|
+
"Drafts and publish flags",
|
|
1000
|
+
"The crawler can't see publish flags; check the content layer (scripts/content-scan.mjs).",
|
|
1001
|
+
],
|
|
663
1002
|
["SCHEMA-08", "Rich result eligibility", "Run one URL per template through Google's Rich Results Test."],
|
|
664
1003
|
["META-07", "Search Console and Bing verification", "Check DNS or ask the owner."],
|
|
665
1004
|
["LINK-03", "Circular linking design", "Needs a read of the related-content code and data."],
|
|
666
1005
|
["CONTENT-03", "Keyword targeting and cannibalization", "Needs the content plan or Search Console query data."],
|
|
667
|
-
[
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
1006
|
+
[
|
|
1007
|
+
"CONTENT-11",
|
|
1008
|
+
"Spam policies (scaled content, doorways, site reputation, back-button hijacking)",
|
|
1009
|
+
'Needs a read of content strategy and scripts. The crawler covers parts of it: near-duplicate pages, links in comment sections without rel="ugc" or "nofollow", and inline scripts that may trap the Back button; scripts loaded from files aren\'t read.',
|
|
1010
|
+
],
|
|
1011
|
+
[
|
|
1012
|
+
"AI-02",
|
|
1013
|
+
"AI crawler access through the CDN/WAF",
|
|
1014
|
+
"robots.txt is checked; firewall behaviour toward OAI-SearchBot, Claude-SearchBot and PerplexityBot isn't visible locally.",
|
|
1015
|
+
],
|
|
671
1016
|
];
|
|
672
|
-
for (const [rule, area, reason] of NOT_CRAWLABLE)
|
|
673
|
-
|
|
674
|
-
if (
|
|
675
|
-
|
|
1017
|
+
for (const [rule, area, reason] of NOT_CRAWLABLE) skip(rule, reason, `${rule} ${area}`);
|
|
1018
|
+
// MAP-01 is half the robots.txt Sitemap: line, so only a sitemap finding settles it while robots.txt is down.
|
|
1019
|
+
if (robotsDown)
|
|
1020
|
+
for (const rule of ["MAP-01", "MAP-05", "MAP-06"])
|
|
1021
|
+
if (![...findings.keys()].some(k => CHECKS[k][0] === rule))
|
|
1022
|
+
skip(
|
|
1023
|
+
rule,
|
|
1024
|
+
`robots.txt answered ${robotsRes.status ? `status ${robotsRes.status}` : "nothing"}, so its ${rule === "MAP-01" ? "Sitemap: line" : "rules"} couldn't be read. Re-run once it returns 200.`,
|
|
1025
|
+
);
|
|
1026
|
+
// A page missing from the sitemap URLs read may be in the part past SITEMAP_KEEP.
|
|
1027
|
+
if (sm.cut && findings.delete("missing-from-sitemap") && evaluated.delete("MAP-03"))
|
|
1028
|
+
skip(
|
|
1029
|
+
"MAP-03",
|
|
1030
|
+
sm.filesLeft
|
|
1031
|
+
? "Some crawled pages aren't in the first 60 sitemap files, the most this audit reads, so they may still be in the files after them."
|
|
1032
|
+
: `Some crawled pages aren't among the first ${SITEMAP_KEEP.toLocaleString("en-US")} sitemap URLs, the most this audit reads, so they may still be in the rest of the sitemap.`,
|
|
1033
|
+
);
|
|
1034
|
+
if (!redirectSources.length)
|
|
1035
|
+
skip(
|
|
1036
|
+
"URL-07",
|
|
1037
|
+
"No redirect list given. Pass --urls (old site URLs) or --next-manifest .next/routes-manifest.json.",
|
|
1038
|
+
"URL-07 Old-URL redirects",
|
|
1039
|
+
);
|
|
1040
|
+
if (!BANNED && !VERIFY)
|
|
1041
|
+
skip(
|
|
1042
|
+
"CONTENT-10",
|
|
1043
|
+
"Pass --banned and --verify with the profile's claim lists.",
|
|
1044
|
+
"CONTENT-10 Banned and unconfirmed claims",
|
|
1045
|
+
);
|
|
1046
|
+
if (IGNORE_NOINDEX && evaluated.delete("CRAWL-02"))
|
|
1047
|
+
skip(
|
|
1048
|
+
"CRAWL-02",
|
|
1049
|
+
"Pre-launch run: noindex is expected now. Re-check after launch (CRAWL-03).",
|
|
1050
|
+
"CRAWL-02 Pages meant to rank are not noindex",
|
|
1051
|
+
);
|
|
676
1052
|
|
|
677
1053
|
// ---------- output ----------
|
|
678
|
-
const
|
|
679
|
-
const out = [];
|
|
680
|
-
for (const [key, f] of findings) {
|
|
681
|
-
const [rule, severity, title, why, fix] = CHECKS[key];
|
|
682
|
-
const ex = f.evidence[0] || {};
|
|
683
|
-
const what = `${f.count === 1 ? "Found on" : `${f.count} cases, for example`} ${ex.url || "the site"}${ex.detail ? ` (${ex.detail})` : ""}.`;
|
|
684
|
-
out.push({ check: key, rule, severity, category: RULES[rule][1], title: title(f.count), what, why, fix, count: f.count, evidence: f.evidence, source: "crawler", status: severity === "needs-decision" ? "needs-decision" : "open" });
|
|
685
|
-
}
|
|
686
|
-
out.sort((a, b) => SEV[a.severity] - SEV[b.severity] || b.count - a.count);
|
|
687
|
-
out.forEach((f, i) => { f.id = "C-" + String(i + 1).padStart(3, "0"); });
|
|
1054
|
+
const out = list({ source: "crawler", prefix: "C" });
|
|
688
1055
|
const failedRules = new Set(out.map(f => f.rule));
|
|
689
|
-
const passed = [...evaluated]
|
|
690
|
-
|
|
1056
|
+
const passed = [...evaluated]
|
|
1057
|
+
.filter(r => !failedRules.has(r))
|
|
1058
|
+
.sort()
|
|
1059
|
+
.map(r => ({ rule: r, title: RULES[r][0], category: RULES[r][1] }));
|
|
1060
|
+
// Every note and every notChecked reason, whichever check wrote it and whenever, through one scrub.
|
|
1061
|
+
const scrubText = s => redact(maskKeys(String(s)));
|
|
1062
|
+
const noteList = notes.map(scrubText);
|
|
691
1063
|
const report = {
|
|
692
|
-
tool: "seo-supervisor-crawler",
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
1064
|
+
tool: "seo-supervisor-crawler",
|
|
1065
|
+
version: VERSION,
|
|
1066
|
+
crawledAt: new Date().toISOString(),
|
|
1067
|
+
durationMs: Date.now() - t0,
|
|
1068
|
+
startUrl: START.href,
|
|
1069
|
+
siteOrigin: EXPECT_ORIGIN,
|
|
1070
|
+
options: {
|
|
1071
|
+
max: MAX,
|
|
1072
|
+
concurrency: CONC,
|
|
1073
|
+
ignoreNoindex: IGNORE_NOINDEX,
|
|
1074
|
+
banned: BANNED ? String(BANNED) : null,
|
|
1075
|
+
verify: VERIFY ? String(VERIFY) : null,
|
|
1076
|
+
redirectSources: redirectSources.length,
|
|
1077
|
+
trailingSlash: SLASH,
|
|
1078
|
+
detectedSlashStyle: style,
|
|
1079
|
+
includeQuery: INCLUDE_QUERY,
|
|
1080
|
+
brand: BRAND || null,
|
|
1081
|
+
},
|
|
1082
|
+
// capped: stopped at --max. sitemapComplete: every sitemap file answered 200 and none went unread past a limit.
|
|
1083
|
+
// seo-diff.mjs compares internal links and sitemap listing only when they say the crawl and the sitemap were whole.
|
|
1084
|
+
stats: {
|
|
1085
|
+
fetched,
|
|
1086
|
+
capped,
|
|
1087
|
+
htmlPages: htmlPages.length,
|
|
1088
|
+
sitemapUrls: sm.entries.length,
|
|
1089
|
+
sitemapFiles: sm.files,
|
|
1090
|
+
sitemapComplete: !sm.cut && sm.files.every(f => f.status === 200),
|
|
1091
|
+
robotsTxt: robotsRes.status,
|
|
1092
|
+
},
|
|
1093
|
+
notes: noteList,
|
|
1094
|
+
findings: out,
|
|
1095
|
+
passed,
|
|
1096
|
+
notChecked: notChecked.map(n => ({ ...n, reason: scrubText(n.reason) })),
|
|
1097
|
+
...extra,
|
|
1098
|
+
...(speed ? { speed } : {}),
|
|
1099
|
+
...(labSpeed ? { labSpeed } : {}),
|
|
1100
|
+
...(lighthouse ? { lighthouse } : {}),
|
|
1101
|
+
errors: all.filter(p => !p.html && (p.status >= 400 || p.status === 0)).map(p => ({ url: p.url, status: p.status })),
|
|
1102
|
+
pages: htmlPages.map(p => ({
|
|
1103
|
+
url: p.finalUrl,
|
|
1104
|
+
status: p.status,
|
|
1105
|
+
depth: p.depth ?? null,
|
|
1106
|
+
inSitemap: smSet.has(p.url),
|
|
1107
|
+
noindex: p.noindex,
|
|
1108
|
+
canonical: canonicalFor(p),
|
|
1109
|
+
title: p.title,
|
|
1110
|
+
description: p.description,
|
|
1111
|
+
ogTitle: p.ogTitle,
|
|
1112
|
+
ogImage: p.ogImage,
|
|
1113
|
+
h1Text: p.headings.find(h => h.level === 1)?.text ?? null,
|
|
1114
|
+
words: p.words,
|
|
1115
|
+
h1: p.h1Count,
|
|
1116
|
+
schema: p.types,
|
|
1117
|
+
schemaOther: p.schemaOther,
|
|
1118
|
+
schemaProps: p.schemaProps,
|
|
1119
|
+
linksOut: p.links.length,
|
|
1120
|
+
linksIn: inbound.get(p.finalUrl) || 0,
|
|
1121
|
+
h2s: p.headings
|
|
1122
|
+
.filter(h => h.level === 2)
|
|
1123
|
+
.map(h => h.text)
|
|
1124
|
+
.slice(0, 50),
|
|
1125
|
+
h3s: p.headings
|
|
1126
|
+
.filter(h => h.level === 3)
|
|
1127
|
+
.map(h => h.text)
|
|
1128
|
+
.slice(0, 50),
|
|
1129
|
+
ogDescription: p.ogDescription,
|
|
1130
|
+
ogUrl: p.ogUrl,
|
|
1131
|
+
hreflang: (p.hreflang || []).map(h => ({ lang: h.lang, href: h.href })),
|
|
1132
|
+
})),
|
|
697
1133
|
};
|
|
698
1134
|
mkdirSync(dirname(OUT), { recursive: true });
|
|
1135
|
+
// File the previous seo-crawl.json in history/ before replacing it, so "Since last audit" still has it. Other --out
|
|
1136
|
+
// names (a branch crawl, say) stay out of the history.
|
|
1137
|
+
if (basename(OUT) === "seo-crawl.json" && existsSync(OUT))
|
|
1138
|
+
try {
|
|
1139
|
+
fileCrawl(join(dirname(OUT), "history"), OUT, JSON.parse(readFileSync(OUT, "utf8")));
|
|
1140
|
+
} catch (e) {
|
|
1141
|
+
console.log(`note: the previous ${OUT} couldn't be filed in history/ (${e.message})`);
|
|
1142
|
+
}
|
|
699
1143
|
writeFileSync(OUT, JSON.stringify(report, null, 2));
|
|
700
|
-
const counts = out.reduce((m, f) => (m[f.severity] = (m[f.severity] || 0) + 1, m), {});
|
|
701
|
-
console.log(
|
|
702
|
-
|
|
1144
|
+
const counts = out.reduce((m, f) => ((m[f.severity] = (m[f.severity] || 0) + 1), m), {});
|
|
1145
|
+
console.log(
|
|
1146
|
+
`seo-crawl: ${htmlPages.length} HTML pages (${fetched} fetched), ${sm.entries.length} sitemap URLs, ${out.length} findings ` +
|
|
1147
|
+
JSON.stringify(counts) +
|
|
1148
|
+
`, ${passed.length} rules passed`,
|
|
1149
|
+
);
|
|
1150
|
+
for (const n of noteList) console.log("note: " + n);
|
|
703
1151
|
console.log("wrote " + OUT);
|