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,396 @@
1
+ // @ts-check
2
+ // hreflang and page-language checks.
3
+
4
+ // ISO 639-1 languages and ISO 3166-1 alpha-2 regions, the formats Google names.
5
+ // https://developers.google.com/search/docs/specialty/international/localized-versions
6
+ const LANGS = new Set(
7
+ "aa ab ae af ak am an ar as av ay az ba be bg bi bm bn bo br bs ca ce ch co cr cs cu cv cy da de dv dz ee el en eo es et eu fa ff fi fj fo fr fy ga gd gl gn gu gv ha he hi ho hr ht hu hy hz ia id ie ig ii ik io is it iu ja jv ka kg ki kj kk kl km kn ko kr ks ku kv kw ky la lb lg li ln lo lt lu lv mg mh mi mk ml mn mr ms mt my na nb nd ne ng nl nn no nr nv ny oc oj om or os pa pi pl ps pt qu rm rn ro ru rw sa sc sd se sg si sk sl sm sn so sq sr ss st su sv sw ta te tg th ti tk tl tn to tr ts tt tw ty ug uk ur uz ve vi vo wa wo xh yi yo za zh zu".split(
8
+ " ",
9
+ ),
10
+ );
11
+ const REGIONS = new Set(
12
+ "ad ae af ag ai al am ao aq ar as at au aw ax az ba bb bd be bf bg bh bi bj bl bm bn bo bq br bs bt bv bw by bz ca cc cd cf cg ch ci ck cl cm cn co cr cu cv cw cx cy cz de dj dk dm do dz ec ee eg eh er es et fi fj fk fm fo fr ga gb gd ge gf gg gh gi gl gm gn gp gq gr gs gt gu gw gy hk hm hn hr ht hu id ie il im in io iq ir is it je jm jo jp ke kg kh ki km kn kp kr kw ky kz la lb lc li lk lr ls lt lu lv ly ma mc md me mf mg mh mk ml mm mn mo mp mq mr ms mt mu mv mw mx my mz na nc ne nf ng ni nl no np nr nu nz om pa pe pf pg ph pk pl pm pn pr ps pt pw py qa re ro rs ru rw sa sb sc sd se sg sh si sj sk sl sm sn so sr ss st sv sx sy sz tc td tf tg th tj tk tl tm tn to tr tt tv tw tz ua ug um us uy uz va vc ve vg vi vn vu wf ws ye yt za zm zw".split(
13
+ " ",
14
+ ),
15
+ );
16
+
17
+ // A language, optional script (zh-Hant) and optional region, or x-default.
18
+ export function validCode(code) {
19
+ const c = code.toLowerCase();
20
+ if (c === "x-default") return true;
21
+ const m = c.match(/^([a-z]{2})(?:-([a-z]{4}))?(?:-([a-z]{2}))?$/);
22
+ return !!m && LANGS.has(m[1]) && (!m[3] || REGIONS.has(m[3]));
23
+ }
24
+
25
+ // Google reads hreflang from the HTML, the Link header and the sitemap alike, so using more than one gains nothing. It
26
+ // detects a page's language from its visible text, not hreflang or lang, and recommends a URL per language.
27
+ // https://developers.google.com/search/docs/specialty/international/localized-versions
28
+ // https://developers.google.com/search/docs/specialty/international/managing-multi-regional-sites
29
+ export const CHECKS = {
30
+ "hreflang-no-return": [
31
+ "META-08",
32
+ "high",
33
+ n => `${n} hreflang link(s) have no return link`,
34
+ "Search engines ignore an hreflang pair unless both pages point at each other.",
35
+ "Generate hreflang for every language version from one shared list, so each page lists every version, itself included.",
36
+ ],
37
+ "hreflang-invalid-code": [
38
+ "META-08",
39
+ "medium",
40
+ n => `${n} hreflang value(s) aren't valid language or region codes`,
41
+ "Codes search engines can't read are ignored. A common mistake is `en-uk`: the United Kingdom's region code is `gb`.",
42
+ "Use an ISO 639-1 language, optionally followed by an ISO 3166-1 alpha-2 region (for example `en-GB`), or `x-default`.",
43
+ ],
44
+ "hreflang-no-self": [
45
+ "META-08",
46
+ "low",
47
+ n => `${n} page(s) with hreflang don't list themselves`,
48
+ "Each page should include itself in its own hreflang set.",
49
+ "Add the page's own URL with its own language code.",
50
+ ],
51
+ "hreflang-no-xdefault": [
52
+ "META-08",
53
+ "low",
54
+ n => `${n} page(s) with hreflang have no x-default`,
55
+ "x-default tells search engines which version to show visitors whose language matches none of the listed ones.",
56
+ "Add an x-default entry, usually the main version or a language picker.",
57
+ ],
58
+ "hreflang-bad-target": [
59
+ "META-08",
60
+ "high",
61
+ n => `${n} hreflang link(s) point at a URL that isn't a working canonical page`,
62
+ "hreflang must point at the canonical, indexable, 200 version of each page, or the pair is ignored.",
63
+ "Point each hreflang at the final canonical URL of that language version.",
64
+ ],
65
+ "hreflang-sources-disagree": [
66
+ "META-08",
67
+ "medium",
68
+ n => `${n} page(s) pair a language and a URL differently in the HTML, the Link header and the sitemap`,
69
+ "Google reads hreflang from all three places, treats them alike and combines them, and says using more than one brings no benefit. It doesn't say which wins when they conflict, so a version can be paired with the wrong URL or language. Two lists usually drift apart after a URL change, when one is updated and the other isn't.",
70
+ "Keep hreflang in one place (HTML tags, the Link header or the sitemap) and remove the others, or build every one from the same list.",
71
+ ],
72
+ "hreflang-missing-version": [
73
+ "META-08",
74
+ "low",
75
+ n => `${n} page(s) leave out a language version their other versions list`,
76
+ "Each version of a page has to list every version, itself included. These pages lack one the pages they link to list, so search engines may not pair it with them and can show visitors the wrong language.",
77
+ "Build each page's hreflang from one shared list of the page's versions, so they all list the same set.",
78
+ ],
79
+ "lang-hreflang-mismatch": [
80
+ "META-08",
81
+ "low",
82
+ n => `${n} page(s) declare a different language in <html lang> than their hreflang`,
83
+ 'The page\'s `lang` says one language while hreflang calls it another. Google ignores `lang` and goes by the visible text, but screen readers pick their pronunciation from it (WCAG 3.1.1) and browsers offer translation from it, so one of the two is wrong, often a layout that hard-codes `lang="en"` for every language.',
84
+ "Set `<html lang>` from the same locale as the page's hreflang code, in the shared layout.",
85
+ ],
86
+ "untranslated-copy": [
87
+ "META-08",
88
+ "medium",
89
+ n => `${n} pair(s) of language versions share their main text`,
90
+ "The versions are listed as different languages, but one wasn't translated. Google works out a page's language from its visible text, so an untranslated version counts as the original language and can't rank for the other one, and the two compete as duplicates.",
91
+ "Translate the title and main text of each version, or drop the untranslated page from hreflang (and the language menu) until it's translated.",
92
+ ],
93
+ "lang-invalid": [
94
+ "META-08",
95
+ "low",
96
+ n => `${n} page(s) have an <html lang> that isn't a language code`,
97
+ "`lang` takes a BCP 47 language tag such as `en` or `de-AT`. A value such as `auto`, `english` or `en_US` names no language, so screen readers and browser translation can't use it.",
98
+ "Set `lang` to the page's language code (`en`, `en-US`, `de-AT`; a hyphen, not an underscore) from the site's locale setting.",
99
+ ],
100
+ "translate-widget": [
101
+ "META-08",
102
+ "low",
103
+ () => "The site is translated only by the Google Translate widget",
104
+ "The widget translates the page in the visitor's browser, on the same URL, after they pick a language. Google indexes the text the page shows and recommends a separate URL for each language version, so search engines see only the original language and the translations never appear in search.",
105
+ "For languages that matter, publish translated pages on their own URLs (`/de/`, `de.example.com`) linked with hreflang. Keep the widget only as an extra for the other languages.",
106
+ ],
107
+ "inlanguage-mismatch": [
108
+ "META-08",
109
+ "low",
110
+ n => `${n} page(s) name a different language in schema inLanguage than in <html lang>`,
111
+ "The structured data says the content is in one language and the page's `lang` says another. One of them was copied from another language version or a sitewide default.",
112
+ "Set `inLanguage` from the same locale as `<html lang>` (a BCP 47 code such as `de-DE`).",
113
+ ],
114
+ };
115
+
116
+ const pathKey = u => u.pathname.replace(/\/+$/, "") || "/";
117
+ // Links to the page's own or the public origin are ours and compared by path; other hosts can't be verified. A variant
118
+ // is the site's host on the other protocol or with or without www: ours, but not where the pages live, so a bad target.
119
+ const bareHost = u => u.host.replace(/^www\./i, "");
120
+ const entriesOf = (p, origin) =>
121
+ (p.hreflang || []).flatMap(h => {
122
+ try {
123
+ const u = new URL(h.href, p.finalUrl),
124
+ homes = [origin, p.finalUrl].filter(Boolean).map(o => new URL(o)),
125
+ exact = homes.some(o => o.origin === u.origin);
126
+ const variant = !exact && /^https?:$/.test(u.protocol) && homes.some(o => bareHost(o) === bareHost(u)),
127
+ ours = exact || variant;
128
+ return [
129
+ {
130
+ lang: h.lang.toLowerCase(),
131
+ href: u.href,
132
+ raw: h.href,
133
+ ours,
134
+ variant,
135
+ path: pathKey(u),
136
+ where: ours ? pathKey(u) : u.href,
137
+ },
138
+ ];
139
+ } catch {
140
+ return [];
141
+ }
142
+ });
143
+
144
+ export function checkHreflang(pages, { add, canonicalFor, statusOf, origin }) {
145
+ const byPath = new Map(pages.map(p => [pathKey(new URL(p.finalUrl)), p]));
146
+ for (const p of pages) {
147
+ if (!p.hreflang?.length) continue;
148
+ const u = p.finalUrl,
149
+ self = pathKey(new URL(u)),
150
+ entries = entriesOf(p, origin);
151
+ for (const h of p.hreflang) if (!validCode(h.lang)) add("hreflang-invalid-code", u, h.lang);
152
+ if (!entries.some(e => e.ours && e.path === self)) add("hreflang-no-self", u);
153
+ if (!entries.some(e => e.lang === "x-default")) add("hreflang-no-xdefault", u);
154
+ for (const e of entries) {
155
+ if (e.variant) {
156
+ add(
157
+ "hreflang-bad-target",
158
+ u,
159
+ `${e.lang} → ${e.href} (this site at another address, ${new URL(e.href).origin}; its pages are at ${origin})`,
160
+ );
161
+ continue;
162
+ }
163
+ if (!e.ours || e.path === self) continue;
164
+ const t = byPath.get(e.path);
165
+ if (!t) {
166
+ const s = statusOf(e.href);
167
+ if (s !== undefined && s !== 200) add("hreflang-bad-target", u, `${e.lang} → ${e.href} (status ${s})`);
168
+ continue;
169
+ }
170
+ const c = canonicalFor(t);
171
+ const why =
172
+ t.status !== 200
173
+ ? `status ${t.status}`
174
+ : t.noindex
175
+ ? "noindex"
176
+ : c && pathKey(new URL(c)) !== e.path
177
+ ? `canonical is ${c}`
178
+ : null;
179
+ if (why) {
180
+ add("hreflang-bad-target", u, `${e.lang} → ${e.href} (${why})`);
181
+ continue;
182
+ }
183
+ if (!entriesOf(t, origin).some(b => b.ours && b.path === self))
184
+ add("hreflang-no-return", u, `${e.lang} → ${e.href} doesn't link back`);
185
+ }
186
+ }
187
+ }
188
+
189
+ // hreflang targets on other sites, as target URL -> [{ url, lang }] of the pages listing them. The crawler visits them
190
+ // only with --outside and --hreflang-other-sites.
191
+ export function otherSiteTargets(pages, origin) {
192
+ const out = new Map();
193
+ for (const p of pages)
194
+ for (const e of entriesOf(p, origin))
195
+ if (!e.ours) (out.get(e.href) || out.set(e.href, []).get(e.href)).push({ url: p.finalUrl, lang: e.lang });
196
+ return out;
197
+ }
198
+ // Whether hreflang names `back` by origin and path, trailing slashes aside; same maps the public origin onto the
199
+ // crawled one. Google ignores a pair without the return link.
200
+ export const linksBack = (hreflang, base, back, same = u => u) =>
201
+ hreflang.some(h => {
202
+ try {
203
+ const u = new URL(same(new URL(h.href, base).href)),
204
+ b = new URL(back);
205
+ return u.origin === b.origin && pathKey(u) === pathKey(b);
206
+ } catch {
207
+ return false;
208
+ }
209
+ });
210
+
211
+ // The Link header form Google documents:
212
+ // Link: <url1>; rel="alternate"; hreflang="de", <url2>; rel="alternate"; hreflang="fr"
213
+ const LINK = /<([^>]*)>((?:\s*;\s*[\w*.-]+\s*(?:=\s*(?:"[^"]*"|[^\s;,]*))?)*)/g,
214
+ PARAM = /;\s*([\w*.-]+)\s*(?:=\s*(?:"([^"]*)"|([^\s;,]*)))?/g;
215
+ export const linkHreflang = header =>
216
+ [...(header || "").matchAll(LINK)].flatMap(([, href, params]) => {
217
+ const p = Object.fromEntries([...params.matchAll(PARAM)].map(m => [m[1].toLowerCase(), m[2] ?? m[3] ?? ""]));
218
+ return p.rel?.toLowerCase().split(/\s+/).includes("alternate") && p.hreflang
219
+ ? [{ lang: p.hreflang, href: href.trim() }]
220
+ : [];
221
+ });
222
+
223
+ // One page's hreflang merged from { html, header, sitemap }, one entry per language and target, and the first conflict
224
+ // between sources. same maps an absolute URL onto the one it's compared as (the public origin onto the crawled one).
225
+ const SOURCE = { html: "the HTML", header: "the Link header", sitemap: "the sitemap" };
226
+ export function mergeHreflang(sources, base, same = u => u) {
227
+ const at = h => {
228
+ try {
229
+ const u = new URL(same(new URL(h.href, base).href));
230
+ return `${u.origin}${pathKey(u)}${u.search}`;
231
+ } catch {
232
+ return h.href;
233
+ }
234
+ };
235
+ const lists = Object.entries(sources)
236
+ .filter(([, l]) => l?.length)
237
+ .map(
238
+ ([s, l]) =>
239
+ /** @type {[string, Map<string, any>]} */ ([
240
+ s,
241
+ new Map(
242
+ l.map(h => {
243
+ const e = { h, lang: h.lang.toLowerCase(), url: at(h) };
244
+ return [`${e.lang} ${e.url}`, e];
245
+ }),
246
+ ),
247
+ ]),
248
+ );
249
+ const merged = new Map();
250
+ for (const [, l] of lists) for (const [k, e] of l) if (!merged.has(k)) merged.set(k, e.h);
251
+ // Google combines the sources, so an entry missing from one isn't a conflict. A conflict is the same code at another
252
+ // URL, or the same URL under another language (x-default may share a version's URL).
253
+ let disagree = null;
254
+ for (const [i, [a, la]] of lists.entries())
255
+ for (const [b, lb] of lists.slice(i + 1)) {
256
+ const theirs = [...lb].filter(([k]) => !la.has(k)).map(([, o]) => o);
257
+ for (const [k, e] of la) {
258
+ const o =
259
+ !disagree &&
260
+ !lb.has(k) &&
261
+ theirs.find(o => o.lang === e.lang || (o.url === e.url && e.lang !== "x-default" && o.lang !== "x-default"));
262
+ if (o) disagree = `${SOURCE[a]} lists ${e.h.lang} → ${e.h.href}, ${SOURCE[b]} lists ${o.h.lang} → ${o.h.href}`;
263
+ }
264
+ }
265
+ return { hreflang: [...merged.values()], hreflangDisagree: disagree };
266
+ }
267
+
268
+ // The Translate widget (its loader, or the goog-te-* classes it adds, which sites style or hide) and schema inLanguage
269
+ // values (text, or a Language's alternateName).
270
+ export const languageFeatures = (html, nodes) => ({
271
+ translateWidget: /translate\.google\.[a-z.]+\/translate_a\/element\.js|\bgoog-te-[a-z]/i.test(html),
272
+ inLanguage: [
273
+ ...new Set(
274
+ nodes
275
+ .flatMap(n => [].concat(n.inLanguage || []))
276
+ .map(l => (typeof l === "string" ? l : l?.alternateName))
277
+ .filter(l => typeof l === "string")
278
+ .map(l => l.trim()),
279
+ ),
280
+ ],
281
+ });
282
+
283
+ // A BCP 47 tag as HTML lang takes it: a 2–3 letter language (or x-/i- private and grandfathered tags), then subtags.
284
+ const LANG_TAG = /^(?:[a-z]{2,3}|[xi])(?:-[a-z\d]{1,8})*$/i;
285
+ const ALIAS = { nb: "no", nn: "no", iw: "he", in: "id", ji: "yi" }; // Norwegian's three codes, and retired ones
286
+ const primary = c => {
287
+ const l = c.toLowerCase().split("-")[0];
288
+ return ALIAS[l] || l;
289
+ };
290
+ const flat = s => (s || "").toLowerCase().replace(/\s+/g, " ").trim();
291
+ const words = s =>
292
+ flat(s)
293
+ .split(/[^\p{L}\p{N}]+/u)
294
+ .filter(Boolean);
295
+ const dice = (a, b) => {
296
+ if (!a || !b) return 0;
297
+ let n = 0;
298
+ for (const x of a) if (b.has(x)) n++;
299
+ return (2 * n) / (a.size + b.size);
300
+ };
301
+
302
+ // pages: the indexable crawled pages, with merged hreflang, lang, title, shingles (5-word sets of the main text),
303
+ // hreflangDisagree, translateWidget and inLanguage.
304
+ export function checkLanguages(pages, { add, origin }) {
305
+ const byPath = new Map(pages.map(p => [pathKey(new URL(p.finalUrl)), p]));
306
+ const ent = new Map(pages.map(p => [p, entriesOf(p, origin).filter(e => e.lang !== "x-default")]));
307
+ const listedAs = new Map(); // path -> the codes any page lists it under
308
+ for (const es of ent.values())
309
+ for (const e of es) if (e.ours) (listedAs.get(e.path) || listedAs.set(e.path, new Set()).get(e.path)).add(e.lang);
310
+ // Words that name the page: no model numbers (words with digits) and no brand words (in over half the titles), so a
311
+ // product name kept in every language isn't counted.
312
+ const titled = pages.filter(p => p.title),
313
+ inTitles = new Map();
314
+ for (const p of titled) for (const w of new Set(words(p.title))) inTitles.set(w, (inTitles.get(w) || 0) + 1);
315
+ const naming = t => words(t).filter(w => !/\p{N}/u.test(w) && !(inTitles.get(w) > titled.length / 2)).length;
316
+ const pairs = new Set(),
317
+ langs = new Set();
318
+ // Of two versions sharing their text, the original is the x-default one, else the one in the home page's language,
319
+ // else the one closer to the home page, else the first by URL; the other is the copy. Never the order pages finished
320
+ // loading in, which changes from run to run.
321
+ const xDefault = new Set(
322
+ pages.flatMap(p =>
323
+ entriesOf(p, origin)
324
+ .filter(e => e.lang === "x-default" && e.ours)
325
+ .map(e => e.path),
326
+ ),
327
+ );
328
+ const home = byPath.get("/"),
329
+ homeLang = home?.lang && LANG_TAG.test(home.lang) ? primary(home.lang) : null;
330
+ const rank = (q, l) => (xDefault.has(pathKey(new URL(q.finalUrl))) ? 2 : l === homeLang ? 1 : 0);
331
+ for (const p of pages) {
332
+ const u = p.finalUrl,
333
+ self = pathKey(new URL(u)),
334
+ es = ent.get(p);
335
+ if (p.hreflangDisagree) add("hreflang-sources-disagree", u, p.hreflangDisagree);
336
+ const lang = p.lang && LANG_TAG.test(p.lang) ? primary(p.lang) : null;
337
+ if (lang) langs.add(lang);
338
+ if (p.lang && !lang) add("lang-invalid", u, `lang="${p.lang}"`);
339
+ const codes = [...(listedAs.get(self) || [])];
340
+ if (lang && codes.length && !codes.some(c => primary(c) === lang))
341
+ add("lang-hreflang-mismatch", u, `<html lang="${p.lang}">, hreflang lists it as ${codes.join(", ")}`);
342
+ const schema = (p.inLanguage || []).filter(c => LANG_TAG.test(c));
343
+ if (lang && schema.length && !schema.some(c => primary(c) === lang))
344
+ add(
345
+ "inlanguage-mismatch",
346
+ u,
347
+ `<html lang="${p.lang}">, schema inLanguage ${schema.map(c => `"${c}"`).join(", ")}`,
348
+ );
349
+ // Versions the listed pages know that this one lists under neither code nor URL; and versions in different
350
+ // languages sharing a title or main text (en-GB and en-US may share theirs, so only the primary language counts).
351
+ const selfCode = es.find(e => e.ours && e.path === self)?.lang,
352
+ mine = selfCode ? primary(selfCode) : lang,
353
+ missing = new Map();
354
+ for (const e of es) {
355
+ const t = e.ours && e.path !== self && byPath.get(e.path);
356
+ if (!t) continue;
357
+ // A version on the site counts only if crawled and indexable, which is all pages holds. One on another host
358
+ // can't be checked, so it counts.
359
+ for (const f of ent.get(t))
360
+ if (
361
+ (!f.ours || (f.path !== self && byPath.has(f.path))) &&
362
+ !missing.has(f.lang) &&
363
+ !es.some(x => x.lang === f.lang || x.where === f.where)
364
+ )
365
+ missing.set(f.lang, `${f.lang} → ${f.raw} (listed by ${t.finalUrl})`);
366
+ const theirs = primary(e.lang),
367
+ pair = [u, t.finalUrl].sort().join(" ");
368
+ if (!mine || mine === theirs || pairs.has(pair)) continue;
369
+ pairs.add(pair);
370
+ // Conservative: 80% of the main text, or the same title of five naming words or more and half the main text.
371
+ const title = flat(p.title) && flat(p.title) === flat(t.title) && naming(p.title) >= 5,
372
+ same = dice(p.shingles, t.shingles);
373
+ if (same >= 0.8 || (title && same >= 0.5)) {
374
+ const pFirst =
375
+ rank(p, mine) - rank(t, theirs) ||
376
+ (t.depth ?? Infinity) - (p.depth ?? Infinity) ||
377
+ (u < t.finalUrl ? 1 : -1),
378
+ [copy, copyLang, orig, origLang] = pFirst > 0 ? [t, theirs, p, mine] : [p, mine, t, theirs];
379
+ add(
380
+ "untranslated-copy",
381
+ copy.finalUrl,
382
+ `${copy.finalUrl} (${copyLang}) and ${orig.finalUrl} (${origLang}) ${title ? `have the same title “${copy.title}” and ` : ""}share ${Math.round(same * 100)}% of their main text`,
383
+ );
384
+ }
385
+ }
386
+ if (missing.size) add("hreflang-missing-version", u, [...missing.values()].join("; "));
387
+ }
388
+ // The widget as the site's only translation: every page is in one language, and none lists versions in two.
389
+ const widget = pages.filter(p => p.translateWidget);
390
+ if (widget.length && langs.size <= 1 && ![...ent.values()].some(es => new Set(es.map(e => primary(e.lang))).size > 1))
391
+ add(
392
+ "translate-widget",
393
+ widget[0].finalUrl,
394
+ `on ${widget.length} page(s); every page is in one language and none lists language versions with hreflang`,
395
+ );
396
+ }
@@ -0,0 +1,227 @@
1
+ // @ts-check
2
+ // Duplicate analytics tags, exposed secret keys, CSS-hidden links and app link files. Every cut-off is a local choice.
3
+ // HTML is read with regexes, as in the crawler; swap in a real parser if a site breaks them.
4
+
5
+ export const HIDDEN_MIN = 3; // links to other sites hidden on one page before it's flagged
6
+ export const PDF_PAGES = 3; // pages linking one PDF before the report lists it
7
+ // Caps on the site's script files read for secret keys, so huge bundles can't stall the crawl.
8
+ export const JS_CAPS = { files: 50, each: 5 * 1024 * 1024, all: 50 * 1024 * 1024 };
9
+
10
+ export const CHECKS = {
11
+ // A Google tag configured twice may duplicate data unless "Ignore duplicate instances" is on. Google also advises
12
+ // against redundant tag managers, but doesn't say what a second copy of a container does.
13
+ // https://support.google.com/analytics/answer/12015327
14
+ // https://developers.google.com/tag-platform/devguides/prerequisites
15
+ "analytics-tag-twice": [
16
+ "LAUNCH-04",
17
+ "low",
18
+ n => `${n} page(s) set up the same Google Analytics or Tag Manager ID twice`,
19
+ "These pages set up the same Google Analytics 4 measurement ID (G-…) in two separate scripts, or load the same Google Tag Manager container (GTM-…) twice. Google's Analytics help says the same Google tag set up two or more times on a page \"may cause duplicate data or mixed settings\": visits and events can be counted twice, which inflates the numbers you see and import. For Tag Manager, Google's tag guide says to avoid installing redundant tags or tag management systems. It's fine if the Google tag's setting \"Ignore duplicate instances of on-page configuration\" is on, which Google turns on when two tags are combined: the crawler can't see that setting, nor tags added inside Tag Manager.",
20
+ "Keep one copy. A theme or plugin often adds the tag while it's also pasted into the layout or added through Tag Manager, so remove the others. Then open Google Analytics' Realtime report and check that one visit shows one page view.",
21
+ ],
22
+ // Key prefixes each provider documents as secret, and RFC 7468's private-key labels.
23
+ // https://docs.stripe.com/keys
24
+ // https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/about-authentication-to-github
25
+ // https://docs.slack.dev/authentication/tokens
26
+ // https://www.rfc-editor.org/rfc/rfc7468
27
+ "secret-key-exposed": [
28
+ "TRUST-01",
29
+ "high",
30
+ n => `${n} page(s) send a secret key to every visitor`,
31
+ `The HTML of these pages, or a script file on your site that they load, holds a key that its provider says must stay secret. Anyone who opens the page source or the script can copy it and act as you: take payments, read data or post messages, depending on the key. A key in a script file usually got there when the site was built, from a setting meant for the server. Only key formats that are always secret are flagged: Stripe live secret and restricted keys (sk_live_, rk_live_), GitHub tokens (ghp_, github_pat_, gho_, ghu_, ghs_, ghr_), Slack tokens (xoxb-, xoxp-, xapp-, xwfp-) and private-key blocks. Keys made for browsers, such as Google and Firebase web API keys and Stripe publishable keys (pk_live_), aren't. Only script files on your own site are read, never other sites', up to our own limits of ${JS_CAPS.files} files, ${JS_CAPS.each / 1048576} MB each and ${JS_CAPS.all / 1048576} MB in all. The evidence shows only the key's type and first characters.`,
32
+ "Treat it as an emergency. First revoke the key with its provider (Stripe's API keys page, GitHub's token settings, the Slack app's settings) and make a new one: taking it off the page isn't enough, because copies and caches may already exist. Then keep the new key on the server only, read from an environment variable, and check that the build doesn't copy server settings into the page.",
33
+ ],
34
+ // Google's spam policies count CSS-hidden links as content injection, and allow menus, tabs and panels that show and
35
+ // hide content.
36
+ // https://developers.google.com/search/docs/essentials/spam-policies
37
+ // https://web.dev/articles/hacked
38
+ "hidden-links": [
39
+ "CONTENT-11",
40
+ "low",
41
+ n => `${n} page(s) hide links to other sites with CSS`,
42
+ `These pages hold ${HIDDEN_MIN} or more links to other sites inside an element hidden by its own style: display:none, visibility:hidden, a font size or opacity of 0, or moved far off the screen (${HIDDEN_MIN} is our own cut-off). Google's spam policies name hidden links added with CSS as one way hackers inject content into a site, and hidden links meant for search engines break Google's rules whoever added them. This is only a possible issue: it's fine if it's a menu, tab or panel that visitors can open. The page's topic plays no part, only where the links are.`,
43
+ "Look at the links in the page source. If you didn't add them, the site may have been hacked: check Search Console's Security issues report and follow Google's guide at web.dev/articles/hacked, remove the code, then find how it got in (an old plugin or theme, a weak password) and update everything. If it's your own menu or panel, nothing needs to change.",
44
+ ],
45
+ // From otherReviewed and onlineOnly in schema.mjs, which cite their sources.
46
+ "review-target-conflict": [
47
+ "SCHEMA-01",
48
+ "low",
49
+ n => `${n} page(s) have a nested review that names a different item`,
50
+ "A review or rating here sits inside an item, through its review or aggregateRating property, but also names a different item in itemReviewed. Google's review snippet guide says to leave itemReviewed out of a nested review, as the item it sits in is the one reviewed, and since 12 Nov 2025 it asks sites not to say what's reviewed in more than one way. With two answers Google can't tell which item the rating is for, so the stars may not show.",
51
+ "Remove itemReviewed from the nested review or rating. If the review really is about another item, move it out into its own Review that names that item in itemReviewed.",
52
+ ],
53
+ // low: the only cost is that the stars don't show. The rule is cited at schema.mjs's reviewEventProblems.
54
+ // https://developers.google.com/search/docs/appearance/structured-data/review-snippet
55
+ "rating-self-serving": [
56
+ "SCHEMA-04",
57
+ "low",
58
+ n => `${n} page(s) rate the site's own business in its schema`,
59
+ "These pages mark up a rating or review of the site's own business: an aggregateRating or review on its Organization or LocalBusiness node, or a Review that names it in itemReviewed. Google's review snippet guide says that when a business controls the reviews about itself, its pages that use LocalBusiness or any other Organization structured data are \"ineligible for star review feature\", whether the reviews sit in the markup or come from an embedded widget such as Google or Facebook reviews. So these stars never show in Google. The site's own business is the business at the top of the home page's schema, found on other pages by its @id or name.",
60
+ "Take the rating and the reviews out of the business's schema; the reviews themselves can stay on the page as text. Stars can still show for what the business sells, such as a Product rated by real reviews shown on its page (SCHEMA-04). If this site collects reviews of other businesses, check that the business rated here really is another one: then nothing needs to change.",
61
+ ],
62
+ "event-online": [
63
+ "SCHEMA-05",
64
+ "low",
65
+ n => `${n} page(s) mark up online-only events`,
66
+ "These events are online only: their eventAttendanceMode is OnlineEventAttendanceMode, or their only location is a VirtualLocation. On 5 Jun 2025 Google removed the online event properties from its event guide: events must be open to the public and held at a physical location, and \"virtual experiences that have no real-world component aren't supported\". So these events can't show in Google's event results. The markup does no harm, and other search engines may still read it.",
67
+ "Keep it knowingly or remove it, but don't expect Google event results for online-only events. An event that also has a real venue should say MixedEventAttendanceMode and give a Place with an address.",
68
+ ],
69
+ };
70
+
71
+ const attr = (tag, name) => {
72
+ const m = new RegExp(`\\s${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s"'>]+))`, "i").exec(tag);
73
+ return m ? (m[1] ?? m[2] ?? m[3]) : null;
74
+ };
75
+ const noComments = h => h.replace(/<!--[\s\S]*?-->/g, " ");
76
+ const JS = /^((text|application)\/(x-)?(java|ecma)script|module)?$/i;
77
+
78
+ // ---------- the same analytics ID twice (LAUNCH-04) ----------
79
+ // IDs set up per JavaScript <script>: a GA4 gtag('config', …) ID, or a Tag Manager container in its snippet or a
80
+ // gtm.js?id= src. An ID counts once per element, so a second config call there (a route change) isn't a copy, and
81
+ // Tag Manager's <noscript> iframe is its own second half.
82
+ const CONFIG = /\bgtag\s*\(\s*["']config["']\s*,\s*["'](G-[A-Z0-9]{4,})["']/g,
83
+ CONTAINER = /\b(GTM-[A-Z0-9]{4,})\b/g;
84
+ export function analyticsTwice(html) {
85
+ const seen = new Map();
86
+ for (const [, a, js] of noComments(html).matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script\s*>/gi)) {
87
+ if (!JS.test((attr(a, "type") || "").trim())) continue;
88
+ const ids = new Set([...js.matchAll(CONFIG)].map(m => m[1]));
89
+ const src = attr(a, "src") || "";
90
+ if (/googletagmanager\.com\/gtm\.js/i.test(src)) for (const [, id] of src.matchAll(CONTAINER)) ids.add(id);
91
+ if (/googletagmanager\.com\/gtm\.js/i.test(js)) for (const [, id] of js.matchAll(CONTAINER)) ids.add(id);
92
+ for (const id of ids) seen.set(id, (seen.get(id) || 0) + 1);
93
+ }
94
+ return [...seen]
95
+ .filter(([, n]) => n > 1)
96
+ .map(([id, n]) => (id.startsWith("GTM-") ? `${id} loaded ${n} times` : `${id} set up in ${n} scripts`));
97
+ }
98
+
99
+ // ---------- secret keys in the HTML and the site's own script files (TRUST-01) ----------
100
+ // Formats documented as secret (sources at secret-key-exposed). Keys made for browsers are left out on purpose: Google
101
+ // and Firebase API keys, Firebase web config, Stripe publishable keys. So are Stripe test keys, which tutorials show
102
+ // and which can't move money, and Stripe organization keys, whose live form isn't documented.
103
+ // https://firebase.google.com/docs/projects/api-keys
104
+ const KEYS = [
105
+ ["a private key", /-----BEGIN ((?:[A-Z0-9]+ )*PRIVATE KEY(?: BLOCK)?)-----([\s\S]{0,12000}?)-----END \1-----/g],
106
+ ["a Stripe live secret key", /\bsk_live_[A-Za-z0-9]{20,}/g, true],
107
+ ["a Stripe live restricted key", /\brk_live_[A-Za-z0-9]{20,}/g, true],
108
+ ["a GitHub token", /\b(?:gh[pousr]_[A-Za-z0-9]{30,}|github_pat_[A-Za-z0-9_]{40,})/g, true],
109
+ ["a Slack token", /\b(?:xox[bp]|xapp|xwfp|xoxe\.xox[bp]|xoxe\.xapp)-[A-Za-z0-9-]{20,}/g],
110
+ ];
111
+ const PREFIX = /^(?:[sr]k_live_|gh[pousr]_|github_pat_|xoxe\.(?:xox[bp]|xapp)-|xox[bp]-|xapp-|xwfp-)/;
112
+ // Rules out placeholders such as sk_live_xxxx or ghp_YOUR_TOKEN; base62 keys (bothCases) need both letter cases.
113
+ // Shape only: add GitHub's token checksum if made-up keys that look real get flagged.
114
+ const realKey = (tail, bothCases) =>
115
+ /\d/.test(tail) &&
116
+ /[a-z]/i.test(tail) &&
117
+ new Set(tail).size >= 10 &&
118
+ (!bothCases || (/[a-z]/.test(tail) && /[A-Z]/.test(tail)));
119
+ /** Secret keys in HTML or script text as { label, shown, raw }; shown is the type prefix and first 4 characters, or
120
+ * a key block's label. */
121
+ export function secretsIn(html) {
122
+ const out = [];
123
+ for (const [label, re, bothCases] of KEYS)
124
+ for (const m of html.matchAll(re)) {
125
+ if (label === "a private key") {
126
+ // A real key block holds 60 or more base64 characters; a shortened sample doesn't.
127
+ const body = m[2].replace(/\\[nr]/g, "\n").replace(/^[\w-]+:.*$/gm, "");
128
+ if (/\.\.\.|…/.test(body) || (body.match(/[A-Za-z0-9+/]/g) || []).length < 60) continue;
129
+ out.push({ label, shown: `BEGIN ${m[1]}`, raw: m[0] });
130
+ continue;
131
+ }
132
+ const prefix = PREFIX.exec(m[0])?.[0] ?? "",
133
+ tail = m[0].slice(prefix.length);
134
+ if (realKey(tail, bothCases)) out.push({ label, shown: `${prefix}${tail.slice(0, 4)}…`, raw: m[0] });
135
+ }
136
+ return out;
137
+ }
138
+ /** The text with each secret key secretsIn finds replaced by its shown form. */
139
+ export const maskKeys = s => secretsIn(s).reduce((t, k) => t.split(k.raw).join(k.shown), s);
140
+
141
+ // ---------- links hidden with CSS (CONTENT-11) ----------
142
+ // Hidden by the element's own style; screen-reader-only text moves far less than -1000px. Classes aren't read: menus
143
+ // hidden by a class are the usual, honest case.
144
+ const HIDDEN =
145
+ /(?:^|;)\s*(?:display\s*:\s*none|visibility\s*:\s*hidden|font-size\s*:\s*0(?:px|em|rem|pt|%)?(?![.\d])|opacity\s*:\s*0(?:\.0*)?(?![.\d])|(?:left|top|text-indent|margin-left)\s*:\s*-\d{4,}(?:\.\d+)?px)/i;
146
+ const ABS = /^https?:\/\//i;
147
+ // Absolute hrefs of hidden links and links inside hidden elements; the crawler keeps other sites' only. An element ends
148
+ // at the first end tag of its name, so a nested one of the same name undercounts, never overcounts; balance the tags
149
+ // if that misses real cases.
150
+ export function hiddenLinks(body) {
151
+ const out = [];
152
+ let until = 0;
153
+ for (const m of body.matchAll(/<([a-z][\w-]*)\b([^>]*)>/gi)) {
154
+ if (m.index < until || !HIDDEN.test(attr(m[2], "style") || "")) continue;
155
+ const start = m.index + m[0].length,
156
+ close = body.slice(start).search(new RegExp(`</${m[1]}\\s*>`, "i"));
157
+ if (close < 0) continue;
158
+ until = start + close;
159
+ const hrefs =
160
+ m[1].toLowerCase() === "a"
161
+ ? [attr(m[2], "href")]
162
+ : [...body.slice(start, until).matchAll(/<a\b[^>]*>/gi)].map(x => attr(x[0], "href"));
163
+ out.push(...hrefs.map(h => (h || "").trim().replace(/&amp;/g, "&")).filter(h => ABS.test(h)));
164
+ }
165
+ return out;
166
+ }
167
+
168
+ // ---------- app link files ----------
169
+ // A page promotes an app with a Google Play or App Store link, Apple's Smart App Banner tag or an android-app://
170
+ // alternate. Deep links don't change how Search shows pages.
171
+ // https://developers.google.com/search/blog/2025/05/app-deep-links
172
+ export function appPromo(html) {
173
+ const h = noComments(html);
174
+ return {
175
+ android:
176
+ /\bhref\s*=\s*["']?https?:\/\/play\.google\.com\/store\/apps\/details\?/i.test(h) ||
177
+ /<link\b[^>]*\bhref\s*=\s*["']?android-app:\/\//i.test(h),
178
+ ios:
179
+ /\bhref\s*=\s*["']?https?:\/\/(?:apps|itunes)\.apple\.com\/(?:[a-z]{2}(?:-[a-z]{2})?\/)?app\//i.test(h) ||
180
+ /<meta\b[^>]*\bname\s*=\s*["']?apple-itunes-app\b/i.test(h),
181
+ };
182
+ }
183
+ // Android needs assetlinks.json as application/json with no redirects. Apple's file must not redirect either and lists
184
+ // app IDs in applinks details (appID is the older form); Apple names no content type.
185
+ // https://developer.android.com/training/app-links/configure-assetlinks
186
+ // https://developer.apple.com/documentation/xcode/supporting-associated-domains
187
+ export const APP_FILES = { android: "/.well-known/assetlinks.json", ios: "/.well-known/apple-app-site-association" };
188
+ const handlesUrls = s =>
189
+ [].concat(s?.relation ?? []).includes("delegate_permission/common.handle_all_urls") &&
190
+ s?.target?.namespace === "android_app" &&
191
+ typeof s.target.package_name === "string" &&
192
+ Array.isArray(s.target.sha256_cert_fingerprints) &&
193
+ s.target.sha256_cert_fingerprints.length > 0;
194
+ const appIds = d => (Array.isArray(d?.appIDs) && d.appIDs.length > 0) || typeof d?.appID === "string";
195
+ // null when the file is fine, else { missing, problem }. A missing file (404, 410 or a web page) is fine for an app
196
+ // that doesn't open the site's links.
197
+ export function appFile(kind, { status, type, body }) {
198
+ const os = kind === "android" ? "Android" : "Apple";
199
+ if (status === 404 || status === 410) return { missing: true, problem: `isn't there (${status})` };
200
+ if (status >= 300 && status < 400)
201
+ return { missing: false, problem: `redirects (${status}); ${os} reads the file only when it's served directly` };
202
+ if (status !== 200) return { missing: false, problem: `answers ${status || "nothing"}` };
203
+ if (/^\s*</.test(body)) return { missing: true, problem: "isn't there: the server sends a web page instead" };
204
+ let j;
205
+ try {
206
+ j = JSON.parse(body.replace(/^/, ""));
207
+ } catch {
208
+ return { missing: false, problem: "isn't valid JSON" };
209
+ }
210
+ if (kind === "android") {
211
+ if (!/^application\/json\b/i.test(type.trim()))
212
+ return {
213
+ missing: false,
214
+ problem: `is sent as ${type.split(";")[0].trim() || "no content type"}; Android needs application/json`,
215
+ };
216
+ return Array.isArray(j) && j.some(handlesUrls)
217
+ ? null
218
+ : {
219
+ missing: false,
220
+ problem:
221
+ "has no statement for an Android app (the relation delegate_permission/common.handle_all_urls, with a package_name and sha256_cert_fingerprints)",
222
+ };
223
+ }
224
+ return j && typeof j === "object" && Array.isArray(j.applinks?.details) && j.applinks.details.some(appIds)
225
+ ? null
226
+ : { missing: false, problem: "has no applinks details with appIDs, which universal links need" };
227
+ }