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
@@ -1,173 +1,530 @@
1
1
  #!/usr/bin/env node
2
- // content-scan.mjs: audits content data (JSON, CSV or a Markdown folder) before it becomes pages.
3
- // Finds templated copy, reused FAQs, missing required fields, unpublished items, bad title/description
4
- // lengths, placeholders and banned/unconfirmed claims. Read-only, no dependencies, Node 20+.
5
- //
6
- // node content-scan.mjs --in content.json [--items pages] JSON array, {type: [...]}, or {id: {...}}
7
- // node content-scan.mjs --csv sheet.csv first row = headers
8
- // node content-scan.mjs --md content/blog .md/.mdx files with front matter
9
- //
10
- // Field options (dot paths allowed, comma lists where noted):
11
- // --id slug --url "/blog/{slug}/" --title title --desc description
12
- // --text intro,body fields compared for near-duplicate copy (default: longest text field)
13
- // --faq faqs array of strings or {q|question|name, a|answer}
14
- // --publish published truthy = live (yes/true/1/live/published)
15
- // --group service compare duplicates only within the same group
16
- // --strip "Antioch|Concord" words removed before comparing (e.g. city names); the record's own id/title words are removed too
17
- // --required title,localProof fields that must be non-empty
18
- // --banned regex --verify regex --threshold 0.5 --out seo-audit/content-scan.json
19
- //
20
- // For content in TypeScript modules or a CMS, dump it to JSON first, e.g. the way the project runs its own scripts:
21
- // npx tsx -e "import('./src/lib/content.ts').then(m => console.log(JSON.stringify(m.getAllPages())))" > seo-audit/content.json
2
+ // @ts-check
3
+ // Audits content data (JSON, CSV or a Markdown folder) before it becomes pages.
22
4
 
23
5
  import { readFileSync, readdirSync, statSync, mkdirSync, writeFileSync } from "node:fs";
6
+ import { parseCsv } from "./lib/csv.mjs";
24
7
  import { join, dirname, resolve, extname, basename } from "node:path";
8
+ import {
9
+ titleWidth,
10
+ widthText,
11
+ templatedDescs,
12
+ templatedShare,
13
+ sectionOf,
14
+ claimsIn,
15
+ invisibleChar,
16
+ } from "./checks/content.mjs";
17
+ import { isMain } from "./lib/is-main.mjs";
18
+ import { parseArgs } from "./lib/args.mjs";
19
+ import { Fail, runMain } from "./lib/cli.mjs";
20
+ import { createFindings } from "./lib/findings.mjs";
25
21
 
26
- const args = {};
27
- for (let i = 2; i < process.argv.length; i++) {
28
- const a = process.argv[i]; if (!a.startsWith("--")) continue;
29
- args[a.slice(2)] = process.argv[i + 1] && !process.argv[i + 1].startsWith("--") ? process.argv[++i] : true;
30
- }
31
- if (!args.in && !args.csv && !args.md) { console.error("Usage: node content-scan.mjs --in content.json | --csv file.csv | --md dir [--id] [--url] [--title] [--desc] [--text] [--faq] [--publish] [--group] [--strip] [--required] [--banned] [--verify] [--threshold 0.5] [--out file]"); process.exit(2); }
32
- const list = v => typeof v === "string" ? v.split(",").map(s => s.trim()).filter(Boolean) : [];
33
- const get = (o, path) => path.split(".").reduce((x, k) => (x == null ? undefined : x[k]), o);
34
- const OUT = resolve(typeof args.out === "string" ? args.out : "seo-audit/content-scan.json");
35
- const THRESH = Number(args.threshold || 0.5);
36
- const STRIP = typeof args.strip === "string" ? new RegExp(`\\b(${args.strip})\\b`, "gi") : null;
37
- const BANNED = typeof args.banned === "string" ? new RegExp(args.banned, "i") : null;
38
- const VERIFY = typeof args.verify === "string" ? new RegExp(args.verify, "i") : null;
39
- const PH = /\b[Ll]orem [Ii]psum\b|\bTODO\b|\bTBD\b|\{\{\s*[\w.]+\s*\}\}|\[(?:[A-Z][A-Z _]{2,29})\]|�|\b(?:We|You|They|It|Don|Can|Isn|Won|Doesn|Didn|That|There)\?(?:ve|re|s|t|ll|d)\b/;
22
+ const FLAGS = [
23
+ "in",
24
+ "csv",
25
+ "md",
26
+ "items",
27
+ "id",
28
+ "url",
29
+ "title",
30
+ "desc",
31
+ "text",
32
+ "faq",
33
+ "publish",
34
+ "group",
35
+ "strip",
36
+ "required",
37
+ "banned",
38
+ "verify",
39
+ "threshold",
40
+ "date",
41
+ "max-age",
42
+ "fail-on",
43
+ "out",
44
+ ];
45
+
46
+ const USAGE =
47
+ "Usage: node content-scan.mjs --in content.json | --csv file.csv | --md dir [--id] [--url] [--title] [--desc] [--text] [--faq] [--publish] [--group] [--strip] [--required] [--banned] [--verify] [--threshold 0.5] [--date field] [--max-age 12] [--fail-on checks] [--out file]";
48
+
49
+ function main(argv) {
50
+ const args = parseArgs(argv, { flags: FLAGS, positionals: 0, usage: USAGE });
51
+ if (!["in", "csv", "md"].some(k => typeof args[k] === "string")) throw new Fail(USAGE);
52
+ const list = v =>
53
+ typeof v === "string"
54
+ ? v
55
+ .split(",")
56
+ .map(s => s.trim())
57
+ .filter(Boolean)
58
+ : [];
59
+ const get = (o, path) => path.split(".").reduce((x, k) => (x == null ? undefined : x[k]), o);
60
+ const OUT = resolve(typeof args.out === "string" ? args.out : "seo-audit/content-scan.json");
61
+ const THRESH = Number(args.threshold || 0.5);
62
+ const regex = (flag, src, flags) => {
63
+ try {
64
+ return new RegExp(src, flags);
65
+ } catch (e) {
66
+ throw new Fail(`content-scan: --${flag} isn't a valid regular expression (${e.message}).`);
67
+ }
68
+ };
69
+ const STRIP = typeof args.strip === "string" ? regex("strip", `\\b(${args.strip})\\b`, "gi") : null;
70
+ const BANNED = typeof args.banned === "string" ? regex("banned", args.banned, "i") : null;
71
+ const VERIFY = typeof args.verify === "string" ? regex("verify", args.verify, "i") : null;
72
+ const MAX_AGE = Number(args["max-age"] || 12); // months: the far end of CONTENT-07's 6–12 month review cycle
73
+ const FAIL_ON = list(args["fail-on"]);
74
+ // Placeholders, plus mojibake: U+FFFD and curly apostrophes turned into "?" (We?re, Don?t).
75
+ const PH =
76
+ /\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/;
40
77
 
41
- // ---------- load ----------
42
- function parseCsv(txt) {
43
- const rows = []; let row = [], cell = "", q = false;
44
- for (let i = 0; i < txt.length; i++) {
45
- const c = txt[i];
46
- if (q) { if (c === '"' && txt[i + 1] === '"') { cell += '"'; i++; } else if (c === '"') q = false; else cell += c; continue; }
47
- if (c === '"') q = true; else if (c === ",") { row.push(cell); cell = ""; }
48
- else if (c === "\n" || c === "\r") { if (c === "\r" && txt[i + 1] === "\n") i++; row.push(cell); rows.push(row); row = []; cell = ""; }
49
- else cell += c;
78
+ function walk(d) {
79
+ return readdirSync(d).flatMap(f => {
80
+ const p = join(d, f);
81
+ return statSync(p).isDirectory() ? walk(p) : [p];
82
+ });
50
83
  }
51
- if (cell || row.length) { row.push(cell); rows.push(row); }
52
- const [head, ...body] = rows.filter(r => r.some(x => x.trim()));
53
- return body.map(r => Object.fromEntries(head.map((h, i) => [h.trim(), (r[i] ?? "").trim()])));
54
- }
55
- function walk(d) { return readdirSync(d).flatMap(f => { const p = join(d, f); return statSync(p).isDirectory() ? walk(p) : [p]; }); }
56
- function parseMd(file) {
57
- const raw = readFileSync(file, "utf8"); const rec = { _file: file, slug: basename(file, extname(file)) };
58
- const m = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/);
59
- const fm = m ? m[1] : "", body = m ? m[2] : raw;
60
- for (const line of fm.split(/\r?\n/)) { const k = line.match(/^([\w-]+):\s*(.*)$/); if (k) rec[k[1]] = k[2].replace(/^["']|["']$/g, ""); }
61
- rec.body = body; return rec;
62
- }
63
- let records = [], source = "";
64
- if (args.in) {
65
- source = args.in; let data = JSON.parse(readFileSync(args.in, "utf8"));
66
- if (typeof args.items === "string") data = get(data, args.items);
67
- if (Array.isArray(data)) records = data;
68
- else if (data && typeof data === "object") {
69
- const vals = Object.entries(data);
70
- records = vals.every(([, v]) => Array.isArray(v)) ? vals.flatMap(([k, v]) => v.map(r => ({ _type: k, ...r }))) : vals.map(([k, v]) => ({ _key: k, ...v }));
84
+ function parseMd(file) {
85
+ const raw = readFileSync(file, "utf8");
86
+ const rec = { _file: file, slug: basename(file, extname(file)) };
87
+ const m = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/);
88
+ const fm = m ? m[1] : "",
89
+ body = m ? m[2] : raw;
90
+ for (const line of fm.split(/\r?\n/)) {
91
+ const k = line.match(/^([\w-]+):\s*(.*)$/);
92
+ if (k) rec[k[1]] = k[2].replace(/^["']|["']$/g, "");
93
+ }
94
+ rec.body = body;
95
+ return rec;
71
96
  }
72
- } else if (args.csv) { source = args.csv; records = parseCsv(readFileSync(args.csv, "utf8")); }
73
- else { source = args.md; records = walk(args.md).filter(f => /\.mdx?$/.test(f)).map(parseMd); }
74
- records = records.filter(r => r && typeof r === "object");
97
+ let records = [],
98
+ source = "";
99
+ if (typeof args.in === "string") {
100
+ source = args.in;
101
+ let data;
102
+ const text = readFileSync(args.in, "utf8");
103
+ try {
104
+ data = JSON.parse(text);
105
+ } catch (e) {
106
+ throw new Fail(
107
+ `content-scan: ${args.in} isn't JSON (${e.message}). Dump the content as JSON first, or pass --csv or --md.`,
108
+ );
109
+ }
110
+ if (typeof args.items === "string") data = get(data, args.items);
111
+ if (Array.isArray(data)) records = data;
112
+ else if (data && typeof data === "object") {
113
+ const vals = Object.entries(data);
114
+ records = vals.every(([, v]) => Array.isArray(v))
115
+ ? vals.flatMap(([k, v]) => v.map(r => ({ _type: k, ...r })))
116
+ : vals.map(([k, v]) => ({ _key: k, ...v }));
117
+ }
118
+ } else if (typeof args.csv === "string") {
119
+ source = args.csv;
120
+ records = parseCsv(readFileSync(args.csv, "utf8"));
121
+ } else {
122
+ source = args.md;
123
+ records = walk(args.md)
124
+ .filter(f => /\.mdx?$/.test(f))
125
+ .map(parseMd);
126
+ }
127
+ records = records.filter(r => r && typeof r === "object");
75
128
 
76
- // ---------- helpers ----------
77
- const ID = typeof args.id === "string" ? args.id : null;
78
- const idOf = (r, i) => String((ID && get(r, ID)) ?? r.slug ?? r.id ?? r._key ?? r.title ?? `#${i + 1}`);
79
- const urlOf = (r, i) => typeof args.url === "string" ? args.url.replace(/\{([\w.]+)\}/g, (_, k) => get(r, k) ?? "") : idOf(r, i);
80
- const str = v => v == null ? "" : Array.isArray(v) ? v.map(str).join(" ") : typeof v === "object" ? Object.values(v).map(str).join(" ") : String(v);
81
- const norm = s => s.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ").trim();
82
- let textFields = list(args.text);
83
- if (!textFields.length && records.length) {
84
- const lens = {}; for (const r of records.slice(0, 50)) for (const [k, v] of Object.entries(r)) if (typeof v === "string") lens[k] = (lens[k] || 0) + v.length;
85
- const best = Object.entries(lens).sort((a, b) => b[1] - a[1])[0]; if (best) textFields = [best[0]];
86
- }
87
- const own = r => [ID && get(r, ID), r.slug, r.title, r.name, r.city, r.location].filter(Boolean).map(x => norm(String(x).replace(/-/g, " "))).filter(x => x.length > 2);
88
- function cleanText(r) {
89
- let t = norm(textFields.map(f => str(get(r, f))).join(" "));
90
- if (STRIP) t = t.replace(new RegExp(STRIP.source, "gi"), " ");
91
- for (const o of own(r)) t = t.split(o).join(" ");
92
- return t.replace(/\s+/g, " ").trim();
93
- }
94
- const shingles = t => { const w = t.split(" ").filter(Boolean); const s = new Set(); for (let i = 0; i + 5 <= w.length; i++) s.add(w.slice(i, i + 5).join(" ")); return s; };
95
- const isLive = v => /^(1|true|yes|y|live|published|publish)$/i.test(String(v ?? "").trim());
96
- function ctx(text, re) { const m = re.exec(text); if (!m) return null; const s = Math.max(0, m.index - 50), e = Math.min(text.length, m.index + m[0].length + 50); return `“${m[0]}” in: ${s ? "…" : ""}${text.slice(s, e)}${e < text.length ? "…" : ""}`; }
129
+ const ID = typeof args.id === "string" ? args.id : null;
130
+ const idOf = (r, i) => String((ID && get(r, ID)) ?? r.slug ?? r.id ?? r._key ?? r.title ?? `#${i + 1}`);
131
+ const urlOf = (r, i) =>
132
+ typeof args.url === "string" ? args.url.replace(/\{([\w.]+)\}/g, (_, k) => get(r, k) ?? "") : idOf(r, i);
133
+ const str = v =>
134
+ v == null
135
+ ? ""
136
+ : Array.isArray(v)
137
+ ? v.map(str).join(" ")
138
+ : typeof v === "object"
139
+ ? Object.values(v).map(str).join(" ")
140
+ : String(v);
141
+ const norm = s =>
142
+ s
143
+ .toLowerCase()
144
+ .replace(/[^\p{L}\p{N}]+/gu, " ")
145
+ .trim();
146
+ let textFields = list(args.text);
147
+ if (!textFields.length && records.length) {
148
+ const lens = {};
149
+ for (const r of records.slice(0, 50))
150
+ for (const [k, v] of Object.entries(r)) if (typeof v === "string") lens[k] = (lens[k] || 0) + v.length;
151
+ const best = Object.entries(lens).sort((a, b) => b[1] - a[1])[0];
152
+ if (best) textFields = [best[0]];
153
+ }
154
+ // A record's own name words are removed too, so a swapped city or product name can't hide templated copy.
155
+ const own = r =>
156
+ [ID && get(r, ID), r.slug, r.title, r.name, r.city, r.location]
157
+ .filter(Boolean)
158
+ .map(x => norm(String(x).replace(/-/g, " ")))
159
+ .filter(x => x.length > 2);
160
+ function cleanText(r) {
161
+ let t = norm(textFields.map(f => str(get(r, f))).join(" "));
162
+ if (STRIP) t = t.replace(new RegExp(STRIP.source, "gi"), " ");
163
+ for (const o of own(r)) t = t.split(o).join(" ");
164
+ return t.replace(/\s+/g, " ").trim();
165
+ }
166
+ const shingles = t => {
167
+ const w = t.split(" ").filter(Boolean);
168
+ const s = new Set();
169
+ for (let i = 0; i + 5 <= w.length; i++) s.add(w.slice(i, i + 5).join(" "));
170
+ return s;
171
+ };
172
+ const isLive = v => /^(1|true|yes|y|live|published|publish)$/i.test(String(v ?? "").trim());
173
+ function ctx(text, re) {
174
+ const m = re.exec(text);
175
+ if (!m) return null;
176
+ const s = Math.max(0, m.index - 50),
177
+ e = Math.min(text.length, m.index + m[0].length + 50);
178
+ return `“${m[0]}” in: ${s ? "…" : ""}${text.slice(s, e)}${e < text.length ? "…" : ""}`;
179
+ }
97
180
 
98
- // ---------- checks ----------
99
- const CHECKS = {
100
- "templated-text": ["CONTENT-04", "high", n => `${n} pair(s) of items share most of their copy`, "Items whose text differs only by a swapped name (city, product, tool) become doorway or scaled-content pages.", "Write specific copy per item, or merge and hold the items that can't be made unique."],
101
- "few-distinct-texts": ["CONTENT-04", "high", n => `Only ${n} distinct text(s) once names are removed`, "When hundreds of items collapse to a handful of texts after removing the swapped name, the pages are templates.", "Treat each template as one page's worth of content; add real per-item substance before publishing more."],
102
- "faq-reused": ["CONTENT-04", "medium", n => `${n} FAQ question(s) are reused across items`, "Identical FAQs on many pages add nothing unique.", "Write questions specific to each item; keep shared questions on one FAQ page."],
103
- "missing-field": ["CONTENT-05", "high", n => `${n} item(s) are missing required fields`, "Required fields (local proof, unique intro, author) are what make a page worth indexing.", "Fill the fields, or keep the item unpublished until they're filled."],
104
- "unpublished": ["CRAWL-11", "needs-decision", n => `${n} item(s) are marked unpublished`, "Unpublished items must not be routable, linked or in the sitemap. Check the code actually honours this flag.", "Filter every route, static-params list, sitemap and link block by the publish flag."],
105
- "title-length": ["META-01", "medium", n => `${n} title(s) outside 20–60 characters`, "Long titles get cut off in results; very short ones waste the spot.", "Keep titles about 30–60 characters, main keyword first."],
106
- "title-dup": ["META-01", "high", n => `${n} title(s) shared by more than one item`, "Duplicate titles make pages compete with each other.", "Make each title specific to its item."],
107
- "desc-length": ["META-02", "low", n => `${n} description(s) outside 120–160 characters`, "Short descriptions undersell the page; long ones get cut off.", "Aim for 120–160 characters."],
108
- "desc-dup": ["META-02", "medium", n => `${n} description(s) shared by more than one item`, "Duplicate descriptions signal templated pages.", "Write a specific description per item."],
109
- "placeholder": ["CONTENT-09", "high", n => `${n} item(s) contain placeholder or broken text`, "Placeholders and mangled characters look unfinished.", "Replace them with real content; keep the patterns in a build check."],
110
- "banned": ["CONTENT-10", "high", n => `${n} item(s) contain banned text`, "Banned claims are a legal and trust risk. Matches are leads: an honest denial is fine.", "Remove or reword the claim at its source."],
111
- "unconfirmed": ["CONTENT-10", "needs-decision", n => `${n} item(s) contain claims the owner hasn't confirmed`, "Unconfirmed claims become false advertising if they turn out wrong.", "Get each claim confirmed, or hold it."],
112
- };
113
- const found = new Map();
114
- const add = (k, url, detail) => { let f = found.get(k); if (!f) found.set(k, f = { count: 0, evidence: [] }); f.count++; if (f.evidence.length < 100) f.evidence.push(detail ? { url, detail } : { url }); };
115
- const setCount = (k, n) => { const f = found.get(k); if (f) f.count = n; };
181
+ const CHECKS = {
182
+ "templated-text": [
183
+ "CONTENT-04",
184
+ "high",
185
+ n => `${n} pair(s) of items share most of their copy`,
186
+ "Items whose text differs only by a swapped name (city, product, tool) become doorway or scaled-content pages.",
187
+ "Write specific copy per item, or merge and hold the items that can't be made unique.",
188
+ ],
189
+ "few-distinct-texts": [
190
+ "CONTENT-04",
191
+ "high",
192
+ n => `Only ${n} distinct text(s) once names are removed`,
193
+ "When hundreds of items collapse to a handful of texts after removing the swapped name, the pages are templates.",
194
+ "Treat each template as one page's worth of content; add real per-item substance before publishing more.",
195
+ ],
196
+ "faq-reused": [
197
+ "CONTENT-04",
198
+ "medium",
199
+ n => `${n} FAQ question(s) are reused across items`,
200
+ "Identical FAQs on many pages add nothing unique.",
201
+ "Write questions specific to each item; keep shared questions on one FAQ page.",
202
+ ],
203
+ "missing-field": [
204
+ "CONTENT-05",
205
+ "high",
206
+ n => `${n} item(s) are missing required fields`,
207
+ "Required fields (local proof, unique intro, author) are what make a page worth indexing.",
208
+ "Fill the fields, or keep the item unpublished until they're filled.",
209
+ ],
210
+ "unpublished": [
211
+ "CRAWL-11",
212
+ "needs-decision",
213
+ n => `${n} item(s) are marked unpublished`,
214
+ "Unpublished items must not be routable, linked or in the sitemap. Check the code actually honours this flag.",
215
+ "Filter every route, static-params list, sitemap and link block by the publish flag.",
216
+ ],
217
+ "title-length": [
218
+ "META-01",
219
+ "medium",
220
+ n => `${n} title(s) outside 20–60 characters`,
221
+ "Long titles get cut off in results; very short ones waste the spot.",
222
+ "Keep titles about 30–60 characters, main keyword first.",
223
+ ],
224
+ "title-dup": [
225
+ "META-01",
226
+ "high",
227
+ n => `${n} title(s) shared by more than one item`,
228
+ "Duplicate titles make pages compete with each other.",
229
+ "Make each title specific to its item.",
230
+ ],
231
+ "desc-length": [
232
+ "META-02",
233
+ "low",
234
+ n => `${n} description(s) outside 120–160 characters`,
235
+ "Short descriptions undersell the page; long ones get cut off.",
236
+ "Aim for 120–160 characters.",
237
+ ],
238
+ "desc-dup": [
239
+ "META-02",
240
+ "medium",
241
+ n => `${n} description(s) shared by more than one item`,
242
+ "Duplicate descriptions signal templated pages.",
243
+ "Write a specific description per item.",
244
+ ],
245
+ "placeholder": [
246
+ "CONTENT-09",
247
+ "high",
248
+ n => `${n} item(s) contain placeholder or broken text`,
249
+ "Placeholders and mangled characters look unfinished.",
250
+ "Replace them with real content; keep the patterns in a build check.",
251
+ ],
252
+ "invisible-unicode": [
253
+ "CONTENT-09",
254
+ "medium",
255
+ n => `${n} item(s) contain invisible characters`,
256
+ "Zero-width spaces, stray byte-order marks and soft hyphens usually come from copy-pasting. Direction controls can change the order text is read in (the “Trojan Source” trick, CVE-2021-42574), and Unicode tag characters are invisible copies of letters that can hide a whole message. All of them split words for search engines and break matching, while readers see nothing wrong.",
257
+ "Strip them at the source, and normalise pasted text when content is saved.",
258
+ ],
259
+ "templated-desc": [
260
+ "META-02",
261
+ "medium",
262
+ n => `${n} description(s) repeat their title, end in a stock call to action, or end like other descriptions`,
263
+ "Descriptions built from one template (the title again, a closing “Learn more”, or the same last sentence on many items) all read alike in results and give searchers no reason to pick this page.",
264
+ "Write each description from what the page offers, in about 120–160 characters; leave calls to action to the page itself.",
265
+ ],
266
+ "unsourced-stat": [
267
+ "CONTENT-10",
268
+ "needs-decision",
269
+ n => `${n} item(s) make a claim with no source nearby`,
270
+ "Figures and claims like “73% of drivers”, “grew 40%”, “3x faster”, “$3.2 billion”, “by 2030 … will” or “a Gartner study found” can't be checked by readers or quality reviewers without a source next to them, and become a liability if they're wrong.",
271
+ "Put the source next to each claim (a link, a [1] or [^1] footnote, “Source:” or “Via:”), or remove the claim until the owner can back it.",
272
+ ],
273
+ "stale-data": [
274
+ "CONTENT-07",
275
+ "low",
276
+ n => `${n} item(s) haven't been updated in over ${MAX_AGE} months`,
277
+ `Pages built from old data (prices, opening hours, figures, rules) go out of date without anyone noticing. CONTENT-07 asks for a review every 6 to 12 months; ${MAX_AGE === 12 ? "the 12-month line is our own" : `--max-age set it to ${MAX_AGE} months`}.`,
278
+ "Review the items and update their data, or confirm it's still right and record the review date. Never move the date without a real review (CONTENT-12).",
279
+ ],
280
+ "banned": [
281
+ "CONTENT-10",
282
+ "high",
283
+ n => `${n} item(s) contain banned text`,
284
+ "Banned claims are a legal and trust risk. Matches are leads: an honest denial is fine.",
285
+ "Remove or reword the claim at its source.",
286
+ ],
287
+ "unconfirmed": [
288
+ "CONTENT-10",
289
+ "needs-decision",
290
+ n => `${n} item(s) contain claims the owner hasn't confirmed`,
291
+ "Unconfirmed claims become false advertising if they turn out wrong.",
292
+ "Get each claim confirmed, or hold it.",
293
+ ],
294
+ };
295
+ const store = createFindings(CHECKS),
296
+ { add, setCount } = store;
116
297
 
117
- const live = typeof args.publish === "string" ? records.filter(r => isLive(get(r, args.publish))) : records;
118
- const stats = { records: records.length, published: typeof args.publish === "string" ? live.length : null, textFields };
119
- if (typeof args.publish === "string") records.forEach((r, i) => { if (!isLive(get(r, args.publish))) add("unpublished", urlOf(r, i), `${args.publish} = ${JSON.stringify(get(r, args.publish) ?? null)}`); });
298
+ const live = typeof args.publish === "string" ? records.filter(r => isLive(get(r, args.publish))) : records;
299
+ const stats = {
300
+ records: records.length,
301
+ published: typeof args.publish === "string" ? live.length : null,
302
+ textFields,
303
+ };
304
+ if (typeof args.publish === "string")
305
+ records.forEach((r, i) => {
306
+ if (!isLive(get(r, args.publish)))
307
+ add("unpublished", urlOf(r, i), `${args.publish} = ${JSON.stringify(get(r, args.publish) ?? null)}`);
308
+ });
120
309
 
121
- // near-duplicates (within group)
122
- const items = records.map((r, i) => ({ r, i, url: urlOf(r, i), group: typeof args.group === "string" ? String(get(r, args.group) ?? "") : "", text: cleanText(r) })).filter(x => x.text.split(" ").length >= 20);
123
- const distinct = new Set(items.map(x => x.text));
124
- stats.compared = items.length; stats.distinctTexts = distinct.size;
125
- if (items.length >= 10 && distinct.size <= items.length * 0.25) { add("few-distinct-texts", source, `${items.length} items → ${distinct.size} distinct text(s) in ${textFields.join(", ")}`); setCount("few-distinct-texts", distinct.size); }
126
- const sh = items.map(x => shingles(x.text));
127
- let pairs = 0;
128
- for (let a = 0; a < items.length && a < 1500; a++) for (let b = a + 1; b < items.length && b < 1500; b++) {
129
- if (items[a].group !== items[b].group) continue;
130
- const A = sh[a], B = sh[b]; if (!A.size || !B.size) continue;
131
- const [s1, s2] = A.size < B.size ? [A, B] : [B, A]; if (s1.size / s2.size < 0.3) continue;
132
- let inter = 0; for (const x of s1) if (s2.has(x)) inter++;
133
- const d = 2 * inter / (A.size + B.size);
134
- if (d > THRESH) { pairs++; add("templated-text", items[a].url, `${Math.round(d * 100)}% shared with ${items[b].url}`); }
135
- }
136
- setCount("templated-text", pairs);
310
+ // Near-duplicates by 5-word shingles and the Dice coefficient, within each group. Pairwise, so capped at 1,500 items.
311
+ const items = records
312
+ .map((r, i) => ({
313
+ r,
314
+ i,
315
+ url: urlOf(r, i),
316
+ group: typeof args.group === "string" ? String(get(r, args.group) ?? "") : "",
317
+ text: cleanText(r),
318
+ }))
319
+ .filter(x => x.text.split(" ").length >= 20);
320
+ const distinct = new Set(items.map(x => x.text));
321
+ stats.compared = items.length;
322
+ stats.distinctTexts = distinct.size;
323
+ if (items.length >= 10 && distinct.size <= items.length * 0.25) {
324
+ add(
325
+ "few-distinct-texts",
326
+ source,
327
+ `${items.length} items → ${distinct.size} distinct text(s) in ${textFields.join(", ")}`,
328
+ );
329
+ setCount("few-distinct-texts", distinct.size);
330
+ }
331
+ const sh = items.map(x => shingles(x.text));
332
+ let pairs = 0;
333
+ for (let a = 0; a < items.length && a < 1500; a++)
334
+ for (let b = a + 1; b < items.length && b < 1500; b++) {
335
+ if (items[a].group !== items[b].group) continue;
336
+ const A = sh[a],
337
+ B = sh[b];
338
+ if (!A.size || !B.size) continue;
339
+ const [s1, s2] = A.size < B.size ? [A, B] : [B, A];
340
+ if (s1.size / s2.size < 0.3) continue;
341
+ let inter = 0;
342
+ for (const x of s1) if (s2.has(x)) inter++;
343
+ const d = (2 * inter) / (A.size + B.size);
344
+ if (d > THRESH) {
345
+ pairs++;
346
+ add("templated-text", items[a].url, `${Math.round(d * 100)}% shared with ${items[b].url}`);
347
+ }
348
+ }
349
+ setCount("templated-text", pairs);
137
350
 
138
- // FAQs
139
- if (typeof args.faq === "string") {
140
- const qmap = new Map();
141
- records.forEach((r, i) => { for (const f of [].concat(get(r, args.faq) || [])) { const q = typeof f === "string" ? f : f && (f.q || f.question || f.name); if (!q) continue; let k = norm(q); if (STRIP) k = k.replace(new RegExp(STRIP.source, "gi"), " ").replace(/\s+/g, " ").trim(); (qmap.get(k) || qmap.set(k, { q, urls: [] }).get(k)).urls.push(urlOf(r, i)); } });
142
- let reused = 0; for (const { q, urls } of qmap.values()) if (urls.length > 1) { reused++; add("faq-reused", urls[0], `“${q.slice(0, 70)}” on ${urls.length} items`); }
143
- setCount("faq-reused", reused);
144
- }
145
- // required fields
146
- const req = list(args.required);
147
- if (req.length) records.forEach((r, i) => { const miss = req.filter(f => !str(get(r, f)).trim()); if (miss.length) add("missing-field", urlOf(r, i), `missing: ${miss.join(", ")}`); });
148
- // titles / descriptions
149
- for (const [field, lenKey, dupKey, lo, hi] of [[args.title, "title-length", "title-dup", 20, 60], [args.desc, "desc-length", "desc-dup", 120, 160]]) {
150
- if (typeof field !== "string") continue;
151
- const m = new Map();
152
- live.forEach(r => { const i = records.indexOf(r); const v = str(get(r, field)).trim(); if (!v) return; if (v.length < lo || v.length > hi) add(lenKey, urlOf(r, i), `${v.length} chars: ${v.slice(0, 80)}`); (m.get(v) || m.set(v, []).get(v)).push(urlOf(r, i)); });
153
- for (const [v, us] of m) if (us.length > 1) for (const u of us) add(dupKey, u, v.slice(0, 80));
351
+ if (typeof args.faq === "string") {
352
+ const qmap = new Map();
353
+ records.forEach((r, i) => {
354
+ for (const f of [].concat(get(r, args.faq) || [])) {
355
+ const q = typeof f === "string" ? f : f && (f.q || f.question || f.name);
356
+ if (!q) continue;
357
+ let k = norm(q);
358
+ if (STRIP) k = k.replace(new RegExp(STRIP.source, "gi"), " ").replace(/\s+/g, " ").trim();
359
+ (qmap.get(k) || qmap.set(k, { q, urls: [] }).get(k)).urls.push(urlOf(r, i));
360
+ }
361
+ });
362
+ let reused = 0;
363
+ for (const { q, urls } of qmap.values())
364
+ if (urls.length > 1) {
365
+ reused++;
366
+ add("faq-reused", urls[0], `“${q.slice(0, 70)}” on ${urls.length} items`);
367
+ }
368
+ setCount("faq-reused", reused);
369
+ }
370
+ const req = list(args.required);
371
+ if (req.length)
372
+ records.forEach((r, i) => {
373
+ const miss = req.filter(f => !str(get(r, f)).trim());
374
+ if (miss.length) add("missing-field", urlOf(r, i), `missing: ${miss.join(", ")}`);
375
+ });
376
+ // A title's length is its width: Chinese, Japanese and Korean characters count as two.
377
+ for (const [field, lenKey, dupKey, lo, hi, len, lenText] of [
378
+ [args.title, "title-length", "title-dup", 20, 60, titleWidth, widthText],
379
+ [args.desc, "desc-length", "desc-dup", 120, 160, v => v.length, v => `${v.length} chars`],
380
+ ]) {
381
+ if (typeof field !== "string") continue;
382
+ const m = new Map();
383
+ live.forEach(r => {
384
+ const i = records.indexOf(r);
385
+ const v = str(get(r, field)).trim();
386
+ if (!v) return;
387
+ if (len(v) < lo || len(v) > hi) add(lenKey, urlOf(r, i), `${lenText(v)}: ${v.slice(0, 80)}`);
388
+ (m.get(v) || m.set(v, []).get(v)).push(urlOf(r, i));
389
+ });
390
+ for (const [v, us] of m) if (us.length > 1) for (const u of us) add(dupKey, u, v.slice(0, 80));
391
+ }
392
+ // A shared ending counts only on 3+ items. The share is split by --group or the URL's first folder.
393
+ if (typeof args.desc === "string") {
394
+ const descs = live
395
+ .map(r => {
396
+ const i = records.indexOf(r),
397
+ url = urlOf(r, i);
398
+ return {
399
+ url,
400
+ section: typeof args.group === "string" ? String(get(r, args.group) ?? "") : sectionOf(url),
401
+ desc: str(get(r, args.desc)).trim(),
402
+ title: typeof args.title === "string" ? str(get(r, args.title)).trim() : "",
403
+ };
404
+ })
405
+ .filter(x => x.desc);
406
+ const hits = templatedDescs(descs, { titleRepeat: true });
407
+ for (const [u, why] of hits) add("templated-desc", u, why);
408
+ if (hits.length)
409
+ stats.templatedDescriptions = templatedShare(
410
+ descs,
411
+ hits.map(h => h[0]),
412
+ );
413
+ }
414
+ // Without --date, the first of these fields that half the items fill.
415
+ const DATE_KEYS = [
416
+ "dateModified",
417
+ "updatedAt",
418
+ "updated_at",
419
+ "updated",
420
+ "lastUpdated",
421
+ "last_updated",
422
+ "lastModified",
423
+ "modified",
424
+ "lastReviewed",
425
+ "last_reviewed",
426
+ "reviewed",
427
+ ];
428
+ const dateField =
429
+ typeof args.date === "string"
430
+ ? args.date
431
+ : DATE_KEYS.find(k => records.filter(r => str(get(r, k)).trim()).length >= records.length / 2);
432
+ if (dateField)
433
+ live.forEach(r => {
434
+ const v = str(get(r, dateField)).trim(),
435
+ t = Date.parse(v);
436
+ if (t && Date.now() - t > MAX_AGE * 30.44 * 864e5)
437
+ add("stale-data", urlOf(r, records.indexOf(r)), `${dateField}: ${v}`);
438
+ });
439
+ const fieldNames = [...new Set(records.flatMap(r => Object.keys(r)))].filter(k => !k.startsWith("_")).slice(0, 100);
440
+ stats.fields = Object.fromEntries(
441
+ fieldNames.map(k => {
442
+ const filled = records.filter(r => str(r[k]).trim()).length;
443
+ return [k, { filled, missing: records.length - filled }];
444
+ }),
445
+ );
446
+ const missingNote = fieldNames
447
+ .filter(k => stats.fields[k].missing)
448
+ .map(k => `${k} ${stats.fields[k].missing} of ${records.length}`);
449
+ const claims = [];
450
+ records.forEach((r, i) => {
451
+ const all = str(r);
452
+ const inv = invisibleChar(all);
453
+ if (inv) {
454
+ const at = inv.index;
455
+ add(
456
+ "invisible-unicode",
457
+ urlOf(r, i),
458
+ `${inv.code} (${inv.name}) in “${all.slice(Math.max(0, at - 20), at)}⟨here⟩${all.slice(at + inv.char.length, at + 20)}”`,
459
+ );
460
+ }
461
+ // A schema.org `citation` field sources every claim in the item.
462
+ const cited = !!str(get(r, "citation")).trim();
463
+ const own = Object.entries(r)
464
+ .filter(([k]) => !k.startsWith("_") && k !== "citation")
465
+ .flatMap(([, v]) => claimsIn(str(v)))
466
+ .map(c => ({ url: urlOf(r, i), ...c, sourced: c.sourced || cited }));
467
+ claims.push(...own);
468
+ const bare = own.filter(c => !c.sourced);
469
+ if (bare.length)
470
+ add(
471
+ "unsourced-stat",
472
+ urlOf(r, i),
473
+ `${bare.length} of ${own.length} claims have no source nearby (${Math.round((100 * bare.length) / own.length)}%): ${bare
474
+ .slice(0, 5)
475
+ .map(c => `“${c.claim}” (${c.kind})`)
476
+ .join("; ")}${bare.length > 5 ? `; and ${bare.length - 5} more` : ""}`,
477
+ );
478
+ const ph = all.match(PH);
479
+ if (ph) add("placeholder", urlOf(r, i), `“${ph[0]}”`);
480
+ if (BANNED) {
481
+ const c = ctx(all, BANNED);
482
+ if (c) add("banned", urlOf(r, i), c);
483
+ }
484
+ if (VERIFY) {
485
+ const c = ctx(all, VERIFY);
486
+ if (c) add("unconfirmed", urlOf(r, i), c);
487
+ }
488
+ });
489
+
490
+ const findings = store.list({ source: "content-scan", prefix: "D", category: "Content data" });
491
+ stats.claims = { total: claims.length, unsourced: claims.filter(c => !c.sourced).length };
492
+ const notes = [
493
+ `Scanned ${records.length} records from ${source}; compared ${items.length} texts (${distinct.size} distinct after removing names).`,
494
+ ];
495
+ if (missingNote.length) notes.push(`Missing values: ${missingNote.join(", ")}.`);
496
+ if (claims.length > 1000) notes.push(`claims lists the first 1,000 of ${claims.length} claims.`);
497
+ const report = {
498
+ tool: "seo-supervisor-content-scan",
499
+ scannedAt: new Date().toISOString(),
500
+ source,
501
+ options: {
502
+ text: textFields,
503
+ group: args.group || null,
504
+ strip: args.strip || null,
505
+ threshold: THRESH,
506
+ date: dateField || null,
507
+ maxAge: MAX_AGE,
508
+ },
509
+ stats,
510
+ findings,
511
+ claims: claims.slice(0, 1000),
512
+ passed: [],
513
+ notChecked: [],
514
+ notes,
515
+ };
516
+ mkdirSync(dirname(OUT), { recursive: true });
517
+ writeFileSync(OUT, JSON.stringify(report, null, 2));
518
+ console.log(
519
+ `content-scan: ${records.length} records, ${findings.length} findings ${JSON.stringify(findings.reduce((m, f) => ((m[f.severity] = (m[f.severity] || 0) + 1), m), {}))} → ${OUT}`,
520
+ );
521
+ // --fail-on lets CI stop a publish. For unsourced-stat, a single unsourced claim is enough.
522
+ const failed = findings.filter(f => FAIL_ON.includes(f.check));
523
+ if (failed.length) {
524
+ console.error(`content-scan: failing on ${failed.map(f => `${f.check} (${f.count})`).join(", ")}`);
525
+ return 1;
526
+ }
527
+ return 0;
154
528
  }
155
- // text patterns over every string field
156
- records.forEach((r, i) => {
157
- const all = str(r);
158
- const ph = all.match(PH); if (ph) add("placeholder", urlOf(r, i), `“${ph[0]}”`);
159
- if (BANNED) { const c = ctx(all, BANNED); if (c) add("banned", urlOf(r, i), c); }
160
- if (VERIFY) { const c = ctx(all, VERIFY); if (c) add("unconfirmed", urlOf(r, i), c); }
161
- });
162
529
 
163
- // ---------- output ----------
164
- const SEV = { blocker: 0, high: 1, "needs-decision": 2, medium: 3, low: 4 };
165
- const findings = [...found].map(([k, f]) => {
166
- const [rule, severity, title, why, fix] = CHECKS[k]; const ex = f.evidence[0] || {};
167
- return { check: k, rule, severity, category: "Content data", title: title(f.count), what: `${f.count === 1 ? "Found in" : "For example"} ${ex.url}${ex.detail ? ` (${ex.detail})` : ""}.`, why, fix, count: f.count, evidence: f.evidence, source: "content-scan", status: severity === "needs-decision" ? "needs-decision" : "open" };
168
- }).sort((a, b) => SEV[a.severity] - SEV[b.severity] || b.count - a.count);
169
- findings.forEach((f, i) => { f.id = "D-" + String(i + 1).padStart(3, "0"); });
170
- const report = { tool: "seo-supervisor-content-scan", scannedAt: new Date().toISOString(), source, options: { text: textFields, group: args.group || null, strip: args.strip || null, threshold: THRESH }, stats, findings, passed: [], notChecked: [], notes: [`Scanned ${records.length} records from ${source}; compared ${items.length} texts (${distinct.size} distinct after removing names).`] };
171
- mkdirSync(dirname(OUT), { recursive: true });
172
- writeFileSync(OUT, JSON.stringify(report, null, 2));
173
- console.log(`content-scan: ${records.length} records, ${findings.length} findings ${JSON.stringify(findings.reduce((m, f) => (m[f.severity] = (m[f.severity] || 0) + 1, m), {}))} → ${OUT}`);
530
+ if (isMain(import.meta.url)) await runMain(() => main(process.argv.slice(2)));