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,741 @@
1
+ // @ts-check
2
+ // Reads one crawled page into the record the checks use. site.toCrawl and site.sitemapHreflang are functions because
3
+ // the public origin can change mid-crawl.
4
+ import {
5
+ CLIENT_ROUTER,
6
+ NOSPACE_RUN,
7
+ attrs,
8
+ capsOf,
9
+ ctx,
10
+ deepHas,
11
+ headEndOf,
12
+ jsonLdNodes,
13
+ norm,
14
+ stripNonContent,
15
+ tagsOf,
16
+ textOf,
17
+ typesOf,
18
+ wordsOf,
19
+ } from "../lib/html.mjs";
20
+ import { clean, urlOr } from "./fetch.mjs";
21
+ import { RETIRED, KEPT, SHOP_FIELDS } from "./catalog.mjs";
22
+ import { trustFeatures } from "../checks/trust.mjs";
23
+ import { VALUED, agentFeatures, bingAiRules } from "../checks/agents.mjs";
24
+ import { writingText, writingFeatures } from "../checks/writing.mjs";
25
+ import { linkHreflang, mergeHreflang, languageFeatures } from "../checks/hreflang.mjs";
26
+ import { insecureResources } from "../checks/technical.mjs";
27
+ import { ugcLinks, backTrap, paywallLeak, lateHead } from "../checks/page.mjs";
28
+ import { fragmentLinks } from "../checks/crawl.mjs";
29
+ import { analyticsTwice, secretsIn, hiddenLinks, appPromo } from "../checks/hygiene.mjs";
30
+ import { SUPERSEDED, placeholderIn, merchantProblems, sellsWithOffer, reviewEventProblems } from "../checks/schema.mjs";
31
+ import { isBusinessType, isLocalBusinessType } from "../lib/business.mjs";
32
+ import { mainWords as pickMainWords } from "../keyword-ideas.mjs";
33
+ import { lazySrc, hintsOf, domShape } from "../checks/media.mjs";
34
+ import { obsoleteMore, keywordUse, isGuide, newestDate } from "../checks/content.mjs";
35
+ import { localFeatures } from "../checks/local.mjs";
36
+
37
+ // Google's rules from one robots meta content or X-Robots-Tag line. A "<crawler>:" prefix holds for the rules after it,
38
+ // and only unprefixed and googlebot rules count. "none" is noindex plus nofollow.
39
+ // https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag
40
+ export const agentRule = t => {
41
+ const m = /^\s*([a-z][\w-]*)\s*:\s*(.*)$/.exec(t);
42
+ return m && !VALUED.test(m[1]) ? m : null;
43
+ };
44
+ function googleRobots(s) {
45
+ let agent = null;
46
+ const out = [];
47
+ for (let t of (s || "").toLowerCase().split(",")) {
48
+ const m = agentRule(t);
49
+ if (m) [, agent, t] = m;
50
+ t = t.trim().replace(/\s*:\s*/, ":");
51
+ if (t && (!agent || agent === "googlebot")) out.push(...(t === "none" ? ["noindex", "nofollow"] : [t]));
52
+ }
53
+ return out;
54
+ }
55
+ const TITLE = /<title\b[^>]*>([\s\S]*?)<\/title>/i;
56
+ const relIs = (l, r) => (l.rel || "").toLowerCase().split(/\s+/).includes(r);
57
+ // Google takes a canonical link only from the head, takes the Link header too, and warns the two can disagree, so a
58
+ // header naming another URL is a second canonical (canonical-multiple). relative is the first one written without a
59
+ // scheme, since Google recommends absolute URLs.
60
+ // https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls
61
+ const LINK = /<([^>]*)>((?:\s*;\s*[\w*.-]+\s*(?:=\s*(?:"[^"]*"|[^\s;,]*))?)*)/g,
62
+ LINK_REL = /;\s*rel\s*=\s*(?:"([^"]*)"|([^\s;,]*))/i; // Link header entries, as checks/hreflang.mjs reads them
63
+ function canonicalsOf(headLinks, linkHeader, url, base) {
64
+ const html = headLinks.filter(l => relIs(l, "canonical")).map(l => l.href);
65
+ const header = [...(linkHeader || "").matchAll(LINK)]
66
+ .filter(([, , p]) => {
67
+ const r = LINK_REL.exec(p);
68
+ return (r?.[1] ?? r?.[2] ?? "").toLowerCase().split(/\s+/).includes("canonical");
69
+ })
70
+ .map(([, h]) => h.trim());
71
+ const named = new Set(html.map(c => (c && urlOr(c, base)?.href) ?? c)),
72
+ more = header.map(h => urlOr(h, url)?.href ?? h).filter(h => !named.has(h));
73
+ return {
74
+ list: [...html, ...more],
75
+ relative:
76
+ [...html, ...header].find(h => typeof h === "string" && h.trim() && !/^[a-z][a-z\d+.-]*:/i.test(h.trim())) ??
77
+ null,
78
+ };
79
+ }
80
+ // A light read for pages fetched again (the bot comparisons, hreflang return links), each field read as analyze()
81
+ // reads it.
82
+ export function readLight(html, url, headers = new Headers()) {
83
+ const headEnd = html.search(/<\/head>/i),
84
+ head = headEnd > 0 ? html.slice(0, headEnd) : html,
85
+ googleHead = headEndOf(html).at;
86
+ const bodyStart = html.search(/<body\b/i),
87
+ body = stripNonContent(bodyStart >= 0 ? html.slice(bodyStart) : html);
88
+ const titleM = head.match(TITLE) || body.match(TITLE),
89
+ links = tagsOf(head, "link");
90
+ const canonical = canonicalsOf(
91
+ googleHead < 0 ? tagsOf(html, "link") : tagsOf(html.slice(0, googleHead), "link"),
92
+ headers.get("link"),
93
+ url,
94
+ url,
95
+ ).list[0];
96
+ return {
97
+ title: titleM ? textOf(titleM[1]) : null,
98
+ canonical: canonical ? (urlOr(canonical, url)?.href ?? canonical) : null,
99
+ robots: [
100
+ ...tagsOf(html, "meta")
101
+ .filter(m => ["robots", "googlebot"].includes((m.name || "").toLowerCase()))
102
+ .flatMap(m => googleRobots(m.content)),
103
+ ...googleRobots(headers.get("x-robots-tag")),
104
+ ],
105
+ words: wordsOf(textOf(body)).length,
106
+ hreflang: [
107
+ ...links
108
+ .filter(l => relIs(l, "alternate") && l.hreflang && l.href)
109
+ .map(l => ({ lang: l.hreflang, href: l.href })),
110
+ ...linkHreflang(headers.get("link")),
111
+ ],
112
+ };
113
+ }
114
+ // Consent managers have to run before anything else, so a blocking script from one is fine.
115
+ const CONSENT_HOST =
116
+ /(^|\.)(cookiebot\.(com|eu)|cookielaw\.org|onetrust\.com|usercentrics\.eu|privacy-center\.org|iubenda\.com|cookieyes\.com|termly\.io|osano\.com)$/i;
117
+ // xRobotsLines: the X-Robots-Tag lines kept apart, when crawlOne (crawl/queue.mjs) read them raw.
118
+ export function analyze(url, html, headers, xRobotsLines, site) {
119
+ const { start: START, startOrigin: START_ORIGIN, banned: BANNED, verify: VERIFY, toCrawl, sitemapHreflang } = site;
120
+ const headEnd = html.search(/<\/head>/i);
121
+ const head = headEnd > 0 ? html.slice(0, headEnd) : html;
122
+ const headStop = headEndOf(html); // where Google stops reading the head
123
+ const bodyStart = html.search(/<body\b/i);
124
+ const bodyRaw = bodyStart >= 0 ? html.slice(bodyStart) : html;
125
+ const body = stripNonContent(bodyRaw);
126
+ const text = textOf(body);
127
+ const words = wordsOf(text).length;
128
+ // Next.js 15.2+ can stream metadata into <body> for non-bot visitors, so metas after the head count too. Only what
129
+ // follows the head is read: </head> and <body> are optional, and minifiers drop them.
130
+ const tailStart = Math.max(head.length, bodyStart);
131
+ const metas = [
132
+ ...tagsOf(head, "meta"),
133
+ ...tagsOf(tailStart === bodyStart ? body : stripNonContent(html.slice(tailStart)), "meta"),
134
+ ];
135
+ const meta = n => metas.find(m => (m.name || m.property || "").toLowerCase() === n)?.content;
136
+ const titleM = head.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i) || body.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i);
137
+ const titleCount = (stripNonContent(head).match(/<title\b/gi) || []).length; // an inline SVG's <title> isn't one, nor is a script's
138
+ const PH =
139
+ /\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/;
140
+ const allMetas = tagsOf(html, "meta"),
141
+ headLinks = tagsOf(head, "link");
142
+ let bodyLinks;
143
+ const bodyLinksOf = () => (bodyLinks ??= tagsOf(body, "link"));
144
+ const robotsTags = allMetas.filter(m => ["robots", "googlebot"].includes((m.name || "").toLowerCase())); // Google honours robots meta in <body> too
145
+ const robotsMeta = robotsTags
146
+ .map(m => m.content || "")
147
+ .join(",")
148
+ .toLowerCase();
149
+ const xRobots = (headers.get("x-robots-tag") || "").toLowerCase();
150
+ const metaRules = robotsTags.flatMap(m => googleRobots(m.content)),
151
+ headerRules = (xRobotsLines?.length ? xRobotsLines : [xRobots]).flatMap(googleRobots),
152
+ directives = [...metaRules, ...headerRules];
153
+ const hreflang = headLinks
154
+ .filter(l => (l.rel || "").toLowerCase().split(/\s+/).includes("alternate") && l.hreflang && l.href)
155
+ .map(l => ({ lang: l.hreflang, href: l.href }));
156
+ // Render-blocking: head scripts without async, defer or type="module" (other types don't run, and browsers skip
157
+ // nomodule), except consent managers', and stylesheets for every screen. Comments hide old IE shims, and <noscript>
158
+ // holds the fallbacks of stylesheets loaded later, so both are stripped.
159
+ const headOnly = (headEnd > 0 ? html.slice(0, headEnd) : bodyStart > 0 ? html.slice(0, bodyStart) : "").replace(
160
+ /<!--[\s\S]*?-->|<noscript\b[\s\S]*?<\/noscript>/gi,
161
+ " ",
162
+ );
163
+ const blockingJs = tagsOf(headOnly, "script")
164
+ .filter(
165
+ s =>
166
+ s.src &&
167
+ !["async", "defer", "nomodule"].some(k => k in s) &&
168
+ /^((text|application)\/(x-)?(java|ecma)script)?$/i.test((s.type || "").trim()) &&
169
+ !CONSENT_HOST.test(urlOr(s.src, url)?.hostname || ""),
170
+ )
171
+ .map(s => s.src);
172
+ const blockingCss = tagsOf(headOnly, "link").filter(l => {
173
+ const rel = (l.rel || "").toLowerCase().split(/\s+/);
174
+ return (
175
+ rel.includes("stylesheet") &&
176
+ !rel.includes("alternate") &&
177
+ !("disabled" in l) &&
178
+ /^(all|screen)?$/i.test((l.media || "").trim())
179
+ );
180
+ }).length;
181
+ // The favicon links Google reads, with the body as the fallback.
182
+ // https://developers.google.com/search/docs/appearance/favicon-in-search
183
+ const iconsIn = links =>
184
+ links
185
+ .filter(
186
+ l =>
187
+ l.href &&
188
+ (l.rel || "")
189
+ .toLowerCase()
190
+ .split(/\s+/)
191
+ .some(r => ["icon", "apple-touch-icon", "apple-touch-icon-precomposed"].includes(r)),
192
+ )
193
+ .map(l => l.href);
194
+ const headIcons = iconsIn(headLinks),
195
+ icons = headIcons.length ? headIcons : iconsIn(bodyLinksOf());
196
+ const headings = [...body.matchAll(/<h([1-6])\b[^>]*>([\s\S]*?)<\/h\1>/gi)].map(m => ({
197
+ level: +m[1],
198
+ text: textOf(m[2]),
199
+ }));
200
+ const anchors = [...body.matchAll(/<a\b([^>]*)>([\s\S]*?)<\/a>/gi)].map(m => ({
201
+ href: attrs("<a " + m[1] + ">").href,
202
+ text: textOf(m[2]),
203
+ }));
204
+ const imgs = tagsOf(body, "img");
205
+ const { nodes, errors } = jsonLdNodes(html);
206
+ const types = [...new Set(nodes.flatMap(typesOf))];
207
+ // Microdata (itemtype) and RDFa (typeof) types: "https://schema.org/Product" and "schema:Product" read as Product.
208
+ const schemaOther = [
209
+ ...new Set(
210
+ [...stripNonContent(html).matchAll(/<[a-z][\w-]*\s[^>]*(?:itemtype|typeof)\s*=[^>]*>/gi)]
211
+ .flatMap(m => {
212
+ const a = attrs(m[0]);
213
+ return `${a.itemtype || ""} ${a.typeof || ""}`.trim().split(/\s+/);
214
+ })
215
+ .map(t => t.replace(/^.*[\/#:]/, ""))
216
+ .filter(Boolean),
217
+ ),
218
+ ];
219
+ // Top-level field names per type, merged across blocks, so a later crawl can tell which fields went missing.
220
+ const schemaProps = {};
221
+ for (const n of nodes)
222
+ for (const t of typesOf(n))
223
+ schemaProps[t] = [
224
+ ...new Set([...(schemaProps[t] || []), ...Object.keys(n).filter(k => !k.startsWith("@"))]),
225
+ ].sort();
226
+ const faqQs = nodes
227
+ .filter(n => typesOf(n).includes("FAQPage"))
228
+ .flatMap(n => [].concat(n.mainEntity || []))
229
+ .map(q => q && q.name)
230
+ .filter(Boolean);
231
+ const crumbs = nodes
232
+ .filter(n => typesOf(n).includes("BreadcrumbList"))
233
+ .flatMap(n => [].concat(n.itemListElement || []))
234
+ .map(i => i && (typeof i.item === "string" ? i.item : i.item && (i.item["@id"] || i.item.url)))
235
+ .filter(Boolean);
236
+ const hasRating = nodes.some(n =>
237
+ deepHas(n, o => "aggregateRating" in o || typesOf(o).some(t => t === "AggregateRating" || t === "Review")),
238
+ );
239
+ // Matched at any depth, as schema-check.mjs does; a `top` type (Occupation) only when not nested.
240
+ const uses = r => (r.top ? types.includes(r.type) : nodes.some(n => deepHas(n, o => typesOf(o).includes(r.type))));
241
+ const deprecated = RETIRED.filter(uses).map(r => r.type),
242
+ kept = KEPT.filter(uses).map(r => r.type);
243
+ const phMatch = text.match(PH);
244
+ const mainM = body.match(/<main\b[^>]*>([\s\S]*?)<\/main>/i);
245
+ const mainHtml = mainM ? mainM[1] : body.replace(/<(header|nav|footer|aside)\b[\s\S]*?<\/\1>/gi, " ");
246
+ const mainText = textOf(mainHtml),
247
+ mw = wordsOf(mainText.toLowerCase());
248
+ const mainHrefs = [...mainHtml.matchAll(/<a\b([^>]*)>/gi)].map(m => attrs("<a " + m[1] + ">").href).filter(Boolean);
249
+ let shingles = null;
250
+ if (mw.length >= 50) {
251
+ shingles = new Set();
252
+ for (let i = 0; i + 5 <= mw.length; i++) shingles.add(mw.slice(i, i + 5).join(" "));
253
+ }
254
+ // Phone and street address from local business schema (LOCAL-05). Organization, Corporation, online-only businesses
255
+ // and Service aren't local.
256
+ const nap = [
257
+ ...new Map(
258
+ nodes
259
+ .filter(n => typesOf(n).some(isLocalBusinessType))
260
+ .flatMap(n => [
261
+ ...[]
262
+ .concat(n.telephone || [])
263
+ .filter(t => typeof t === "string" && t.replace(/\D/g, "").length >= 7)
264
+ .map(value => ({ kind: "phone", value })),
265
+ ...[]
266
+ .concat(n.address || [])
267
+ .map(a => (typeof a === "string" ? a : a?.streetAddress))
268
+ .filter(s => typeof s === "string" && norm(s))
269
+ .map(value => ({ kind: "street address", value })),
270
+ ])
271
+ .map(f => [f.kind + f.value, f]),
272
+ ).values(),
273
+ ];
274
+ // Merchant listing fields (SHOP-05).
275
+ // https://developers.google.com/search/docs/appearance/structured-data/merchant-listing
276
+ const products = nodes
277
+ .filter(n => typesOf(n).includes("Product"))
278
+ .map(n => {
279
+ const offers = [].concat(n.offers || []).filter(o => o && typeof o === "object");
280
+ const orgHas = key => nodes.some(o => typesOf(o).some(isBusinessType) && o[key]);
281
+ const prices = offers
282
+ .map(o => o.price ?? o.lowPrice)
283
+ .filter(v => v != null && !isNaN(parseFloat(v)))
284
+ .map(v => Number(String(v).replace(/,/g, "")));
285
+ // Every offer needs its own shipping and returns, an AggregateOffer's listed offers included, unless the
286
+ // organization sets them once.
287
+ const each = offers.flatMap(o =>
288
+ typesOf(o).includes("AggregateOffer") && o.offers
289
+ ? [].concat(o.offers).filter(x => x && typeof x === "object")
290
+ : [o],
291
+ );
292
+ return {
293
+ name: n.name || "a product",
294
+ offers: each.length,
295
+ singleAggregate: offers.some(
296
+ o =>
297
+ typesOf(o).includes("AggregateOffer") &&
298
+ (o.offerCount == null ||
299
+ Number(o.offerCount) <= 1 ||
300
+ (o.highPrice != null && Number(o.highPrice) === Number(o.lowPrice))),
301
+ ),
302
+ noShipping: orgHas("hasShippingService") ? 0 : each.filter(o => !o.shippingDetails).length,
303
+ noReturns:
304
+ n.hasMerchantReturnPolicy || orgHas("hasMerchantReturnPolicy")
305
+ ? 0
306
+ : each.filter(o => !o.hasMerchantReturnPolicy).length,
307
+ prices, // every offer's price: the page may show any one variant
308
+ };
309
+ });
310
+ // Parses a shown amount whatever its thousands and decimal separators.
311
+ const toNum = s => {
312
+ s = s.replace(/\s/g, "");
313
+ const i = Math.max(s.lastIndexOf("."), s.lastIndexOf(","));
314
+ return i >= 0 && s.length - i - 1 !== 3
315
+ ? Number(s.slice(0, i).replace(/[.,]/g, "") + "." + s.slice(i + 1))
316
+ : Number(s.replace(/[.,]/g, ""));
317
+ };
318
+ // A number is grouped in threes ("1 299,00", "10.000", "1,299.00") or plain ("29.99"), and "$49 99" (superscript
319
+ // cents) reads as 49.99 too. Every reading is kept, so a mismatch needs all of them to differ from the schema.
320
+ const NUM = String.raw`\d{1,3}(?:[.,\s  ]\d{3})+(?:[.,]\d{1,2})?|\d+(?:[.,]\d{1,2})?`,
321
+ CUR = String.raw`[$€£¥₹]|\b(?:USD|EUR|GBP|CAD|AUD|INR)\b`;
322
+ const amounts = products.length
323
+ ? [
324
+ ...text.matchAll(
325
+ new RegExp(
326
+ `(?:${CUR})\\s?(${NUM})(?:\\s(\\d{2})(?!\\d))?|(${NUM})\\s?(?:[€£]|\\b(?:USD|EUR|GBP|CAD|AUD|INR)\\b)`,
327
+ "g",
328
+ ),
329
+ ),
330
+ ]
331
+ .flatMap(m => {
332
+ const n = toNum(m[1] ?? m[3]);
333
+ return m[2] && !/[.,]\d{1,2}$/.test(m[1]) ? [n, n + Number(m[2]) / 100] : [n];
334
+ })
335
+ .filter(x => !isNaN(x))
336
+ : [];
337
+ const refresh = metas.find(m => (m["http-equiv"] || "").toLowerCase() === "refresh")?.content || "";
338
+ const emptyRoot = /<div[^>]+id=["'](root|app|__next|__nuxt)["'][^>]*>\s*<\/div>/i.test(bodyRaw);
339
+ // An unload handler keeps the page out of the back/forward cache.
340
+ // https://web.dev/articles/bfcache
341
+ const inlineJs = [...html.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script>/gi)].map(m => m[1]).join("\n");
342
+ const unload = /addEventListener\(\s*["'`]unload["'`]|\bonunload\s*=/.test(inlineJs)
343
+ ? "an unload listener in an inline script"
344
+ : /onunload/i.test(html) && /<[a-z][^>]*\sonunload\s*=/i.test(html)
345
+ ? "an onunload attribute"
346
+ : null;
347
+ // Links with no accessible name: no text (an SVG's <title> counts), aria-label, aria-labelledby, title, or alt or
348
+ // label inside. aria-hidden links (a card's image link beside its text link) are skipped, as axe and Lighthouse do.
349
+ const emptyLinks = [
350
+ ...bodyRaw
351
+ .replace(/<(script|style|template|noscript)\b[\s\S]*?<\/\1>|<!--[\s\S]*?-->/gi, " ")
352
+ .matchAll(/<a\b([^>]*)>([\s\S]*?)<\/a>/gi),
353
+ ]
354
+ .map(m => [attrs("<a " + m[1] + ">"), m[2]])
355
+ .filter(
356
+ ([a, inner]) =>
357
+ "href" in a &&
358
+ a["aria-hidden"]?.trim().toLowerCase() !== "true" &&
359
+ ![a["aria-label"], a["aria-labelledby"], a.title].some(v => v?.trim()) &&
360
+ !textOf(inner) &&
361
+ !/\s(alt|aria-label|aria-labelledby|title)\s*=\s*["']?\s*[^\s"'>]/i.test(inner),
362
+ )
363
+ .map(([a]) => a.href);
364
+ // The header's charset wins over the meta tag's; names are compared as browsers read them ("latin1" is windows-1252).
365
+ const label = s =>
366
+ (s || "")
367
+ .trim()
368
+ .replace(/^["']|["']$/g, "")
369
+ .toLowerCase() || null,
370
+ encoding = s => {
371
+ try {
372
+ return new TextDecoder(s).encoding;
373
+ } catch {
374
+ return s;
375
+ }
376
+ };
377
+ const headerCs = label((headers.get("content-type") || "").match(/charset=([^;\s]+)/i)?.[1]);
378
+ const metaCs = label(
379
+ metas
380
+ .map(
381
+ m =>
382
+ m.charset ||
383
+ (/^content-type$/i.test(m["http-equiv"] || "") && (m.content || "").match(/charset=([^;\s]+)/i)?.[1]),
384
+ )
385
+ .find(Boolean),
386
+ );
387
+ // Obsolete tags are looked for in the whole document, since a frameset takes the body's place.
388
+ const noScripts = html.replace(/<(script|style|template)\b[\s\S]*?<\/\1>|<!--[\s\S]*?-->/gi, " ");
389
+ const obsolete = [
390
+ ...new Set(
391
+ [...noScripts.matchAll(/<(frameset|frame|marquee|blink|font|center)(?=[\s>\/])/gi)].map(m => m[1].toLowerCase()),
392
+ ),
393
+ ];
394
+ // Relative URLs resolve against the first <base href>, itself resolved against the page URL, as browsers do.
395
+ // resolve() is memoized because the checks resolve the same address many times.
396
+ const base = urlOr(tagsOf(head, "base").find(b => b.href)?.href ?? url, url)?.href ?? url;
397
+ const resolved = new Map(),
398
+ resolve = s => {
399
+ if (!resolved.has(s)) resolved.set(s, urlOr(s, base));
400
+ return resolved.get(s);
401
+ };
402
+ const googleHeadLinks =
403
+ headStop.at < 0
404
+ ? tagsOf(html, "link")
405
+ : headStop.at === head.length
406
+ ? headLinks
407
+ : tagsOf(html.slice(0, headStop.at), "link");
408
+ const canon = canonicalsOf(googleHeadLinks, headers.get("link"), url, base);
409
+ const rec = {
410
+ base,
411
+ title: titleM ? textOf(titleM[1]) : null,
412
+ description: meta("description") ?? null,
413
+ ogTitle: meta("og:title") ?? null,
414
+ ogImage: meta("og:image") ?? null,
415
+ ogUrl: meta("og:url") ?? null,
416
+ ogDescription: meta("og:description") ?? null,
417
+ ogImageSized: !!(meta("og:image:width") && meta("og:image:height")),
418
+ // X reads twitter: tags from name= and falls back to property=, and the last twitter:card on the page wins.
419
+ // From X's cards getting-started guide, archived 30 May 2025.
420
+ twitterCard: metas.findLast(m => (m.name || m.property || "").toLowerCase() === "twitter:card")?.content ?? null,
421
+ doctype: /^\s*(?:<!--[\s\S]*?-->\s*)*<!doctype html/i.test(html.replace(/^\uFEFF/, "")),
422
+ charset:
423
+ metas.some(m => m.charset || /charset=/i.test(m.content || "")) ||
424
+ /charset=/i.test(headers.get("content-type") || ""),
425
+ viewport: /width\s*=\s*device-width/i.test(meta("viewport") || ""),
426
+ refreshTo: (refresh.match(/url\s*=\s*['"]?([^'"\s;]+)/i) || [])[1] || null,
427
+ robotsMeta,
428
+ xRobots,
429
+ lang: (html.match(/<html\b[^>]*\blang\s*=\s*["']?([\w-]+)/i) || [])[1] || null,
430
+ noindex: directives.includes("noindex"),
431
+ nofollow: directives.includes("nofollow"),
432
+ metaRules,
433
+ headerRules,
434
+ canonicals: canon.list,
435
+ hreflang,
436
+ products,
437
+ amounts,
438
+ nosnippet: directives.some(r => r === "nosnippet" || r === "max-snippet:0"),
439
+ largePreview: directives.includes("max-image-preview:large"),
440
+ headings,
441
+ h1Count: headings.filter(h => h.level === 1).length,
442
+ words,
443
+ normText: norm(text),
444
+ caps: capsOf(text),
445
+ anchors,
446
+ imgs,
447
+ icons,
448
+ blockingJs,
449
+ blockingCss,
450
+ nap,
451
+ types,
452
+ schemaOther,
453
+ schemaProps,
454
+ jsonldErrors: errors,
455
+ faqQs,
456
+ crumbs,
457
+ hasRating,
458
+ deprecated,
459
+ kept,
460
+ emptyRoot,
461
+ mainHrefs,
462
+ banned: BANNED ? ctx(text, BANNED) : null,
463
+ unconfirmed: VERIFY ? ctx(text, VERIFY) : null,
464
+ shingles,
465
+ titleCount,
466
+ placeholder: phMatch ? phMatch[0] : null,
467
+ hashLinks: anchors.filter(l => !l.href || l.href === "#" || /^javascript:/i.test(l.href)).length,
468
+ scripts: (html.match(/<script\b[^>]*\bsrc=/gi) || []).length,
469
+ bytes: Buffer.byteLength(html),
470
+ noStore: /\bno-store\b/i.test(headers.get("cache-control") || ""),
471
+ unload,
472
+ emptyLinks,
473
+ obsolete,
474
+ charsetMismatch:
475
+ headerCs && metaCs && encoding(headerCs) !== encoding(metaCs) ? `header: ${headerCs} · meta: ${metaCs}` : null,
476
+ preloads:
477
+ /<script\b[^>]*\btype\s*=\s*["']?speculationrules/i.test(html) ||
478
+ headers.has("speculation-rules") ||
479
+ CLIENT_ROUTER.test(html),
480
+ // Body elements as Lighthouse counts them; what a script, style, noscript or template holds isn't in the DOM tree.
481
+ elements: (
482
+ bodyRaw
483
+ .replace(/<!--[\s\S]*?-->/g, "")
484
+ .replace(/<(script|style|noscript|template)\b[^>]*>[\s\S]*?<\/\1>/gi, "<$1>")
485
+ .match(/<[a-z][\w-]*/gi) || []
486
+ ).length,
487
+ };
488
+ rec.trust = trustFeatures(html, url, rec.base, { nodes, bodyRaw, resolve });
489
+
490
+ rec.agent = agentFeatures(html);
491
+ rec.writing = writingFeatures(writingText(mainHtml), rec.lang);
492
+
493
+ // The home page's main text feeds the business-type guess, minus post teasers (two or more <article>s).
494
+ if (url === START.href || new URL(url).pathname === "/")
495
+ rec.bizText =
496
+ (mainHtml.match(/<article\b/gi) || []).length > 1
497
+ ? textOf(mainHtml.replace(/<article\b[\s\S]*?<\/article>/gi, " "))
498
+ : mainText;
499
+
500
+ // Links with a space or non-ASCII character in the path or query. A non-ASCII host is fine: browsers punycode it.
501
+ const rawPath = h => h.replace(/^(?:[a-z][\w+.-]*:)?\/\/[^/?#]*/i, "").split("#")[0];
502
+ rec.unencoded = [
503
+ ...new Set(
504
+ anchors
505
+ .map(a => a.href?.trim())
506
+ .filter(h => h && !/^(mailto|tel|javascript|sms|data):/i.test(h) && /[^\x21-\x7e]/.test(rawPath(h))),
507
+ ),
508
+ ];
509
+ // Wide images without srcset; one in a <picture> has its own sources, and SVG scales.
510
+ const realSrc = i => i.src && !/^data:/i.test(i.src);
511
+ rec.wideImgs = tagsOf(body.replace(/<picture\b[\s\S]*?<\/picture>/gi, " "), "img")
512
+ .filter(
513
+ i => realSrc(i) && parseInt(i.width) > 1000 && !i.srcset && !i["data-srcset"] && !/\.svg(?:[?#]|$)/i.test(i.src),
514
+ )
515
+ .map(i => `${i.src} (${parseInt(i.width)} px)`);
516
+ // Images from the 11th on with no loading attribute (an explicit eager is a choice), bar script-loaded and tiny ones.
517
+ rec.eagerLate = imgs
518
+ .slice(10)
519
+ .filter(i => realSrc(i) && !("loading" in i) && !i["data-src"] && !(parseInt(i.width) < 100))
520
+ .map(i => i.src);
521
+
522
+ // hreflang from the HTML, Link header and sitemap is merged before the checks run, noting where sources disagree.
523
+ Object.assign(
524
+ rec,
525
+ mergeHreflang(
526
+ { html: hreflang, header: linkHreflang(headers.get("link")), sitemap: sitemapHreflang(url) },
527
+ url,
528
+ toCrawl,
529
+ ),
530
+ languageFeatures(html, nodes),
531
+ );
532
+
533
+ // Number-only headings are flagged, years aside.
534
+ rec.dupHead = ["description", "robots", "viewport", "og:title"]
535
+ .map(
536
+ n =>
537
+ /** @type {[string, number]} */ ([
538
+ n,
539
+ metas.filter(m => (m.name || m.property || "").toLowerCase() === n).length,
540
+ ]),
541
+ )
542
+ .filter(([, c]) => c > 1)
543
+ .map(([n, c]) => `${c} × ${n}`);
544
+ rec.numberHeadings = headings
545
+ .filter(
546
+ h => /^[#№]?[+\-−]?[$€£¥]?\d[\d.,\s]*(?:[kmb%x×])?\+?\.?$/i.test(h.text) && !/^(1[5-9]|20)\d\d$/.test(h.text),
547
+ )
548
+ .map(h => `H${h.level} “${h.text}”`);
549
+ rec.referrerMeta = meta("referrer") ?? null;
550
+
551
+ // http:// files in the head and body, judged later site-wide against the public origin.
552
+ rec.insecure = insecureResources(html, headers.get("content-security-policy") || "");
553
+
554
+ // Hrefs and srcs no URL parser can read, which the crawl would otherwise skip silently.
555
+ rec.badUrls = [
556
+ ...new Set([...anchors.map(a => a.href), ...imgs.map(i => i.src)].filter(h => h?.trim() && !resolve(h.trim()))),
557
+ ];
558
+
559
+ // Inputs for checks/page.mjs. identity takes the business (not Service) and WebSite nodes' @id and name.
560
+ const idNodes = pred => nodes.filter(n => typesOf(n).some(pred)).map(n => ({ id: n["@id"], name: n.name }));
561
+ const late = lateHead(html, headStop.at);
562
+ rec.pageChecks = {
563
+ ugc: ugcLinks(body)
564
+ .map(h => urlOr(h, rec.base))
565
+ .filter(x => x && /^https?:$/.test(x.protocol))
566
+ .map(x => x.href),
567
+ backTrap: backTrap(html),
568
+ paywall: paywallLeak(body, nodes),
569
+ late,
570
+ // The element that ended Google's head early (an <img>, an <iframe>), when tags came after it.
571
+ lateAt: late.length && !/^<(\/head|body)>$/.test(headStop.by) ? headStop.by : null,
572
+ relCanon: canon.relative, // a canonical written without a scheme (canonical-relative, URL-04)
573
+ identity: { org: idNodes(isBusinessType), site: idNodes(t => t === "WebSite") },
574
+ };
575
+
576
+ // Fragment targets (every id, and <a name>) and the links that jump to one, for checks/crawl.mjs.
577
+ rec.anchorIds = new Set(
578
+ [...noScripts.matchAll(/<([a-z][\w-]*)\s[^>]*\b(?:id|name)\s*=[^>]*>/gi)]
579
+ .flatMap(m => {
580
+ const a = attrs(m[0]);
581
+ return [a.id, m[1].toLowerCase() === "a" ? a.name : null];
582
+ })
583
+ .filter(Boolean),
584
+ );
585
+ rec.fragLinks = fragmentLinks(
586
+ [...body.matchAll(/<a\b[^>]*>/gi)].map(m => attrs(m[0])),
587
+ rec.base,
588
+ ).map(([u, name]) => [clean(toCrawl(u)), name]);
589
+
590
+ // Inputs for checks/hygiene.mjs. A secret key leaves analyze only as its type and first characters; its words are
591
+ // kept just to scrub them from the words file.
592
+ {
593
+ const keys = secretsIn(html),
594
+ navHrefs = [...body.matchAll(/<nav\b[\s\S]*?<\/nav>/gi)].flatMap(m => tagsOf(m[0], "a").map(a => a.href));
595
+ // An own-site link's crawl URL and whether it's a PDF, memoized; null off the site.
596
+ const owned = new Map(),
597
+ own = h => {
598
+ const k = (h || "").trim();
599
+ if (!owned.has(k)) {
600
+ const x = resolve(k),
601
+ y = x && /^https?:$/.test(x.protocol) ? urlOr(toCrawl(x.href)) : null;
602
+ if (y) y.hash = "";
603
+ owned.set(k, y && y.origin === START_ORIGIN ? { href: y.href, pdf: /\.pdf$/i.test(y.pathname) } : null);
604
+ }
605
+ return owned.get(k);
606
+ };
607
+ const pdfOf = h => {
608
+ const o = own(h);
609
+ return o?.pdf ? o.href : null;
610
+ };
611
+ rec.hygieneSignals = {
612
+ analytics: analyticsTwice(html),
613
+ keys: keys.map(k => `${k.label} (${k.shown})`),
614
+ scrub: keys.flatMap(k => pickMainWords(k.raw)),
615
+ hidden: hiddenLinks(body),
616
+ app: appPromo(html),
617
+ schema: reviewEventProblems(nodes),
618
+ pdfs: [...new Set(anchors.map(a => pdfOf(a.href)).filter(Boolean))],
619
+ navPdfs: [...new Set(navHrefs.map(pdfOf).filter(Boolean))],
620
+ js: [
621
+ ...new Set(
622
+ tagsOf(html.replace(/<!--[\s\S]*?-->/g, " "), "script")
623
+ .map(s => s.src && own(s.src)?.href)
624
+ .filter(Boolean),
625
+ ),
626
+ ],
627
+ };
628
+ }
629
+
630
+ // Words for the Markdown comparison: the main text, and all a reader sees. Kept on every page with 50+ main words,
631
+ // as the Markdown sample is picked after the crawl, and joined into strings to save memory.
632
+ {
633
+ const w = s => pickMainWords(s.replace(NOSPACE_RUN, " ")),
634
+ main = w(mainText);
635
+ if (main.length >= 50)
636
+ rec.markdownWords = {
637
+ main: main.join(" "),
638
+ all: w([rec.title, rec.description, rec.ogTitle, rec.ogDescription, text].join(" ")).join(" "),
639
+ };
640
+ }
641
+
642
+ // Words of the title, H1s and main text, for keyword-ideas.mjs. Runs of a script written without spaces are dropped
643
+ // (no words to match), and a page mostly in one is marked, so no missing search is claimed for it.
644
+ {
645
+ const t = [rec.title || "", ...headings.filter(h => h.level === 1).map(h => h.text), mainText].join(" "),
646
+ ns = (t.match(NOSPACE_RUN) || []).join("").length;
647
+ rec.mainWordsText = pickMainWords(t.replace(NOSPACE_RUN, " ")).join(" ");
648
+ rec.mainNoSpace = ns * 2 > (t.match(/\p{L}/gu) || []).length;
649
+ }
650
+
651
+ // Bing's AI rules (AI-03), kept only on pages that have any.
652
+ {
653
+ const b = bingAiRules(
654
+ allMetas.filter(m => /^(robots|bingbot)$/i.test(m.name || "")).map(m => m.content || ""),
655
+ xRobotsLines?.length ? xRobotsLines : [headers.get("x-robots-tag") || ""],
656
+ );
657
+ if (b.legacy.length || b.prefs.length) rec.bingAi = b;
658
+ }
659
+
660
+ rec.schemaPlaceholder = placeholderIn(JSON.stringify(nodes));
661
+ // Deprecated types count at any JSON-LD depth, and in Microdata or RDFa.
662
+ rec.superseded = Object.keys(SUPERSEDED).filter(
663
+ t => schemaOther.includes(t) || nodes.some(n => deepHas(n, o => typesOf(o).includes(t))),
664
+ );
665
+ const schemaImages = new Set(),
666
+ pick = (o, d) => {
667
+ if (!o || typeof o !== "object" || d > 12) return;
668
+ for (const k of ["image", "logo", "thumbnailUrl"])
669
+ for (const x of [].concat(o[k] ?? [])) {
670
+ const s = typeof x === "string" ? x : x?.contentUrl || x?.url;
671
+ if (typeof s === "string" && s.trim()) schemaImages.add(s.trim());
672
+ }
673
+ Object.values(o).forEach(x => pick(x, d + 1));
674
+ };
675
+ nodes.forEach(n => pick(n, 0));
676
+ rec.schemaImages = [...schemaImages];
677
+
678
+ // Per Product: merchant listing problems, a missing required image, no adult label on a page rated adult for
679
+ // SafeSearch, and the recommended fields given. A stand-in brand doesn't count as one.
680
+ const shopNodes = nodes.filter(n => typesOf(n).includes("Product"));
681
+ if (shopNodes.length) {
682
+ const adult = metas.some(
683
+ m =>
684
+ (m.name || "").toLowerCase() === "rating" &&
685
+ /^(adult|RTA-5042-1996-1400-1577-RTA)$/i.test((m.content || "").trim()),
686
+ );
687
+ const filled = (n, k) => n[k] != null && n[k] !== "" && !(Array.isArray(n[k]) && !n[k].length);
688
+ rec.shop = shopNodes.map(n => {
689
+ const problems = merchantProblems(n);
690
+ if (sellsWithOffer(n) && !filled(n, "image")) problems.push({ check: "image-missing" });
691
+ if (
692
+ adult &&
693
+ ![]
694
+ .concat(n.hasAdultConsideration ?? [])
695
+ .some(x => /SexualContentConsideration$/.test(typeof x === "string" ? x : x?.["@id"] || ""))
696
+ )
697
+ problems.push({ check: "adult-unlabelled" });
698
+ const fields = Object.keys(SHOP_FIELDS).filter(
699
+ f =>
700
+ SHOP_FIELDS[f].some(k => filled(n, k)) &&
701
+ !(f === "brand" && problems.some(x => x.check === "brand-placeholder")),
702
+ );
703
+ return { name: typeof n.name === "string" && n.name ? n.name : "a product", problems, fields };
704
+ });
705
+ }
706
+
707
+ // A lazy-loading script's image (data-src behind a placeholder) is read as its real file, so it's weighed and named.
708
+ // The LCP guess is the fetchpriority="high" image, else the first not declared under 100 × 100 px or named an icon.
709
+ const lazy = imgs.map(lazySrc);
710
+ const small = i => Number(i.width) > 0 && Number(i.height) > 0 && Number(i.width) < 100 && Number(i.height) < 100;
711
+ const icon = (i, k) =>
712
+ /(?:^|[^a-z])icons?(?:[^a-z]|$)/i.test(
713
+ `${(lazy[k] || i.src || "").split(/[?#]/)[0].split("/").pop()} ${i.alt || ""}`,
714
+ );
715
+ const hinted = imgs.findIndex(i => (i.fetchpriority || "").toLowerCase() === "high");
716
+ rec.lcpIndex = hinted >= 0 ? hinted : imgs.findIndex((i, k) => !small(i) && !icon(i, k));
717
+ rec.lcpScriptLazy = rec.lcpIndex >= 0 && !!lazy[rec.lcpIndex];
718
+ imgs.forEach((i, k) => {
719
+ if (lazy[k]) i.src = lazy[k];
720
+ });
721
+ Object.assign(rec, hintsOf(html), { domShape: domShape(bodyRaw) });
722
+
723
+ // Dates are read from the whole body, not the main text, since an article's <header> often holds them.
724
+ rec.obsolete.push(...obsoleteMore(html, noScripts));
725
+ rec.guideDate = isGuide(url, rec.title, types) ? newestDate(body, nodes) : null;
726
+ rec.keywordUse = /^en(?![a-z])/i.test(rec.lang || "")
727
+ ? keywordUse({ title: rec.title, headings, description: rec.description || "", text: mainText })
728
+ : null;
729
+
730
+ // Local business schema, plus "we come to you" wording in the text.
731
+ rec.local = localFeatures(nodes, text);
732
+
733
+ return rec;
734
+ }
735
+ // Product schema images, for the pixel size Google recommends (SHOP-05).
736
+ export const productImages = html =>
737
+ jsonLdNodes(html)
738
+ .nodes.filter(n => typesOf(n).includes("Product"))
739
+ .flatMap(n => [].concat(n.image || []))
740
+ .map(i => (typeof i === "string" ? i : i?.contentUrl || i?.url))
741
+ .filter(i => typeof i === "string");