seo-supervisor 0.0.0-stage → 1.2.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/marketplace.json +16 -0
- package/.claude-plugin/plugin.json +14 -0
- package/CHANGELOG.md +31 -0
- package/LICENSE +25 -0
- package/README.md +197 -2
- package/bin/agents.mjs +65 -0
- package/bin/prompt.mjs +76 -0
- package/bin/seo-supervisor.mjs +144 -0
- package/commands/seo-audit.md +7 -0
- package/commands/seo-fix.md +13 -0
- package/commands/seo-launch.md +7 -0
- package/commands/seo-review.md +7 -0
- package/commands/seo-setup.md +19 -0
- package/package.json +45 -4
- package/skills/seo-supervisor/SKILL.md +199 -0
- package/skills/seo-supervisor/examples/sample-audit.json +440 -0
- package/skills/seo-supervisor/examples/sample-report.html +654 -0
- package/skills/seo-supervisor/examples/sample-report.md +257 -0
- package/skills/seo-supervisor/examples/security-tools-profile.md +73 -0
- package/skills/seo-supervisor/examples/snippets.md +134 -0
- package/skills/seo-supervisor/frameworks/nextjs.md +98 -0
- package/skills/seo-supervisor/frameworks/rails.md +34 -0
- package/skills/seo-supervisor/frameworks/spa.md +14 -0
- package/skills/seo-supervisor/planning.md +145 -0
- package/skills/seo-supervisor/profile-template.md +55 -0
- package/skills/seo-supervisor/report-format.md +146 -0
- package/skills/seo-supervisor/rules/ai-search.md +40 -0
- package/skills/seo-supervisor/rules/content.md +60 -0
- package/skills/seo-supervisor/rules/crawl-index.md +65 -0
- package/skills/seo-supervisor/rules/internal-linking.md +61 -0
- package/skills/seo-supervisor/rules/launch-monitoring.md +48 -0
- package/skills/seo-supervisor/rules/media.md +30 -0
- package/skills/seo-supervisor/rules/metadata.md +39 -0
- package/skills/seo-supervisor/rules/performance.md +33 -0
- package/skills/seo-supervisor/rules/rendering.md +42 -0
- package/skills/seo-supervisor/rules/sitemaps-robots.md +37 -0
- package/skills/seo-supervisor/rules/structured-data.md +75 -0
- package/skills/seo-supervisor/rules/trust-security.md +25 -0
- package/skills/seo-supervisor/rules/urls.md +46 -0
- package/skills/seo-supervisor/scripts/content-scan.mjs +173 -0
- package/skills/seo-supervisor/scripts/fonts/OFL-BricolageGrotesque.txt +93 -0
- package/skills/seo-supervisor/scripts/fonts/OFL-Geist.txt +93 -0
- package/skills/seo-supervisor/scripts/fonts/OFL-GeistMono.txt +93 -0
- package/skills/seo-supervisor/scripts/fonts/bricolage-grotesque.woff2 +0 -0
- package/skills/seo-supervisor/scripts/fonts/geist-mono.woff2 +0 -0
- package/skills/seo-supervisor/scripts/fonts/geist.woff2 +0 -0
- package/skills/seo-supervisor/scripts/render-report.mjs +706 -0
- package/skills/seo-supervisor/scripts/report-plan.mjs +162 -0
- package/skills/seo-supervisor/scripts/seo-crawl.mjs +703 -0
- package/skills/seo-supervisor/site-types/content.md +22 -0
- package/skills/seo-supervisor/site-types/ecommerce.md +27 -0
- package/skills/seo-supervisor/site-types/local-business.md +28 -0
- package/skills/seo-supervisor/site-types/services.md +22 -0
- package/skills/seo-supervisor/site-types/tools.md +127 -0
|
@@ -0,0 +1,703 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// seo-crawl.mjs: zero-dependency SEO crawler for the seo-supervisor skill. Needs Node 20+.
|
|
3
|
+
//
|
|
4
|
+
// node seo-crawl.mjs --url http://localhost:3000
|
|
5
|
+
// [--site-origin https://www.example.com] public origin canonicals/sitemaps should use
|
|
6
|
+
// [--trailing-slash auto|always|never] expected URL style (default auto = detect + flag mixing)
|
|
7
|
+
// [--brand "Brand"] flags titles that repeat the brand
|
|
8
|
+
// [--ignore-noindex] pre-launch: check noindex pages as if they were indexable
|
|
9
|
+
// [--banned "regex"] flag visible text matching this (banned claims, wrong names)
|
|
10
|
+
// [--verify "regex"] flag claims the owner hasn't confirmed yet (needs-decision)
|
|
11
|
+
// [--urls old-urls.txt] test old URLs / redirect sources (one per line, CSV first column, or JSON array)
|
|
12
|
+
// [--next-manifest .next/routes-manifest.json] test every fixed-path redirect source of a Next.js build
|
|
13
|
+
// [--max 1000] [--concurrency 4] [--include-query]
|
|
14
|
+
// [--out seo-audit/seo-crawl.json]
|
|
15
|
+
//
|
|
16
|
+
// Read-only: it only sends GET requests. Point it at a local dev/preview server or staging
|
|
17
|
+
// whenever possible; against production keep --concurrency low.
|
|
18
|
+
// ponytail: regex HTML parsing, good enough for audit evidence; swap in a real parser if a site breaks it.
|
|
19
|
+
|
|
20
|
+
import { mkdirSync, writeFileSync, readFileSync } from "node:fs";
|
|
21
|
+
import { dirname, resolve } from "node:path";
|
|
22
|
+
|
|
23
|
+
const VERSION = "1.0.0";
|
|
24
|
+
const UA = "seo-supervisor-crawler/" + VERSION;
|
|
25
|
+
|
|
26
|
+
// ---------- args ----------
|
|
27
|
+
const args = {};
|
|
28
|
+
for (let i = 2; i < process.argv.length; i++) {
|
|
29
|
+
const a = process.argv[i];
|
|
30
|
+
if (!a.startsWith("--")) continue;
|
|
31
|
+
const k = a.slice(2);
|
|
32
|
+
const v = process.argv[i + 1] && !process.argv[i + 1].startsWith("--") ? process.argv[++i] : true;
|
|
33
|
+
args[k] = v;
|
|
34
|
+
}
|
|
35
|
+
if (!args.url || args.url === true) {
|
|
36
|
+
console.error("Usage: node seo-crawl.mjs --url http://localhost:3000 [--site-origin https://example.com] [--trailing-slash auto|always|never] [--brand Name] [--ignore-noindex] [--banned regex] [--verify regex] [--urls file] [--next-manifest file] [--max 1000] [--concurrency 4] [--include-query] [--out seo-audit/seo-crawl.json]");
|
|
37
|
+
process.exit(2);
|
|
38
|
+
}
|
|
39
|
+
const START = new URL(args.url);
|
|
40
|
+
const START_ORIGIN = START.origin;
|
|
41
|
+
const MAX = Number(args.max || 1000);
|
|
42
|
+
const IGNORE_NOINDEX = !!args["ignore-noindex"];
|
|
43
|
+
const BANNED = typeof args.banned === "string" ? new RegExp(args.banned, "i") : null;
|
|
44
|
+
const VERIFY = typeof args.verify === "string" ? new RegExp(args.verify, "i") : null;
|
|
45
|
+
const URL_LIST = typeof args.urls === "string" ? args.urls : null;
|
|
46
|
+
const NEXT_MANIFEST = typeof args["next-manifest"] === "string" ? args["next-manifest"] : null;
|
|
47
|
+
const CONC = Math.max(1, Number(args.concurrency || 4));
|
|
48
|
+
const SLASH = ["always", "never"].includes(args["trailing-slash"]) ? args["trailing-slash"] : "auto";
|
|
49
|
+
const BRAND = typeof args.brand === "string" ? args.brand : "";
|
|
50
|
+
const INCLUDE_QUERY = !!args["include-query"];
|
|
51
|
+
const OUT = resolve(typeof args.out === "string" ? args.out : "seo-audit/seo-crawl.json");
|
|
52
|
+
let SITE_ORIGIN = typeof args["site-origin"] === "string" ? new URL(args["site-origin"]).origin : "";
|
|
53
|
+
const notes = [];
|
|
54
|
+
|
|
55
|
+
// ---------- rule + check catalog ----------
|
|
56
|
+
const RULES = {
|
|
57
|
+
"CRAWL-01": ["robots.txt lets search engines crawl the site", "Crawling & indexing"],
|
|
58
|
+
"CRAWL-02": ["Pages meant to rank are not set to noindex", "Crawling & indexing"],
|
|
59
|
+
"CRAWL-05": ["Correct HTTP status codes, no soft 404s", "Crawling & indexing"],
|
|
60
|
+
"CRAWL-06": ["Sitemap URLs return 200", "Crawling & indexing"],
|
|
61
|
+
"CRAWL-07": ["No internal links to broken pages", "Crawling & indexing"],
|
|
62
|
+
"CRAWL-08": ["Redirects take one hop and internal links skip them", "Crawling & indexing"],
|
|
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; };
|
|
364
|
+
|
|
365
|
+
// ---------- crawl ----------
|
|
366
|
+
const pages = new Map(); // requested crawl URL -> record
|
|
367
|
+
const queue = []; const seen = new Set();
|
|
368
|
+
let fetched = 0, capped = false;
|
|
369
|
+
function enqueue(u, from) {
|
|
370
|
+
const c = clean(u, from); if (!c) return;
|
|
371
|
+
const x = new URL(c);
|
|
372
|
+
if (x.origin !== START_ORIGIN) return;
|
|
373
|
+
if (FILE_EXT.test(x.pathname)) return;
|
|
374
|
+
if (x.search && !INCLUDE_QUERY) return;
|
|
375
|
+
if (seen.has(c)) return; seen.add(c); queue.push(c);
|
|
376
|
+
}
|
|
377
|
+
async function crawlOne(u) {
|
|
378
|
+
const r = await follow(u);
|
|
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
|
+
}
|
|
411
|
+
|
|
412
|
+
// ---------- main ----------
|
|
413
|
+
const t0 = Date.now();
|
|
414
|
+
// robots.txt
|
|
415
|
+
const robotsRes = await get(START_ORIGIN + "/robots.txt", { manual: false });
|
|
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
|
|
428
|
+
const smUrls = robots && robots.sitemaps.length ? robots.sitemaps : [START_ORIGIN + "/sitemap.xml"];
|
|
429
|
+
const firstSm = smUrls[0];
|
|
430
|
+
if (!SITE_ORIGIN) { try { const o = new URL(firstSm).origin; if (o !== START_ORIGIN) SITE_ORIGIN = o; } catch {} }
|
|
431
|
+
let sm = await readSitemaps(smUrls);
|
|
432
|
+
if (!sm.entries.length && !(robots && robots.sitemaps.length)) { const alt = await readSitemaps([START_ORIGIN + "/sitemap_index.xml"]); if (alt.entries.length) sm = alt; }
|
|
433
|
+
if (!SITE_ORIGIN && sm.entries.length) { try { const o = new URL(sm.entries[0].loc).origin; if (o !== START_ORIGIN && !isLocal(o)) SITE_ORIGIN = o; } catch {} }
|
|
434
|
+
if (!sm.entries.length) add("sitemap-missing", smUrls.join(", "), sm.files.map(f => `${f.url} → ${f.status}`).join("; ") || undefined);
|
|
435
|
+
// home first to infer origin from its canonical
|
|
436
|
+
enqueue(START.href);
|
|
437
|
+
await runQueue();
|
|
438
|
+
const home = pages.get(START.href);
|
|
439
|
+
if (!SITE_ORIGIN && home && home.canonicals && home.canonicals[0]) { try { const o = new URL(home.canonicals[0], home.finalUrl).origin; if (o !== START_ORIGIN && !isLocal(o)) SITE_ORIGIN = o; } catch {} }
|
|
440
|
+
const EXPECT_ORIGIN = SITE_ORIGIN || START_ORIGIN;
|
|
441
|
+
if (SITE_ORIGIN && SITE_ORIGIN !== START_ORIGIN) notes.push(`Public origin ${SITE_ORIGIN} was mapped onto ${START_ORIGIN} for crawling.`);
|
|
442
|
+
// sitemap entries
|
|
443
|
+
const smSet = new Map(); // crawl URL -> entry
|
|
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.");
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// ---------- per-page checks ----------
|
|
476
|
+
evalRules("AI-01", "REND-08", "CONTENT-04", "REND-04", "CONTENT-09", "CRAWL-02", "CRAWL-06", "CRAWL-07", "CRAWL-08", "URL-01", "URL-04", "URL-05", "REND-01", "META-01", "META-02", "META-04", "META-05", "CONTENT-01", "CONTENT-02", "CONTENT-05", "CONTENT-08", "SCHEMA-01", "SCHEMA-02", "SCHEMA-03", "SCHEMA-04", "SCHEMA-05", "SCHEMA-07", "MAP-03", "LINK-01", "LINK-02", "LINK-05", "LINK-06", "PERF-03", "PERF-04", "PERF-06");
|
|
477
|
+
if (BRAND) evalRules("META-03");
|
|
478
|
+
if (BANNED || VERIFY) evalRules("CONTENT-10");
|
|
479
|
+
const all = [...pages.values()];
|
|
480
|
+
const byFinal = new Map(); for (const p of all) if (p.finalUrl) byFinal.set(p.finalUrl, p);
|
|
481
|
+
const htmlPages = all.filter(p => p.html);
|
|
482
|
+
const finalOf = u => pages.get(u)?.finalUrl || u;
|
|
483
|
+
const isHome = p => new URL(p.finalUrl).pathname === "/";
|
|
484
|
+
|
|
485
|
+
for (const p of all) {
|
|
486
|
+
if (p.status >= 500 || p.status === 0) add("server-error", p.url, p.error || `status ${p.status}`);
|
|
487
|
+
if (p.chain && p.chain.length > 2) add("redirect-chain", p.url, p.chain.map(c => `${c.status}`).join(" → ") + ` → ${p.finalUrl}`);
|
|
488
|
+
const x = new URL(p.url);
|
|
489
|
+
if (/[A-Z]/.test(x.pathname) || /_/.test(x.pathname) || /%20| /.test(x.pathname) || /\/\//.test(x.pathname)) add("url-format", p.url);
|
|
490
|
+
}
|
|
491
|
+
for (const [u, e] of smSet) {
|
|
492
|
+
const p = pages.get(u); if (!p) continue;
|
|
493
|
+
if (p.status !== 200 || p.chain.length > 1) add("sitemap-bad-status", e.loc, p.chain.length > 1 ? `redirects to ${p.finalUrl}` : `status ${p.status}`);
|
|
494
|
+
else if (p.html && p.noindex && !IGNORE_NOINDEX) add("noindex-in-sitemap", e.loc);
|
|
495
|
+
if (robots && star && !allowedBy(star, new URL(u).pathname)) add("sitemap-url-disallowed", e.loc);
|
|
496
|
+
}
|
|
497
|
+
// titles / descriptions duplicates
|
|
498
|
+
const titleMap = new Map(), descMap = new Map(), faqMap = new Map();
|
|
499
|
+
let checkedPages = 0;
|
|
500
|
+
const notChecked = [];
|
|
501
|
+
const noindexShare = htmlPages.length ? htmlPages.filter(p => p.noindex).length / htmlPages.length : 0;
|
|
502
|
+
if (IGNORE_NOINDEX) notes.push("Ran with --ignore-noindex: noindex pages were checked as if indexable (pre-launch audit). Noindex findings were not raised.");
|
|
503
|
+
else if (noindexShare > 0.5) notes.push(`${Math.round(noindexShare * 100)}% of pages are noindex. If the site is pre-launch, re-run with --ignore-noindex; per-page checks skipped those pages.`);
|
|
504
|
+
const canonicalFor = p => { const c = p.canonicals && p.canonicals[0]; return c ? new URL(c, p.finalUrl).href : null; };
|
|
505
|
+
const samePath = (a, b) => new URL(a).pathname === new URL(b).pathname;
|
|
506
|
+
const indexable = p => p.html && (IGNORE_NOINDEX || !p.noindex) && (() => { const c = canonicalFor(p); return !c || samePath(toCrawl(c), p.finalUrl); })();
|
|
507
|
+
for (const p of htmlPages) {
|
|
508
|
+
const u = p.finalUrl;
|
|
509
|
+
if (!IGNORE_NOINDEX) {
|
|
510
|
+
if (isHome(p) && p.noindex) add("home-noindex", u);
|
|
511
|
+
else if (p.noindex && !smSet.has(p.url)) add("noindex-review", u);
|
|
512
|
+
}
|
|
513
|
+
if (p.banned) add("banned-claim", u, `“${p.banned.match}” in: ${p.banned.snippet}`);
|
|
514
|
+
if (p.unconfirmed) add("unconfirmed-claim", u, `“${p.unconfirmed.match}” in: ${p.unconfirmed.snippet}`);
|
|
515
|
+
if (p.words < 30 && p.h1Count === 0 && (p.emptyRoot || p.scripts > 0)) { add("client-rendered", u, `${p.words} words in server HTML`); p.clientOnly = true; continue; }
|
|
516
|
+
if (p.noindex && !IGNORE_NOINDEX) continue;
|
|
517
|
+
// canonical
|
|
518
|
+
if (!p.canonicals.length) add("canonical-missing", u);
|
|
519
|
+
else {
|
|
520
|
+
if (p.canonicals.length > 1) add("canonical-multiple", u, p.canonicals.join(" | "));
|
|
521
|
+
const c = new URL(p.canonicals[0], u);
|
|
522
|
+
if (c.search) add("canonical-query", u, c.href);
|
|
523
|
+
if (c.origin !== EXPECT_ORIGIN) add("canonical-origin", u, c.href);
|
|
524
|
+
if (!samePath(toCrawl(c.href), u)) add("canonical-not-self", u, `→ ${c.href}`);
|
|
525
|
+
const t = pages.get(clean(toCrawl(c.href)));
|
|
526
|
+
if (t && (t.status !== 200 || (t.chain && t.chain.length > 1))) add("canonical-bad-target", u, `${c.href} → ${t.chain && t.chain.length > 1 ? "redirect" : t.status}`);
|
|
527
|
+
}
|
|
528
|
+
if (!indexable(p)) continue;
|
|
529
|
+
checkedPages++;
|
|
530
|
+
for (const q of p.faqQs) { const k = norm(q); if (k) (faqMap.get(k) || faqMap.set(k, { q, pages: [] }).get(k)).pages.push(u); }
|
|
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}`); }
|
|
573
|
+
}
|
|
574
|
+
// near-duplicate main content (5-word shingles, Dice similarity)
|
|
575
|
+
{
|
|
576
|
+
const cand = htmlPages.filter(p => p.shingles && !p.clientOnly && indexable(p)).slice(0, 400);
|
|
577
|
+
for (let i = 0; i < cand.length; i++) for (let j = i + 1; j < cand.length; j++) {
|
|
578
|
+
const a = cand[i].shingles, b = cand[j].shingles;
|
|
579
|
+
const [small, big] = a.size < b.size ? [a, b] : [b, a];
|
|
580
|
+
if (small.size / big.size < 0.4) continue;
|
|
581
|
+
let inter = 0; for (const x of small) if (big.has(x)) inter++;
|
|
582
|
+
const dice = (2 * inter) / (a.size + b.size);
|
|
583
|
+
if (dice > 0.6) add("near-duplicate", cand[i].finalUrl, `${Math.round(dice * 100)}% shared with ${cand[j].finalUrl}`);
|
|
584
|
+
}
|
|
585
|
+
if (htmlPages.filter(p => p.shingles).length > 400) notes.push("Near-duplicate check compared the first 400 indexable pages only.");
|
|
586
|
+
}
|
|
587
|
+
for (const { q, pages: ps } of faqMap.values()) if (ps.length > 1) add("faq-reused", ps[0], `“${q.slice(0, 70)}” on ${ps.length} pages`);
|
|
588
|
+
const PER_PAGE_RULES = ["AI-01", "REND-08", "URL-04", "META-01", "META-02", "META-04", "CONTENT-01", "CONTENT-02", "CONTENT-04", "CONTENT-05", "CONTENT-08", "CONTENT-09", "REND-04", "SCHEMA-01", "SCHEMA-03", "SCHEMA-04", "SCHEMA-05", "SCHEMA-07", "MAP-03", "LINK-05", "LINK-06", "PERF-03", "PERF-04", "PERF-06"];
|
|
589
|
+
if (checkedPages === 0) for (const r of PER_PAGE_RULES) if (evaluated.delete(r)) notChecked.push({ rule: r, area: `${r} ${RULES[r][0]}`, reason: "No indexable pages were checked (all noindex, non-canonical or failed). For a pre-launch site, re-run with --ignore-noindex." });
|
|
590
|
+
for (const [t, us] of titleMap) if (us.length > 1) for (const u of us) add("title-dup", u, t);
|
|
591
|
+
for (const [d, us] of descMap) if (us.length > 1) for (const u of us) add("desc-dup", u, d.slice(0, 80));
|
|
592
|
+
if (home && home.html) {
|
|
593
|
+
if (!home.lang) add("lang-missing", home.finalUrl);
|
|
594
|
+
if (!home.types.some(t => ORG_RE.test(t))) add("org-missing", home.finalUrl);
|
|
595
|
+
if (!home.types.includes("WebSite")) add("website-missing", home.finalUrl);
|
|
596
|
+
}
|
|
597
|
+
// links: broken / to redirects / inbound / depth
|
|
598
|
+
const inbound = new Map(), bodyInbound = new Map(), brokenSeen = new Set(), redirSeen = new Set();
|
|
599
|
+
for (const p of htmlPages) for (const l of (p.mainLinks || [])) { const fin = finalOf(l); if (fin !== p.finalUrl) bodyInbound.set(fin, (bodyInbound.get(fin) || 0) + 1); }
|
|
600
|
+
for (const p of htmlPages) for (const l of p.links) {
|
|
601
|
+
const t = pages.get(l.url); const fin = finalOf(l.url);
|
|
602
|
+
if (fin !== p.finalUrl) inbound.set(fin, (inbound.get(fin) || 0) + 1);
|
|
603
|
+
if (!t) continue;
|
|
604
|
+
if ((t.status >= 400 || t.status === 0) && !brokenSeen.has(l.url)) { brokenSeen.add(l.url); add("broken-internal-link", l.url, `status ${t.status}, linked from ${p.finalUrl}`); }
|
|
605
|
+
else if (t.chain && t.chain.length > 1 && !redirSeen.has(l.url)) { redirSeen.add(l.url); add("link-to-redirect", l.url, `→ ${t.finalUrl} (linked from ${p.finalUrl})`); }
|
|
606
|
+
}
|
|
607
|
+
for (const [u, e] of smSet) { const p = pages.get(u); if (!p || !p.html || isHome(p)) continue; if (!bodyInbound.get(p.finalUrl)) add("orphan", e.loc, inbound.get(p.finalUrl) ? `only nav/footer links (${inbound.get(p.finalUrl)})` : "no links at all"); }
|
|
608
|
+
if (home && home.html) {
|
|
609
|
+
const depth = new Map([[home.finalUrl, 0]]); const q = [home.finalUrl];
|
|
610
|
+
while (q.length) { const cur = q.shift(); const p = byFinal.get(cur); if (!p || !p.links) continue; for (const l of p.links) { const f = finalOf(l.url); if (!depth.has(f)) { depth.set(f, depth.get(cur) + 1); q.push(f); } } }
|
|
611
|
+
for (const p of htmlPages) { const d = depth.get(p.finalUrl); if (d > 3 && indexable(p)) add("deep-page", p.finalUrl, `${d} clicks`); if (d === undefined) p.depth = null; else p.depth = d; }
|
|
612
|
+
}
|
|
613
|
+
// trailing slash style
|
|
614
|
+
const styled = htmlPages.filter(p => p.status === 200 && !isHome(p) && !FILE_EXT.test(new URL(p.finalUrl).pathname));
|
|
615
|
+
const withS = styled.filter(p => new URL(p.finalUrl).pathname.endsWith("/")), withoutS = styled.filter(p => !new URL(p.finalUrl).pathname.endsWith("/"));
|
|
616
|
+
let style = SLASH;
|
|
617
|
+
if (SLASH === "auto") style = withS.length >= withoutS.length ? "always" : "never";
|
|
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`);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// ---------- old URLs / redirect sources ----------
|
|
627
|
+
const redirectSources = [];
|
|
628
|
+
if (URL_LIST) {
|
|
629
|
+
try {
|
|
630
|
+
const raw = readFileSync(URL_LIST, "utf8");
|
|
631
|
+
let items; try { const j = JSON.parse(raw); items = Array.isArray(j) ? j.map(x => typeof x === "string" ? x : x.source || x.url || x.from) : Object.keys(j); }
|
|
632
|
+
catch { items = raw.split(/\r?\n/).map(l => l.split(",")[0].trim().replace(/^"|"$/g, "")).filter(l => l && !l.startsWith("#") && !/^(url|source|from)$/i.test(l)); }
|
|
633
|
+
redirectSources.push(...items.filter(Boolean));
|
|
634
|
+
} catch (e) { notes.push("Could not read --urls: " + e.message); }
|
|
635
|
+
}
|
|
636
|
+
if (NEXT_MANIFEST) {
|
|
637
|
+
try { const m = JSON.parse(readFileSync(NEXT_MANIFEST, "utf8")); for (const r of m.redirects || []) if (!r.internal && r.source && !/[:(*]/.test(r.source)) redirectSources.push(r.source); }
|
|
638
|
+
catch (e) { notes.push("Could not read --next-manifest: " + e.message); }
|
|
639
|
+
}
|
|
640
|
+
if (redirectSources.length) {
|
|
641
|
+
evalRules("URL-07");
|
|
642
|
+
const seenR = new Set(), list = [];
|
|
643
|
+
for (const src of redirectSources) {
|
|
644
|
+
let x; try { x = new URL(src, START_ORIGIN); } catch { continue; }
|
|
645
|
+
const p0 = x.pathname, alt = p0 === "/" ? p0 : (p0.endsWith("/") ? p0.slice(0, -1) : p0 + "/");
|
|
646
|
+
for (const path of [p0, alt]) { const full = START_ORIGIN + path + x.search; if (!seenR.has(full)) { seenR.add(full); list.push(full); } }
|
|
647
|
+
}
|
|
648
|
+
for (const u of list.slice(0, 2000)) {
|
|
649
|
+
const r = await follow(u);
|
|
650
|
+
const trail = r.chain.map(c => c.status).join(" → ") + ` → ${r.finalUrl}`;
|
|
651
|
+
if (r.status >= 400 || r.status === 0) add("redirect-broken", u, trail + (r.error ? ` (${r.error})` : ""));
|
|
652
|
+
else if (r.chain.length > 2) add("redirect-chain", u, trail);
|
|
653
|
+
}
|
|
654
|
+
notes.push(`Tested ${Math.min(list.length, 2000)} old/redirect URLs, each with and without a trailing slash.`);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// ---------- what the crawler cannot check ----------
|
|
658
|
+
const NOT_CRAWLABLE = [
|
|
659
|
+
["PERF-01", "Core Web Vitals", "Needs field data (Search Console, CrUX) or a Lighthouse run."],
|
|
660
|
+
["CRAWL-09", "Bot protection and firewall", "A local crawl can't see CDN or WAF behaviour toward Googlebot; check the CDN settings and URL Inspection after launch."],
|
|
661
|
+
["CRAWL-11", "Drafts and publish flags", "The crawler can't see publish flags; check the content layer (scripts/content-scan.mjs)."],
|
|
662
|
+
["URL-03", "http→https and www redirects", "Probe production's http:// and other-host variants, or check server/CDN config."],
|
|
663
|
+
["SCHEMA-08", "Rich result eligibility", "Run one URL per template through Google's Rich Results Test."],
|
|
664
|
+
["META-07", "Search Console and Bing verification", "Check DNS or ask the owner."],
|
|
665
|
+
["LINK-03", "Circular linking design", "Needs a read of the related-content code and data."],
|
|
666
|
+
["CONTENT-03", "Keyword targeting and cannibalization", "Needs the content plan or Search Console query data."],
|
|
667
|
+
["CONTENT-11", "Spam policies (scaled content, doorways, site reputation, back-button hijacking)", "Needs a read of content strategy and scripts; the near-duplicate check covers part of it."],
|
|
668
|
+
["REND-07", "Mobile/desktop parity", "Compare a mobile and desktop render of key templates."],
|
|
669
|
+
["PERF-07", "Popups and interstitials", "Needs a browser look at first load on mobile."],
|
|
670
|
+
["AI-02", "AI crawler access through the CDN/WAF", "robots.txt is checked; firewall behaviour toward OAI-SearchBot, Claude-SearchBot and PerplexityBot isn't visible locally."],
|
|
671
|
+
];
|
|
672
|
+
for (const [rule, area, reason] of NOT_CRAWLABLE) notChecked.push({ rule, area: `${rule} ${area}`, reason });
|
|
673
|
+
if (!redirectSources.length) notChecked.push({ rule: "URL-07", area: "URL-07 Old-URL redirects", reason: "No redirect list given. Pass --urls (old site URLs) or --next-manifest .next/routes-manifest.json." });
|
|
674
|
+
if (!BANNED && !VERIFY) notChecked.push({ rule: "CONTENT-10", area: "CONTENT-10 Banned and unconfirmed claims", reason: "Pass --banned and --verify with the profile's claim lists." });
|
|
675
|
+
if (IGNORE_NOINDEX && evaluated.delete("CRAWL-02")) notChecked.push({ rule: "CRAWL-02", area: "CRAWL-02 Pages meant to rank are not noindex", reason: "Pre-launch run: noindex is expected now. Re-check after launch (CRAWL-03)." });
|
|
676
|
+
|
|
677
|
+
// ---------- output ----------
|
|
678
|
+
const SEV = { blocker: 0, high: 1, "needs-decision": 2, medium: 3, low: 4 };
|
|
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"); });
|
|
688
|
+
const failedRules = new Set(out.map(f => f.rule));
|
|
689
|
+
const passed = [...evaluated].filter(r => !failedRules.has(r)).sort().map(r => ({ rule: r, title: RULES[r][0], category: RULES[r][1] }));
|
|
690
|
+
if (capped) notes.push(`Crawl stopped at ${MAX} pages (--max). Some pages were not checked; raise --max.`);
|
|
691
|
+
const report = {
|
|
692
|
+
tool: "seo-supervisor-crawler", version: VERSION, crawledAt: new Date().toISOString(), durationMs: Date.now() - t0,
|
|
693
|
+
startUrl: START.href, siteOrigin: EXPECT_ORIGIN, options: { max: MAX, concurrency: CONC, ignoreNoindex: IGNORE_NOINDEX, banned: BANNED ? String(BANNED) : null, verify: VERIFY ? String(VERIFY) : null, redirectSources: redirectSources.length, trailingSlash: SLASH, detectedSlashStyle: style, includeQuery: INCLUDE_QUERY, brand: BRAND || null },
|
|
694
|
+
stats: { fetched, htmlPages: htmlPages.length, sitemapUrls: sm.entries.length, sitemapFiles: sm.files, robotsTxt: robotsRes.status },
|
|
695
|
+
notes, findings: out, passed, notChecked,
|
|
696
|
+
pages: htmlPages.map(p => ({ url: p.finalUrl, status: p.status, depth: p.depth ?? null, inSitemap: smSet.has(p.url), noindex: p.noindex, canonical: canonicalFor(p), title: p.title, description: p.description, h1Text: p.headings.find(h => h.level === 1)?.text ?? null, words: p.words, h1: p.h1Count, schema: p.types, linksOut: p.links.length, linksIn: inbound.get(p.finalUrl) || 0 })),
|
|
697
|
+
};
|
|
698
|
+
mkdirSync(dirname(OUT), { recursive: true });
|
|
699
|
+
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(`seo-crawl: ${htmlPages.length} HTML pages (${fetched} fetched), ${sm.entries.length} sitemap URLs, ${out.length} findings ` + JSON.stringify(counts) + `, ${passed.length} rules passed`);
|
|
702
|
+
for (const n of notes) console.log("note: " + n);
|
|
703
|
+
console.log("wrote " + OUT);
|