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.
Files changed (207) hide show
  1. package/.claude-plugin/icon.png +0 -0
  2. package/.claude-plugin/marketplace.json +2 -2
  3. package/.claude-plugin/plugin.json +16 -3
  4. package/CHANGELOG.md +430 -0
  5. package/NOTICE +7 -0
  6. package/README.md +230 -25
  7. package/agents/seo-auditor.md +16 -0
  8. package/agents/seo-reviewer.md +16 -0
  9. package/bin/agents.mjs +194 -29
  10. package/bin/extras.mjs +422 -0
  11. package/bin/prompt.mjs +34 -14
  12. package/bin/seo-supervisor.mjs +386 -53
  13. package/commands/seo-audit.md +29 -3
  14. package/commands/seo-brief.md +28 -0
  15. package/commands/seo-connect.md +27 -0
  16. package/commands/seo-fix.md +24 -3
  17. package/commands/seo-grow.md +26 -0
  18. package/commands/seo-launch.md +17 -3
  19. package/commands/seo-review.md +13 -1
  20. package/commands/seo-rewrite.md +25 -0
  21. package/commands/seo-setup.md +17 -1
  22. package/commands/seo-watch.md +28 -0
  23. package/hooks/hooks.json +117 -0
  24. package/package.json +20 -7
  25. package/skills/seo-supervisor/NOTICE +7 -0
  26. package/skills/seo-supervisor/SKILL.md +302 -21
  27. package/skills/seo-supervisor/audience.md +61 -0
  28. package/skills/seo-supervisor/examples/drafts/security.md +41 -0
  29. package/skills/seo-supervisor/examples/hooks/README.md +28 -0
  30. package/skills/seo-supervisor/examples/hooks/claude-code-settings.json +15 -0
  31. package/skills/seo-supervisor/examples/hooks/codex-hooks.json +17 -0
  32. package/skills/seo-supervisor/examples/hooks/copilot-hooks.json +15 -0
  33. package/skills/seo-supervisor/examples/hooks/cursor-hooks.json +11 -0
  34. package/skills/seo-supervisor/examples/hooks/github-actions.yml +21 -0
  35. package/skills/seo-supervisor/examples/hooks/pre-commit +17 -0
  36. package/skills/seo-supervisor/examples/hooks/reading-ease.yml +24 -0
  37. package/skills/seo-supervisor/examples/sample-audit.json +94 -2
  38. package/skills/seo-supervisor/examples/sample-report.html +111 -61
  39. package/skills/seo-supervisor/examples/sample-report.md +147 -44
  40. package/skills/seo-supervisor/examples/scheduled-runs.md +89 -0
  41. package/skills/seo-supervisor/examples/snippets.md +648 -1
  42. package/skills/seo-supervisor/grow.md +342 -0
  43. package/skills/seo-supervisor/og-images.md +85 -0
  44. package/skills/seo-supervisor/page-types.md +124 -0
  45. package/skills/seo-supervisor/planning.md +19 -7
  46. package/skills/seo-supervisor/profile-template.md +41 -0
  47. package/skills/seo-supervisor/report-format.md +177 -10
  48. package/skills/seo-supervisor/rewrite.md +59 -0
  49. package/skills/seo-supervisor/rules/ai-search.md +65 -12
  50. package/skills/seo-supervisor/rules/content.md +33 -9
  51. package/skills/seo-supervisor/rules/crawl-index.md +33 -6
  52. package/skills/seo-supervisor/rules/internal-linking.md +49 -6
  53. package/skills/seo-supervisor/rules/launch-monitoring.md +17 -8
  54. package/skills/seo-supervisor/rules/media.md +13 -1
  55. package/skills/seo-supervisor/rules/metadata.md +41 -9
  56. package/skills/seo-supervisor/rules/performance.md +50 -5
  57. package/skills/seo-supervisor/rules/rendering.md +39 -2
  58. package/skills/seo-supervisor/rules/search-intent.md +32 -0
  59. package/skills/seo-supervisor/rules/sitemaps-robots.md +24 -12
  60. package/skills/seo-supervisor/rules/structured-data.md +37 -14
  61. package/skills/seo-supervisor/rules/trust-security.md +25 -2
  62. package/skills/seo-supervisor/rules/urls.md +10 -2
  63. package/skills/seo-supervisor/scripts/ai-answers.mjs +314 -0
  64. package/skills/seo-supervisor/scripts/backlinks.mjs +412 -0
  65. package/skills/seo-supervisor/scripts/change-check.mjs +281 -0
  66. package/skills/seo-supervisor/scripts/checks/agents.mjs +488 -0
  67. package/skills/seo-supervisor/scripts/checks/assets.mjs +404 -0
  68. package/skills/seo-supervisor/scripts/checks/bots.mjs +146 -0
  69. package/skills/seo-supervisor/scripts/checks/business-type.mjs +193 -0
  70. package/skills/seo-supervisor/scripts/checks/content.mjs +391 -0
  71. package/skills/seo-supervisor/scripts/checks/coverage.mjs +184 -0
  72. package/skills/seo-supervisor/scripts/checks/crawl.mjs +95 -0
  73. package/skills/seo-supervisor/scripts/checks/hreflang.mjs +396 -0
  74. package/skills/seo-supervisor/scripts/checks/hygiene.mjs +227 -0
  75. package/skills/seo-supervisor/scripts/checks/lighthouse.mjs +271 -0
  76. package/skills/seo-supervisor/scripts/checks/link-strength.mjs +59 -0
  77. package/skills/seo-supervisor/scripts/checks/links.mjs +360 -0
  78. package/skills/seo-supervisor/scripts/checks/local.mjs +101 -0
  79. package/skills/seo-supervisor/scripts/checks/media.mjs +194 -0
  80. package/skills/seo-supervisor/scripts/checks/outbound.mjs +53 -0
  81. package/skills/seo-supervisor/scripts/checks/page.mjs +223 -0
  82. package/skills/seo-supervisor/scripts/checks/probes.mjs +130 -0
  83. package/skills/seo-supervisor/scripts/checks/render.mjs +552 -0
  84. package/skills/seo-supervisor/scripts/checks/robots.mjs +144 -0
  85. package/skills/seo-supervisor/scripts/checks/schema.mjs +206 -0
  86. package/skills/seo-supervisor/scripts/checks/site-agents.mjs +79 -0
  87. package/skills/seo-supervisor/scripts/checks/site-content.mjs +135 -0
  88. package/skills/seo-supervisor/scripts/checks/site-hygiene.mjs +202 -0
  89. package/skills/seo-supervisor/scripts/checks/site-pages.mjs +474 -0
  90. package/skills/seo-supervisor/scripts/checks/site-security.mjs +102 -0
  91. package/skills/seo-supervisor/scripts/checks/sitemap.mjs +473 -0
  92. package/skills/seo-supervisor/scripts/checks/speed.mjs +267 -0
  93. package/skills/seo-supervisor/scripts/checks/technical.mjs +368 -0
  94. package/skills/seo-supervisor/scripts/checks/tls.mjs +297 -0
  95. package/skills/seo-supervisor/scripts/checks/trust.mjs +421 -0
  96. package/skills/seo-supervisor/scripts/checks/visual.mjs +1132 -0
  97. package/skills/seo-supervisor/scripts/checks/writing.mjs +192 -0
  98. package/skills/seo-supervisor/scripts/commoncrawl.mjs +452 -0
  99. package/skills/seo-supervisor/scripts/connect-keys.mjs +422 -0
  100. package/skills/seo-supervisor/scripts/content-scan.mjs +515 -158
  101. package/skills/seo-supervisor/scripts/crawl/catalog.mjs +1248 -0
  102. package/skills/seo-supervisor/scripts/crawl/fetch.mjs +362 -0
  103. package/skills/seo-supervisor/scripts/crawl/page.mjs +741 -0
  104. package/skills/seo-supervisor/scripts/crawl/queue.mjs +190 -0
  105. package/skills/seo-supervisor/scripts/dashboard.mjs +140 -0
  106. package/skills/seo-supervisor/scripts/data/ai-bots.json +38 -0
  107. package/skills/seo-supervisor/scripts/data/build-schema-vocab.mjs +57 -0
  108. package/skills/seo-supervisor/scripts/data/business-types.json +338 -0
  109. package/skills/seo-supervisor/scripts/data/google-rich-results.json +79 -0
  110. package/skills/seo-supervisor/scripts/data/schema-vocab.json +1 -0
  111. package/skills/seo-supervisor/scripts/deploy-check.mjs +462 -0
  112. package/skills/seo-supervisor/scripts/disavow.mjs +176 -0
  113. package/skills/seo-supervisor/scripts/doctor.mjs +174 -0
  114. package/skills/seo-supervisor/scripts/geo-grid.mjs +371 -0
  115. package/skills/seo-supervisor/scripts/google/search-console.mjs +151 -0
  116. package/skills/seo-supervisor/scripts/google/session.mjs +167 -0
  117. package/skills/seo-supervisor/scripts/google-updates.mjs +189 -0
  118. package/skills/seo-supervisor/scripts/google.mjs +1341 -0
  119. package/skills/seo-supervisor/scripts/gsc-import.mjs +298 -0
  120. package/skills/seo-supervisor/scripts/guard/adapters/claude-code.mjs +149 -0
  121. package/skills/seo-supervisor/scripts/guard/adapters/cline.mjs +28 -0
  122. package/skills/seo-supervisor/scripts/guard/adapters/codex.mjs +26 -0
  123. package/skills/seo-supervisor/scripts/guard/adapters/copilot.mjs +36 -0
  124. package/skills/seo-supervisor/scripts/guard/adapters/cursor.mjs +33 -0
  125. package/skills/seo-supervisor/scripts/guard/adapters/devin.mjs +25 -0
  126. package/skills/seo-supervisor/scripts/guard/adapters/edits.mjs +124 -0
  127. package/skills/seo-supervisor/scripts/guard/mode.mjs +37 -0
  128. package/skills/seo-supervisor/scripts/guard/rules.mjs +931 -0
  129. package/skills/seo-supervisor/scripts/guard.mjs +74 -0
  130. package/skills/seo-supervisor/scripts/images.mjs +408 -0
  131. package/skills/seo-supervisor/scripts/indexnow.mjs +300 -0
  132. package/skills/seo-supervisor/scripts/issues.mjs +217 -0
  133. package/skills/seo-supervisor/scripts/keys/authority.mjs +135 -0
  134. package/skills/seo-supervisor/scripts/keys/bing.mjs +239 -0
  135. package/skills/seo-supervisor/scripts/keys/clarity.mjs +137 -0
  136. package/skills/seo-supervisor/scripts/keys/dataforseo.mjs +57 -0
  137. package/skills/seo-supervisor/scripts/keys/googleplaces.mjs +26 -0
  138. package/skills/seo-supervisor/scripts/keys/http.mjs +212 -0
  139. package/skills/seo-supervisor/scripts/keys/matomo.mjs +138 -0
  140. package/skills/seo-supervisor/scripts/keys/openai.mjs +26 -0
  141. package/skills/seo-supervisor/scripts/keys/perplexity.mjs +26 -0
  142. package/skills/seo-supervisor/scripts/keys/posthog.mjs +165 -0
  143. package/skills/seo-supervisor/scripts/keys/semrush.mjs +25 -0
  144. package/skills/seo-supervisor/scripts/keys/services.mjs +41 -0
  145. package/skills/seo-supervisor/scripts/keys/store.mjs +140 -0
  146. package/skills/seo-supervisor/scripts/keys/visits.mjs +58 -0
  147. package/skills/seo-supervisor/scripts/keys/youtube.mjs +84 -0
  148. package/skills/seo-supervisor/scripts/keyword-data.mjs +316 -0
  149. package/skills/seo-supervisor/scripts/keyword-ideas.mjs +503 -0
  150. package/skills/seo-supervisor/scripts/lib/args.mjs +56 -0
  151. package/skills/seo-supervisor/scripts/lib/business.mjs +27 -0
  152. package/skills/seo-supervisor/scripts/lib/cdp.mjs +242 -0
  153. package/skills/seo-supervisor/scripts/lib/cli.mjs +56 -0
  154. package/skills/seo-supervisor/scripts/lib/csv.mjs +38 -0
  155. package/skills/seo-supervisor/scripts/lib/findings.mjs +100 -0
  156. package/skills/seo-supervisor/scripts/lib/google-client.mjs +9 -0
  157. package/skills/seo-supervisor/scripts/lib/html.mjs +146 -0
  158. package/skills/seo-supervisor/scripts/lib/http.mjs +28 -0
  159. package/skills/seo-supervisor/scripts/lib/image-size.mjs +78 -0
  160. package/skills/seo-supervisor/scripts/lib/is-main.mjs +13 -0
  161. package/skills/seo-supervisor/scripts/lib/net.mjs +116 -0
  162. package/skills/seo-supervisor/scripts/lib/proxy.mjs +47 -0
  163. package/skills/seo-supervisor/scripts/lib/recheck.mjs +106 -0
  164. package/skills/seo-supervisor/scripts/lib/redact.mjs +78 -0
  165. package/skills/seo-supervisor/scripts/lib/robots.mjs +73 -0
  166. package/skills/seo-supervisor/scripts/lib/score.mjs +266 -0
  167. package/skills/seo-supervisor/scripts/lib/settings-dir.mjs +81 -0
  168. package/skills/seo-supervisor/scripts/links-import.mjs +603 -0
  169. package/skills/seo-supervisor/scripts/log-scan.mjs +597 -0
  170. package/skills/seo-supervisor/scripts/og-card.mjs +273 -0
  171. package/skills/seo-supervisor/scripts/osm.mjs +359 -0
  172. package/skills/seo-supervisor/scripts/rdap.mjs +164 -0
  173. package/skills/seo-supervisor/scripts/render-report.mjs +324 -690
  174. package/skills/seo-supervisor/scripts/report/client.js +37 -0
  175. package/skills/seo-supervisor/scripts/report/diff.mjs +264 -0
  176. package/skills/seo-supervisor/scripts/report/findings.mjs +165 -0
  177. package/skills/seo-supervisor/scripts/report/format.mjs +111 -0
  178. package/skills/seo-supervisor/scripts/report/markdown.mjs +250 -0
  179. package/skills/seo-supervisor/scripts/report/model.mjs +171 -0
  180. package/skills/seo-supervisor/scripts/report/overview-lines.mjs +158 -0
  181. package/skills/seo-supervisor/scripts/report/overview.mjs +224 -0
  182. package/skills/seo-supervisor/scripts/report/page.mjs +127 -0
  183. package/skills/seo-supervisor/scripts/report/panel.mjs +172 -0
  184. package/skills/seo-supervisor/scripts/report/panels/ai.mjs +211 -0
  185. package/skills/seo-supervisor/scripts/report/panels/connections.mjs +139 -0
  186. package/skills/seo-supervisor/scripts/report/panels/content.mjs +204 -0
  187. package/skills/seo-supervisor/scripts/report/panels/data-search.mjs +379 -0
  188. package/skills/seo-supervisor/scripts/report/panels/data-site.mjs +44 -0
  189. package/skills/seo-supervisor/scripts/report/panels/links.mjs +380 -0
  190. package/skills/seo-supervisor/scripts/report/panels/local.mjs +221 -0
  191. package/skills/seo-supervisor/scripts/report/panels/site.mjs +359 -0
  192. package/skills/seo-supervisor/scripts/report/panels/speed-media.mjs +267 -0
  193. package/skills/seo-supervisor/scripts/report/sources.mjs +163 -0
  194. package/skills/seo-supervisor/scripts/report/styles.css +223 -0
  195. package/skills/seo-supervisor/scripts/report/traffic.mjs +264 -0
  196. package/skills/seo-supervisor/scripts/report-plan.mjs +112 -33
  197. package/skills/seo-supervisor/scripts/schema-check.mjs +717 -0
  198. package/skills/seo-supervisor/scripts/seo-crawl.mjs +1086 -638
  199. package/skills/seo-supervisor/scripts/seo-diff.mjs +584 -0
  200. package/skills/seo-supervisor/scripts/update-check.mjs +82 -0
  201. package/skills/seo-supervisor/site-types/content.md +34 -1
  202. package/skills/seo-supervisor/site-types/ecommerce.md +38 -1
  203. package/skills/seo-supervisor/site-types/local-business.md +96 -6
  204. package/skills/seo-supervisor/site-types/services.md +46 -0
  205. package/skills/seo-supervisor/site-types/tools.md +3 -3
  206. package/skills/seo-supervisor/strategy.md +232 -0
  207. package/skills/seo-supervisor/troubleshooting.md +56 -0
@@ -0,0 +1,360 @@
1
+ // @ts-check
2
+ // The crawler's link checks and link data. site is the crawl's context (seo-crawl.mjs).
3
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
+ import { basename, dirname } from "node:path";
5
+ import { TEMPORARY, isLocal, slashOnly, urlOr } from "../crawl/fetch.mjs";
6
+ import { pool } from "../crawl/queue.mjs";
7
+ import { FILE_EXT } from "../lib/html.mjs";
8
+ import { checkOutbound } from "./outbound.mjs";
9
+ import { hasName } from "./crawl.mjs";
10
+ import { pageRank, scale as strengthScale } from "./link-strength.mjs";
11
+ import { quote } from "../lib/findings.mjs";
12
+
13
+ // An HTML sitemap page, by its path, H1 or title. It's a page of links reached from the footer, so the menu-only and
14
+ // too-many-links checks leave it alone.
15
+ const SITEMAP = /^site ?map$/i;
16
+ export const isHtmlSitemap = p =>
17
+ /^\/sitemap\/?$/i.test(urlOr(p.finalUrl)?.pathname || "") ||
18
+ SITEMAP.test((p.headings || []).find(h => h.level === 1)?.text?.trim() || "") ||
19
+ SITEMAP.test((p.title || "").split(/\s[|–—·-]\s/)[0].trim());
20
+
21
+ // Returns inbound (final URL -> links to it, the pages list's linksIn) and sets each page's depth. A bad link's
22
+ // evidence, here and for other sites below, is the page holding it, the one to fix; the detail names the target. Each
23
+ // target is reported once, from the first page found linking to it.
24
+ export function checkLinks(site) {
25
+ const { pages, htmlPages, byFinal, home, smSet, add, finalOf, isHome, indexable } = site;
26
+ const inbound = new Map(),
27
+ bodyInbound = new Map(),
28
+ brokenSeen = new Set(),
29
+ redirSeen = new Set();
30
+ for (const p of htmlPages)
31
+ for (const l of p.mainLinks || []) {
32
+ const fin = finalOf(l);
33
+ if (fin !== p.finalUrl) bodyInbound.set(fin, (bodyInbound.get(fin) || 0) + 1);
34
+ }
35
+ for (const p of htmlPages)
36
+ for (const l of p.links) {
37
+ const t = pages.get(l.url);
38
+ const fin = finalOf(l.url);
39
+ if (fin !== p.finalUrl) inbound.set(fin, (inbound.get(fin) || 0) + 1);
40
+ if (!t) continue;
41
+ if ((t.status >= 400 || t.status === 0) && !brokenSeen.has(l.url)) {
42
+ brokenSeen.add(l.url);
43
+ add("broken-internal-link", p.finalUrl, `links to ${l.url}: status ${t.status}`);
44
+ } else if (t.chain && t.chain.length > 1 && !redirSeen.has(l.url)) {
45
+ redirSeen.add(l.url);
46
+ add("link-to-redirect", p.finalUrl, `links to ${l.url}, which redirects to ${t.finalUrl}`);
47
+ }
48
+ }
49
+ for (const [u, e] of smSet) {
50
+ const p = pages.get(u);
51
+ if (!p || !p.html || isHome(p)) continue;
52
+ if (bodyInbound.get(p.finalUrl)) continue;
53
+ const n = inbound.get(p.finalUrl);
54
+ if (n && isHtmlSitemap(p)) continue;
55
+ if (n) add("nav-only-links", e.loc, `only menu, footer or sidebar links (${n})`);
56
+ else add("orphan", e.loc, "no links at all");
57
+ }
58
+ if (home && home.html) {
59
+ const depth = new Map([[home.finalUrl, 0]]);
60
+ const q = [home.finalUrl];
61
+ while (q.length) {
62
+ const cur = q.shift();
63
+ const p = byFinal.get(cur);
64
+ if (!p || !p.links) continue;
65
+ for (const l of p.links) {
66
+ const f = finalOf(l.url);
67
+ if (!depth.has(f)) {
68
+ depth.set(f, depth.get(cur) + 1);
69
+ q.push(f);
70
+ }
71
+ }
72
+ }
73
+ for (const p of htmlPages) {
74
+ const d = depth.get(p.finalUrl);
75
+ if (d > 3 && indexable(p)) add("deep-page", p.finalUrl, `${d} clicks`);
76
+ if (d === undefined) p.depth = null;
77
+ else p.depth = d;
78
+ }
79
+ }
80
+ return { inbound };
81
+ }
82
+
83
+ // SLASH is --trailing-slash (auto, always or never). Returns the style found or set.
84
+ export async function slashStyle(site, SLASH) {
85
+ const { htmlPages, add, notes, startOrigin: START_ORIGIN, get, isHome } = site;
86
+ const styled = htmlPages.filter(p => p.status === 200 && !isHome(p) && !FILE_EXT.test(new URL(p.finalUrl).pathname));
87
+ const withS = styled.filter(p => new URL(p.finalUrl).pathname.endsWith("/")),
88
+ withoutS = styled.filter(p => !new URL(p.finalUrl).pathname.endsWith("/"));
89
+ let style = SLASH;
90
+ if (SLASH === "auto") style = withS.length >= withoutS.length ? "always" : "never";
91
+ const off = style === "always" ? withoutS : withS;
92
+ if (SLASH !== "auto" || (withS.length && withoutS.length))
93
+ for (const p of off)
94
+ add(
95
+ "trailing-slash-mixed",
96
+ p.finalUrl,
97
+ `expected ${style === "always" ? "a trailing slash" : "no trailing slash"}`,
98
+ );
99
+ const slashTemp = [];
100
+ for (const p of styled.slice(0, 5)) {
101
+ const x = new URL(p.finalUrl);
102
+ x.pathname = x.pathname.endsWith("/") ? x.pathname.slice(0, -1) : x.pathname + "/";
103
+ const r = await get(x.href);
104
+ if (r.status === 200) add("slash-variant-no-redirect", x.href, `and ${p.finalUrl} both return 200`);
105
+ else if (TEMPORARY.has(r.status) && urlOr(r.location || "", x.href)?.pathname === new URL(p.finalUrl).pathname)
106
+ slashTemp.push([x.href, `${r.status} → ${p.finalUrl}`]);
107
+ }
108
+ // Dev servers often add the slash with a 302 (http-server does) where production doesn't, so locally it's a note.
109
+ if (slashTemp.length && isLocal(START_ORIGIN))
110
+ notes.push(
111
+ `The local server adds or drops the trailing slash with a temporary redirect (${slashTemp[0][0]}: ${slashTemp[0][1]}). Development servers often do; check that production uses a 301 or 308.`,
112
+ );
113
+ else for (const [u, detail] of slashTemp) add("slash-redirect-temporary", u, detail);
114
+ return style;
115
+ }
116
+
117
+ // Old URLs and redirect sources (URL-07), from --urls and --next-manifest, each tried with and without a trailing
118
+ // slash; their records join site.all. Returns the sources read.
119
+ export async function oldUrls(site, { urlList: URL_LIST, nextManifest: NEXT_MANIFEST }) {
120
+ const { pages, all, add, evalRules, notes, startOrigin: START_ORIGIN, conc: CONC, follow } = site;
121
+ const redirectSources = [];
122
+ if (URL_LIST) {
123
+ try {
124
+ const raw = readFileSync(URL_LIST, "utf8");
125
+ let items;
126
+ try {
127
+ const j = JSON.parse(raw);
128
+ items = Array.isArray(j)
129
+ ? j.map(x => (typeof x === "string" ? x : x.source || x.url || x.from))
130
+ : Object.keys(j);
131
+ } catch {
132
+ items = raw
133
+ .split(/\r?\n/)
134
+ .map(l => l.split(",")[0].trim().replace(/^"|"$/g, ""))
135
+ .filter(l => l && !l.startsWith("#") && !/^(url|source|from)$/i.test(l));
136
+ }
137
+ redirectSources.push(...items.filter(Boolean));
138
+ } catch (e) {
139
+ notes.push("Could not read --urls: " + e.message);
140
+ }
141
+ }
142
+ if (NEXT_MANIFEST) {
143
+ try {
144
+ const m = JSON.parse(readFileSync(NEXT_MANIFEST, "utf8"));
145
+ for (const r of m.redirects || [])
146
+ if (!r.internal && r.source && !/[:(*]/.test(r.source)) redirectSources.push(r.source);
147
+ } catch (e) {
148
+ notes.push("Could not read --next-manifest: " + e.message);
149
+ }
150
+ }
151
+ if (redirectSources.length) {
152
+ evalRules("URL-07");
153
+ const seenR = new Set(),
154
+ list = [];
155
+ for (const src of redirectSources) {
156
+ let x;
157
+ try {
158
+ x = new URL(src, START_ORIGIN);
159
+ } catch {
160
+ continue;
161
+ }
162
+ const p0 = x.pathname,
163
+ alt = p0 === "/" ? p0 : p0.endsWith("/") ? p0.slice(0, -1) : p0 + "/";
164
+ for (const path of [p0, alt]) {
165
+ const full = START_ORIGIN + path + x.search;
166
+ if (!seenR.has(full)) {
167
+ seenR.add(full);
168
+ list.push(full);
169
+ }
170
+ }
171
+ }
172
+ const answers = await pool(list.slice(0, 2000), CONC, u => follow(u)); // the crawl's pool, read back in order
173
+ for (const [i, u] of list.slice(0, 2000).entries()) {
174
+ const r = answers[i];
175
+ // Kept with the crawl's records so the report lists it; links-import.mjs and seo-diff.mjs read it from there.
176
+ if (!pages.has(u))
177
+ all.push({ url: u, status: r.status, finalUrl: r.finalUrl, chain: r.chain, error: r.error || null });
178
+ const trail = r.chain.map(c => c.status).join(" → ") + ` → ${r.finalUrl}`;
179
+ if (r.status >= 400 || r.status === 0) add("redirect-broken", u, trail + (r.error ? ` (${r.error})` : ""));
180
+ else {
181
+ if (r.chain.length > 2) add("redirect-chain", u, trail);
182
+ if (r.chain.some((c, i) => TEMPORARY.has(c.status) && !slashOnly(c.url, r.chain[i + 1]?.url ?? r.finalUrl)))
183
+ add("old-url-temporary", u, trail);
184
+ }
185
+ }
186
+ notes.push(`Tested ${Math.min(list.length, 2000)} old/redirect URLs, each with and without a trailing slash.`);
187
+ // Google may treat many old URLs redirected to one page as soft 404s. Counted per old path, both slash forms as
188
+ // one; 3 to the home page or 10 to another (local thresholds), since merging a few pages into one is fine.
189
+ // https://developers.google.com/search/docs/crawling-indexing/site-move-with-url-changes
190
+ const rec = new Map(all.map(p => [p.url, p])),
191
+ landed = new Map(); // final URL -> old paths
192
+ for (const u of list.slice(0, 2000)) {
193
+ const r = pages.get(u) || rec.get(u);
194
+ if (r?.status !== 200 || !(r.chain?.length > 1) || slashOnly(u, r.finalUrl)) continue;
195
+ (landed.get(r.finalUrl) || landed.set(r.finalUrl, new Set()).get(r.finalUrl)).add(
196
+ new URL(u).pathname.replace(/(.)\/$/, "$1"),
197
+ );
198
+ }
199
+ for (const [to, from] of landed)
200
+ if (from.size >= (new URL(to).pathname === "/" ? 3 : 10))
201
+ add(
202
+ "old-urls-same-target",
203
+ to,
204
+ `${from.size} old URLs redirect here, e.g. ${[...from].slice(0, 3).join(", ")}`,
205
+ );
206
+ }
207
+ return redirectSources;
208
+ }
209
+
210
+ // Each page's distinct http(s) links to other sites, hash dropped, cached for outboundLinks and otherSites.
211
+ const awayOf = new WeakMap();
212
+ function linksAway(p, { selfHosts, bareHost }) {
213
+ let away = awayOf.get(p);
214
+ if (!away) {
215
+ awayOf.set(p, (away = new Set()));
216
+ for (const a of p.anchors) {
217
+ const x = a.href && urlOr(a.href.trim(), p.base);
218
+ if (!x || !/^https?:$/.test(x.protocol) || selfHosts.has(bareHost(x.host))) continue;
219
+ x.hash = "";
220
+ away.add(x.href);
221
+ }
222
+ }
223
+ return away;
224
+ }
225
+
226
+ // Other sites are visited only with --outbound-links (OUTBOUND), since that contacts them.
227
+ export async function outboundLinks(site, OUTBOUND) {
228
+ const { htmlPages, add, notes, notChecked, extra } = site;
229
+ const outbound = new Map(); // another site's URL -> the first page linking to it
230
+ for (const p of htmlPages)
231
+ for (const href of linksAway(p, site)) if (!outbound.has(href)) outbound.set(href, p.finalUrl);
232
+ if (OUTBOUND) {
233
+ const r = await checkOutbound([...outbound.keys()], { limit: 100 });
234
+ for (const b of r.broken) add("outbound-broken", outbound.get(b.url), `links to ${b.url}: status ${b.status}`);
235
+ extra.outboundLinks = { checked: Math.min(outbound.size, 100), ...r };
236
+ if (r.unreachable.length)
237
+ notes.push(
238
+ `${r.unreachable.length} link(s) to other sites couldn't be checked (the site turned the visit away, didn't answer, or isn't a public address), e.g. ${quote(r.unreachable[0].url)}: ${r.unreachable[0].reason}. They aren't counted as broken; outboundLinks in seo-crawl.json lists them.`,
239
+ );
240
+ if (outbound.size > 100) notes.push(`Links to other sites: the first 100 of ${outbound.size} were checked.`);
241
+ } else if (outbound.size)
242
+ notChecked.push({
243
+ rule: "CRAWL-07",
244
+ area: "CRAWL-07 Links to other sites",
245
+ reason: `The pages link to ${outbound.size} address(es) on other sites, which weren't visited: that contacts other sites, so it needs the owner's own yes. With it, --outbound-links checks up to 100 of them, 4 at a time, for broken links.`,
246
+ });
247
+ return outbound;
248
+ }
249
+
250
+ // SECTION: a one-section crawl (--include or --exclude); capped: the crawl stopped at --max.
251
+ export function linkedOnce(site, { section: SECTION, capped }) {
252
+ const { htmlPages, byPage, add, extra, finalOf, isHome, indexable } = site;
253
+ // Indexable pages exactly one other page links to, the first 20 listed. A one-section crawl doesn't know the links
254
+ // from pages it leaves out, so it's skipped there.
255
+ if (!SECTION) {
256
+ const from = new Map();
257
+ for (const p of htmlPages)
258
+ for (const l of p.links) {
259
+ const f = finalOf(l.url);
260
+ if (f !== p.finalUrl) (from.get(f) || from.set(f, new Set()).get(f)).add(p.finalUrl);
261
+ }
262
+ const once = htmlPages.filter(p => indexable(p) && !isHome(p) && from.get(p.finalUrl)?.size === 1);
263
+ if (once.length)
264
+ extra.linkedOnce = {
265
+ count: once.length,
266
+ pages: once.slice(0, 20).map(p => ({ url: p.finalUrl, from: [...from.get(p.finalUrl)][0] })),
267
+ ...(capped ? { capped: true } : {}),
268
+ };
269
+ }
270
+ // A page#name link whose target lacks that id or <a name>, once each. Pages built only in the browser get their ids
271
+ // from JavaScript, so they aren't judged, nor are pages the crawl didn't read.
272
+ const done = new Set();
273
+ for (const p of htmlPages)
274
+ for (const [to, name] of p.fragLinks || []) {
275
+ const t = byPage.get(finalOf(to)),
276
+ key = t && `${t.finalUrl}#${name}`;
277
+ if (!t || t.clientOnly || done.has(key) || hasName(t.anchorIds, name)) continue;
278
+ done.add(key);
279
+ add("link-fragment-missing", p.finalUrl, `links to ${key}, but that page has no such part`);
280
+ }
281
+ }
282
+
283
+ // Each indexable page's link strength, 0–100, over the link checks' graph; noindex pages pass links on too. Keyed by
284
+ // path rather than a column on `pages`: leaner, and the report matches it to Search Console's paths. Skipped on a
285
+ // one-section crawl, as linkedOnce is.
286
+ export function linkStrength(site, { section: SECTION, capped }) {
287
+ const { htmlPages, extra, finalOf, indexable } = site;
288
+ if (!SECTION) {
289
+ const { rank, base } = pageRank(new Map(htmlPages.map(p => [p.finalUrl, p.links.map(l => finalOf(l.url))])));
290
+ const s = [
291
+ ...strengthScale(
292
+ rank,
293
+ base,
294
+ htmlPages.filter(p => indexable(p)).map(p => p.finalUrl),
295
+ ),
296
+ ].sort((a, b) => b[1] - a[1]);
297
+ if (s.length)
298
+ extra.linkStrength = {
299
+ pages: Object.fromEntries(
300
+ s.map(([u, v]) => {
301
+ const x = new URL(u);
302
+ return [x.pathname + x.search, v];
303
+ }),
304
+ ),
305
+ median: s[s.length >> 1][1],
306
+ ...(capped ? { capped: true } : {}),
307
+ };
308
+ }
309
+ }
310
+
311
+ // Each indexable page's words and links (as indexes into the same list) for keyword-ideas.mjs. A file of its own, so
312
+ // seo-crawl.json doesn't grow: a few KB a page, some 10–25 MB for 5,000 pages. Both files carry the crawl's start
313
+ // time (t0), so keyword-ideas can tell a file left from another crawl. OUT is the crawl file.
314
+ export function pageWords(site, { out: OUT, stamp: t0 }) {
315
+ const { htmlPages, extra, finalOf, indexable } = site;
316
+ const kept = htmlPages.filter(p => indexable(p) && !p.clientOnly && typeof p.mainWordsText === "string"),
317
+ at = new Map(kept.map((p, i) => [p.finalUrl, i]));
318
+ const file = OUT.replace(/\.json$/i, "") + ".words.json",
319
+ pathOf = u => {
320
+ const x = new URL(u);
321
+ return x.pathname + x.search;
322
+ };
323
+ mkdirSync(dirname(file), { recursive: true });
324
+ writeFileSync(
325
+ file,
326
+ JSON.stringify({
327
+ tool: "seo-supervisor-crawler-words",
328
+ stamp: t0,
329
+ pages: kept.map(p => ({
330
+ path: pathOf(p.finalUrl),
331
+ words: p.mainWordsText,
332
+ links: [...new Set(p.links.map(l => at.get(finalOf(l.url))).filter(i => i !== undefined))],
333
+ ...(p.mainNoSpace ? { nospace: true } : {}),
334
+ })),
335
+ }),
336
+ );
337
+ extra.pageWords = { file: basename(file), stamp: t0, pages: kept.length };
338
+ }
339
+
340
+ // Links to other sites, counted from the pages already read with no requests. pages: distinct addresses per page;
341
+ // domains: distinct addresses per host (www left off), the 1,000 most linked, which links-import.mjs crosses with
342
+ // Search Console's Top linking sites.
343
+ export function otherSites(site, outbound) {
344
+ const { htmlPages, extra, bareHost } = site;
345
+ const perPage = {},
346
+ domains = {};
347
+ for (const p of htmlPages) perPage[p.finalUrl] = linksAway(p, site).size;
348
+ for (const u of outbound.keys()) {
349
+ const h = bareHost(new URL(u).hostname);
350
+ domains[h] = (domains[h] || 0) + 1;
351
+ }
352
+ extra.linksToOtherSites = {
353
+ pages: perPage,
354
+ domains: Object.fromEntries(
355
+ Object.entries(domains)
356
+ .sort((a, b) => b[1] - a[1])
357
+ .slice(0, 1000),
358
+ ),
359
+ };
360
+ }
@@ -0,0 +1,101 @@
1
+ // @ts-check
2
+ // Whether a local business is a storefront, a service-area business or a hybrid, from its schema and visible text.
3
+ // The kind is never a finding or scored; it keeps nap-not-shown quiet for a service-area business hiding its street.
4
+ // Google: a service-area business hides an address it doesn't serve customers at, and a hybrid gives both.
5
+ // https://support.google.com/business/answer/3038177
6
+ // https://support.google.com/business/answer/9157481
7
+ // OnlineStore, Organization and a bare Service aren't local businesses.
8
+ import { isLocalBusinessType as isLocal } from "../lib/business.mjs";
9
+
10
+ const typesOf = n => [].concat(n?.["@type"] || []).filter(t => typeof t === "string");
11
+ const str = v => (typeof v === "string" && v.trim() ? v.trim() : null);
12
+ const ADDRESS = ["streetAddress", "addressLocality", "addressRegion", "postalCode", "addressCountry"];
13
+ // "We'll come to you" and the like. English only, a few common phrasings; other languages need their own.
14
+ const COME =
15
+ /\b(?:we|our (?:team|engineers?|technicians?|fitters?|staff|vans?))(?:['’]ll| will| can)? (?:come|comes|travel|travels|drive|drives) (?:out )?to (?:you|your (?:home|house|door|doorstep|office|site|premises|business|workplace|location|address))\b/i;
16
+ const pathOf = u => {
17
+ try {
18
+ return new URL(u).pathname;
19
+ } catch {
20
+ return u;
21
+ }
22
+ };
23
+ const coord = v => (typeof v === "number" || (typeof v === "string" && v.trim()) ? Number(v) : NaN);
24
+
25
+ // One page's local business nodes and come-to-you phrase, or null when it has neither.
26
+ export function localFeatures(nodes, text) {
27
+ const biz = nodes
28
+ .filter(n => typesOf(n).some(isLocal))
29
+ .map(n => {
30
+ const a = [].concat(n.address || []).find(x => str(x) || (x && typeof x === "object"));
31
+ const g = [].concat(n.geo || [])[0],
32
+ lat = coord(g?.latitude),
33
+ lon = coord(g?.longitude);
34
+ // serviceArea is areaServed's older name; an area is a name, a Place with a name, or a shape (GeoCircle, GeoShape).
35
+ const areas = [...[].concat(n.areaServed || []), ...[].concat(n.serviceArea || [])]
36
+ .map(x => str(x) || str(x?.name) || typesOf(x)[0])
37
+ .filter(Boolean);
38
+ return {
39
+ name: str(n.name),
40
+ type: typesOf(n).find(isLocal),
41
+ street: str(a) || str(a?.streetAddress),
42
+ address: str(a)
43
+ ? { text: str(a) }
44
+ : a
45
+ ? Object.fromEntries(ADDRESS.map(k => [k, str(a[k]) || str(a[k]?.name)]).filter(([, v]) => v))
46
+ : null,
47
+ geo: g && Math.abs(lat) <= 90 && Math.abs(lon) <= 180 ? { lat, lon } : null,
48
+ areas,
49
+ };
50
+ });
51
+ const come = String(text || "").match(COME);
52
+ return biz.length || come ? { biz, comeToYou: come?.[0] || null } : null;
53
+ }
54
+
55
+ // shows(page, { kind, value }) is the address check's visible-text test. Returns null when no page has local business
56
+ // schema; kind is null when nothing says either way.
57
+ export function judgeLocal(pages, shows) {
58
+ const at = pages.filter(p => p.local?.biz.length);
59
+ if (!at.length) return null;
60
+ const biz = at.flatMap(p => p.local.biz),
61
+ first = biz[0];
62
+ const streets = [...new Set(biz.map(b => b.street).filter(Boolean))];
63
+ const shown = streets.map(s => [s, pages.find(p => shows(p, { kind: "street address", value: s }))]);
64
+ const areas = [...new Set(biz.flatMap(b => b.areas))];
65
+ const come = pages.find(p => p.local?.comeToYou);
66
+ const serves = areas.length > 0 || !!come,
67
+ onSite = shown.some(([, p]) => p);
68
+ const kind = streets.length
69
+ ? onSite
70
+ ? serves
71
+ ? "hybrid"
72
+ : "storefront"
73
+ : serves
74
+ ? "service-area"
75
+ : "storefront"
76
+ : serves
77
+ ? "service-area"
78
+ : null;
79
+ const evidence = [
80
+ `schema: ${first.type}${first.name ? ` “${first.name}”` : ""} on ${pathOf(at[0].finalUrl)}`,
81
+ ...shown.map(
82
+ ([s, p]) =>
83
+ `street address “${s}” in the schema, ${p ? `shown on ${pathOf(p.finalUrl)}` : "not shown on any page"}`,
84
+ ),
85
+ ...(streets.length ? [] : ["no street address in the schema"]),
86
+ ...(areas.length
87
+ ? [`areaServed: ${areas.slice(0, 5).join(", ")}${areas.length > 5 ? ` and ${areas.length - 5} more` : ""}`]
88
+ : []),
89
+ ...(come ? [`text: “${come.local.comeToYou}” on ${pathOf(come.finalUrl)}`] : []),
90
+ ];
91
+ return {
92
+ kind,
93
+ name: first.name,
94
+ type: first.type,
95
+ address: biz.find(b => b.address)?.address || null,
96
+ geo: biz.find(b => b.geo)?.geo || null,
97
+ areas: areas.slice(0, 20),
98
+ evidence,
99
+ streetHidden: kind === "service-area" && streets.length > 0,
100
+ };
101
+ }
@@ -0,0 +1,194 @@
1
+ // @ts-check
2
+ // Image and DOM shape checks on the HTML and headers the crawler already fetched.
3
+ import { attrs } from "../lib/html.mjs";
4
+
5
+ export const CHECKS = {
6
+ "img-alt-quality": [
7
+ "CONTENT-08",
8
+ "low",
9
+ n => `${n} page(s) have alt text that doesn't describe the image`,
10
+ "Google reads alt text to understand an image and asks for useful, descriptive text, not a list of keywords. A file name, a bare word such as “image”, a string of keywords or a paragraph tells search engines and screen-reader users little about what the picture shows.",
11
+ 'Describe what the image shows in its context, in a short sentence (“Engineer fitting a combi boiler in a Leeds kitchen”). Use `alt=""` for decorative images, and put long descriptions in the text or a caption.',
12
+ ],
13
+ "image-preloads": [
14
+ "PERF-03",
15
+ "low",
16
+ n => `${n} page(s) preload more than one image`,
17
+ "A page has one largest image to show first, so one image preload is enough. web.dev advises using preload sparingly: “If too many resources are prioritized, effectively none of them are”, and the extra images compete with the hero for the network.",
18
+ 'Keep one image preload, for the hero (with `fetchpriority="high"`), and drop the others. Preloads for other screen sizes (with a `media` attribute) count as one. With Next.js, set `priority` on the hero image only.',
19
+ ],
20
+ "prerender-hint": [
21
+ "PERF-09",
22
+ "low",
23
+ n => `${n} page(s) use the old rel=prerender hint`,
24
+ 'Chrome no longer prerenders a page from `<link rel="prerender">`: it only fetches some of its files (NoState Prefetch), and Chrome\'s docs say the hint may be retired. The Speculation Rules API now does what it was meant to.',
25
+ 'Replace it with speculation rules: `<script type="speculationrules">{"prerender":[{"urls":["/next-page/"]}]}</script>`, or the prefetch rules PERF-09 describes.',
26
+ ],
27
+ "image-over-500kb": [
28
+ "PERF-08",
29
+ "medium",
30
+ n => `${n} image(s) weigh over 500 KB`,
31
+ "Each of these images costs a phone visitor more than half a megabyte. On a slow connection that alone takes seconds, and when it's the largest image on screen it holds up LCP.",
32
+ "Resize it to the size it's shown at and serve WebP or AVIF, through the framework's image component, the CDN, or scripts/images.mjs.",
33
+ ],
34
+ "hero-no-fetchpriority": [
35
+ "PERF-03",
36
+ "low",
37
+ n => `${n} page(s) load their largest image without fetchpriority="high"`,
38
+ "In a lab load, Chrome found that the largest image on the page (the LCP element) wasn't marked as important. Images start at low priority until the page is laid out, so the hero waits behind other files. web.dev: boosting the LCP image's priority makes LCP happen sooner.",
39
+ 'Add `fetchpriority="high"` to the hero `<img>` (and to its preload, if it has one), or `priority` on a Next.js `<Image>`. Only the hero: one high-priority image per page.',
40
+ ],
41
+ };
42
+
43
+ // Local lines, apart from Google's warning against keyword-stuffed alt text. Empty alt is right for decorative images.
44
+ // https://developers.google.com/search/docs/appearance/google-images
45
+ const GENERIC = /^(image|img|photo|picture|pic|graphic|icon|banner|untitled|placeholder)s?$/i;
46
+ export function altProblem(alt, src = "") {
47
+ const a = String(alt ?? "").trim();
48
+ if (!a) return null;
49
+ let stem = String(src)
50
+ .split(/[?#]/)[0]
51
+ .split("/")
52
+ .pop()
53
+ .replace(/\.[a-z0-9]+$/i, "");
54
+ try {
55
+ stem = decodeURIComponent(stem);
56
+ } catch {}
57
+ if (
58
+ /\.(jpe?g|png|gif|webp|avif|svg|bmp|tiff?|heic)$/i.test(a) ||
59
+ /^(img|dsc|dscn|dcim|pxl|mvimg|screenshot)[\s_-]?\d/i.test(a) ||
60
+ (/[-_\d]/.test(stem) && a.toLowerCase() === stem.toLowerCase())
61
+ )
62
+ return "a file name";
63
+ if (GENERIC.test(a.replace(/[^\p{L}\s]/gu, "").trim())) return "a generic word";
64
+ if (a.length > 150) return "over 150 characters";
65
+ const parts = a.split(",");
66
+ if (parts.length >= 4 && parts.every(p => p.trim().split(/\s+/).length <= 3)) return "a keyword list";
67
+ return null;
68
+ }
69
+
70
+ // The real image behind a lazy-loading script (lazysizes, Perfmatters, EWWW, WP Rocket, LiteSpeed): used when src is
71
+ // missing or a data: placeholder, or the image carries the loader's lazy class.
72
+ export function lazySrc(i) {
73
+ const real =
74
+ i["data-src"] ||
75
+ i["data-lazy-src"] ||
76
+ i["data-original"] ||
77
+ (i["data-srcset"] || i["data-lazy-srcset"] || "").trim().split(/\s+/)[0];
78
+ if (!real || /^data:/i.test(real)) return null;
79
+ return !i.src || /^data:/i.test(i.src) || /\blazy/i.test(i.class || "") ? real : null;
80
+ }
81
+
82
+ /** @typedef {{ rels: string[], as?: string, href?: string, imagesrcset?: string }} LinkTag every attribute by its lowercased name (those read here typed), and rel's values */
83
+ /** @type {(html: string) => LinkTag[]} */
84
+ const linkTags = html =>
85
+ [...html.replace(/<!--[\s\S]*?-->|<noscript\b[\s\S]*?<\/noscript>/gi, " ").matchAll(/<link\b[^>]*>/gi)].map(m => {
86
+ const a = /** @type {Record<string, string>} */ (attrs(m[0]));
87
+ return { ...a, rels: (a.rel || "").toLowerCase().split(/\s+/) };
88
+ });
89
+ export function hintsOf(html) {
90
+ const links = linkTags(html),
91
+ img = links.filter(l => l.rels.includes("preload") && (l.as || "").toLowerCase() === "image");
92
+ return {
93
+ // Preloads with a media attribute are one hero per screen size, so together they count as one.
94
+ imagePreloads: img.filter(l => !("media" in l)).length + (img.some(l => "media" in l) ? 1 : 0),
95
+ preloadHrefs: img
96
+ .map(l => l.href || (l.imagesrcset || "").trim().split(/\s+/)[0])
97
+ .filter(Boolean)
98
+ .slice(0, 3),
99
+ prerender: links
100
+ .filter(l => l.rels.includes("prerender"))
101
+ .map(l => l.href || "")
102
+ .slice(0, 3),
103
+ };
104
+ }
105
+
106
+ // Optional end tags (li, p, td, option…) close the open one when the next starts, so unclosed lists don't read as
107
+ // nesting. Not HTML's full parsing rules, but enough for the 32-deep and 60-children lines; use a real parser if finer
108
+ // counts matter.
109
+ const VOID = new Set([
110
+ "area",
111
+ "base",
112
+ "br",
113
+ "col",
114
+ "embed",
115
+ "hr",
116
+ "img",
117
+ "input",
118
+ "link",
119
+ "meta",
120
+ "param",
121
+ "source",
122
+ "track",
123
+ "wbr",
124
+ ]);
125
+ const AUTO = {
126
+ li: [["li"], /^(ul|ol|menu)$/],
127
+ dt: [["dt", "dd"], /^dl$/],
128
+ dd: [["dt", "dd"], /^dl$/],
129
+ tr: [["tr"], /^(table|thead|tbody|tfoot)$/],
130
+ td: [["td", "th"], /^(tr|table)$/],
131
+ th: [["td", "th"], /^(tr|table)$/],
132
+ option: [["option"], /^(select|datalist|optgroup)$/],
133
+ p: [["p"], /^$/],
134
+ };
135
+ export function domShape(html) {
136
+ const stack = [],
137
+ names = [],
138
+ kids = []; // open elements (tag.class), their tag names, and each one's child count
139
+ let depth = 0,
140
+ widest = { tag: null, children: 0 };
141
+ const src = html
142
+ .replace(/<!--[\s\S]*?-->/g, "")
143
+ .replace(/<(script|style|noscript|template|textarea)\b[^>]*>[\s\S]*?<\/\1>/gi, "<$1></$1>");
144
+ const cut = i => {
145
+ stack.length = i;
146
+ names.length = i;
147
+ kids.length = i;
148
+ };
149
+ for (const m of src.matchAll(/<(\/?)([a-z][\w-]*)\b([^>]*?)(\/?)>/gi)) {
150
+ const tag = m[2].toLowerCase();
151
+ if (m[1]) {
152
+ const i = names.lastIndexOf(tag);
153
+ if (i >= 0) cut(i);
154
+ continue;
155
+ }
156
+ if (AUTO[tag]) {
157
+ const [same, scope] = AUTO[tag],
158
+ i = Math.max(...same.map(s => names.lastIndexOf(s)));
159
+ if (i >= 0 && !names.slice(i + 1).some(t => scope.test(t))) cut(i);
160
+ }
161
+ if (kids.length && ++kids[kids.length - 1] > widest.children)
162
+ widest = { tag: stack[stack.length - 1], children: kids[kids.length - 1] };
163
+ if (VOID.has(tag) || m[4]) {
164
+ depth = Math.max(depth, stack.length + 1);
165
+ continue;
166
+ }
167
+ const cls = /\bclass\s*=\s*["']?([^\s"'>]+)/i.exec(m[3])?.[1];
168
+ stack.push(cls ? `${tag}.${cls}` : tag);
169
+ names.push(tag);
170
+ kids.push(0);
171
+ depth = Math.max(depth, stack.length);
172
+ }
173
+ return { depth, widest };
174
+ }
175
+
176
+ // A response header only that CDN sends.
177
+ const CDN_HEADERS = [
178
+ ["cf-cache-status", "Cloudflare"],
179
+ ["x-amz-cf-id", "Amazon CloudFront"],
180
+ ["x-vercel-cache", "Vercel"],
181
+ ["x-nf-request-id", "Netlify"],
182
+ ["cdn-pullzone", "Bunny"],
183
+ ["x-azure-ref", "Azure Front Door"],
184
+ ["x-fastly-request-id", "Fastly"],
185
+ ];
186
+ export const cdnOf = h => CDN_HEADERS.find(([k]) => h.has(k))?.[1] ?? null;
187
+ // Lighthouse flags static files browsers can't cache.
188
+ // https://developer.chrome.com/docs/lighthouse/performance/uses-long-cache-ttl
189
+ export function uncached(h) {
190
+ const cc = (h.get("cache-control") || "").toLowerCase();
191
+ if (/no-store|no-cache/.test(cc)) return true;
192
+ const age = /(?:^|[,\s])max-age\s*=\s*(\d+)/.exec(cc)?.[1];
193
+ return age != null ? Number(age) === 0 : !h.has("expires");
194
+ }