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.
- package/.claude-plugin/icon.png +0 -0
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +16 -3
- package/CHANGELOG.md +430 -0
- package/NOTICE +7 -0
- package/README.md +230 -25
- package/agents/seo-auditor.md +16 -0
- package/agents/seo-reviewer.md +16 -0
- package/bin/agents.mjs +194 -29
- package/bin/extras.mjs +422 -0
- package/bin/prompt.mjs +34 -14
- package/bin/seo-supervisor.mjs +386 -53
- package/commands/seo-audit.md +29 -3
- package/commands/seo-brief.md +28 -0
- package/commands/seo-connect.md +27 -0
- package/commands/seo-fix.md +24 -3
- package/commands/seo-grow.md +26 -0
- package/commands/seo-launch.md +17 -3
- package/commands/seo-review.md +13 -1
- package/commands/seo-rewrite.md +25 -0
- package/commands/seo-setup.md +17 -1
- package/commands/seo-watch.md +28 -0
- package/hooks/hooks.json +117 -0
- package/package.json +20 -7
- package/skills/seo-supervisor/NOTICE +7 -0
- package/skills/seo-supervisor/SKILL.md +302 -21
- package/skills/seo-supervisor/audience.md +61 -0
- package/skills/seo-supervisor/examples/drafts/security.md +41 -0
- package/skills/seo-supervisor/examples/hooks/README.md +28 -0
- package/skills/seo-supervisor/examples/hooks/claude-code-settings.json +15 -0
- package/skills/seo-supervisor/examples/hooks/codex-hooks.json +17 -0
- package/skills/seo-supervisor/examples/hooks/copilot-hooks.json +15 -0
- package/skills/seo-supervisor/examples/hooks/cursor-hooks.json +11 -0
- package/skills/seo-supervisor/examples/hooks/github-actions.yml +21 -0
- package/skills/seo-supervisor/examples/hooks/pre-commit +17 -0
- package/skills/seo-supervisor/examples/hooks/reading-ease.yml +24 -0
- package/skills/seo-supervisor/examples/sample-audit.json +94 -2
- package/skills/seo-supervisor/examples/sample-report.html +111 -61
- package/skills/seo-supervisor/examples/sample-report.md +147 -44
- package/skills/seo-supervisor/examples/scheduled-runs.md +89 -0
- package/skills/seo-supervisor/examples/snippets.md +648 -1
- package/skills/seo-supervisor/grow.md +342 -0
- package/skills/seo-supervisor/og-images.md +85 -0
- package/skills/seo-supervisor/page-types.md +124 -0
- package/skills/seo-supervisor/planning.md +19 -7
- package/skills/seo-supervisor/profile-template.md +41 -0
- package/skills/seo-supervisor/report-format.md +177 -10
- package/skills/seo-supervisor/rewrite.md +59 -0
- package/skills/seo-supervisor/rules/ai-search.md +65 -12
- package/skills/seo-supervisor/rules/content.md +33 -9
- package/skills/seo-supervisor/rules/crawl-index.md +33 -6
- package/skills/seo-supervisor/rules/internal-linking.md +49 -6
- package/skills/seo-supervisor/rules/launch-monitoring.md +17 -8
- package/skills/seo-supervisor/rules/media.md +13 -1
- package/skills/seo-supervisor/rules/metadata.md +41 -9
- package/skills/seo-supervisor/rules/performance.md +50 -5
- package/skills/seo-supervisor/rules/rendering.md +39 -2
- package/skills/seo-supervisor/rules/search-intent.md +32 -0
- package/skills/seo-supervisor/rules/sitemaps-robots.md +24 -12
- package/skills/seo-supervisor/rules/structured-data.md +37 -14
- package/skills/seo-supervisor/rules/trust-security.md +25 -2
- package/skills/seo-supervisor/rules/urls.md +10 -2
- package/skills/seo-supervisor/scripts/ai-answers.mjs +314 -0
- package/skills/seo-supervisor/scripts/backlinks.mjs +412 -0
- package/skills/seo-supervisor/scripts/change-check.mjs +281 -0
- package/skills/seo-supervisor/scripts/checks/agents.mjs +488 -0
- package/skills/seo-supervisor/scripts/checks/assets.mjs +404 -0
- package/skills/seo-supervisor/scripts/checks/bots.mjs +146 -0
- package/skills/seo-supervisor/scripts/checks/business-type.mjs +193 -0
- package/skills/seo-supervisor/scripts/checks/content.mjs +391 -0
- package/skills/seo-supervisor/scripts/checks/coverage.mjs +184 -0
- package/skills/seo-supervisor/scripts/checks/crawl.mjs +95 -0
- package/skills/seo-supervisor/scripts/checks/hreflang.mjs +396 -0
- package/skills/seo-supervisor/scripts/checks/hygiene.mjs +227 -0
- package/skills/seo-supervisor/scripts/checks/lighthouse.mjs +271 -0
- package/skills/seo-supervisor/scripts/checks/link-strength.mjs +59 -0
- package/skills/seo-supervisor/scripts/checks/links.mjs +360 -0
- package/skills/seo-supervisor/scripts/checks/local.mjs +101 -0
- package/skills/seo-supervisor/scripts/checks/media.mjs +194 -0
- package/skills/seo-supervisor/scripts/checks/outbound.mjs +53 -0
- package/skills/seo-supervisor/scripts/checks/page.mjs +223 -0
- package/skills/seo-supervisor/scripts/checks/probes.mjs +130 -0
- package/skills/seo-supervisor/scripts/checks/render.mjs +552 -0
- package/skills/seo-supervisor/scripts/checks/robots.mjs +144 -0
- package/skills/seo-supervisor/scripts/checks/schema.mjs +206 -0
- package/skills/seo-supervisor/scripts/checks/site-agents.mjs +79 -0
- package/skills/seo-supervisor/scripts/checks/site-content.mjs +135 -0
- package/skills/seo-supervisor/scripts/checks/site-hygiene.mjs +202 -0
- package/skills/seo-supervisor/scripts/checks/site-pages.mjs +474 -0
- package/skills/seo-supervisor/scripts/checks/site-security.mjs +102 -0
- package/skills/seo-supervisor/scripts/checks/sitemap.mjs +473 -0
- package/skills/seo-supervisor/scripts/checks/speed.mjs +267 -0
- package/skills/seo-supervisor/scripts/checks/technical.mjs +368 -0
- package/skills/seo-supervisor/scripts/checks/tls.mjs +297 -0
- package/skills/seo-supervisor/scripts/checks/trust.mjs +421 -0
- package/skills/seo-supervisor/scripts/checks/visual.mjs +1132 -0
- package/skills/seo-supervisor/scripts/checks/writing.mjs +192 -0
- package/skills/seo-supervisor/scripts/commoncrawl.mjs +452 -0
- package/skills/seo-supervisor/scripts/connect-keys.mjs +422 -0
- package/skills/seo-supervisor/scripts/content-scan.mjs +515 -158
- package/skills/seo-supervisor/scripts/crawl/catalog.mjs +1248 -0
- package/skills/seo-supervisor/scripts/crawl/fetch.mjs +362 -0
- package/skills/seo-supervisor/scripts/crawl/page.mjs +741 -0
- package/skills/seo-supervisor/scripts/crawl/queue.mjs +190 -0
- package/skills/seo-supervisor/scripts/dashboard.mjs +140 -0
- package/skills/seo-supervisor/scripts/data/ai-bots.json +38 -0
- package/skills/seo-supervisor/scripts/data/build-schema-vocab.mjs +57 -0
- package/skills/seo-supervisor/scripts/data/business-types.json +338 -0
- package/skills/seo-supervisor/scripts/data/google-rich-results.json +79 -0
- package/skills/seo-supervisor/scripts/data/schema-vocab.json +1 -0
- package/skills/seo-supervisor/scripts/deploy-check.mjs +462 -0
- package/skills/seo-supervisor/scripts/disavow.mjs +176 -0
- package/skills/seo-supervisor/scripts/doctor.mjs +174 -0
- package/skills/seo-supervisor/scripts/geo-grid.mjs +371 -0
- package/skills/seo-supervisor/scripts/google/search-console.mjs +151 -0
- package/skills/seo-supervisor/scripts/google/session.mjs +167 -0
- package/skills/seo-supervisor/scripts/google-updates.mjs +189 -0
- package/skills/seo-supervisor/scripts/google.mjs +1341 -0
- package/skills/seo-supervisor/scripts/gsc-import.mjs +298 -0
- package/skills/seo-supervisor/scripts/guard/adapters/claude-code.mjs +149 -0
- package/skills/seo-supervisor/scripts/guard/adapters/cline.mjs +28 -0
- package/skills/seo-supervisor/scripts/guard/adapters/codex.mjs +26 -0
- package/skills/seo-supervisor/scripts/guard/adapters/copilot.mjs +36 -0
- package/skills/seo-supervisor/scripts/guard/adapters/cursor.mjs +33 -0
- package/skills/seo-supervisor/scripts/guard/adapters/devin.mjs +25 -0
- package/skills/seo-supervisor/scripts/guard/adapters/edits.mjs +124 -0
- package/skills/seo-supervisor/scripts/guard/mode.mjs +37 -0
- package/skills/seo-supervisor/scripts/guard/rules.mjs +931 -0
- package/skills/seo-supervisor/scripts/guard.mjs +74 -0
- package/skills/seo-supervisor/scripts/images.mjs +408 -0
- package/skills/seo-supervisor/scripts/indexnow.mjs +300 -0
- package/skills/seo-supervisor/scripts/issues.mjs +217 -0
- package/skills/seo-supervisor/scripts/keys/authority.mjs +135 -0
- package/skills/seo-supervisor/scripts/keys/bing.mjs +239 -0
- package/skills/seo-supervisor/scripts/keys/clarity.mjs +137 -0
- package/skills/seo-supervisor/scripts/keys/dataforseo.mjs +57 -0
- package/skills/seo-supervisor/scripts/keys/googleplaces.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/http.mjs +212 -0
- package/skills/seo-supervisor/scripts/keys/matomo.mjs +138 -0
- package/skills/seo-supervisor/scripts/keys/openai.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/perplexity.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/posthog.mjs +165 -0
- package/skills/seo-supervisor/scripts/keys/semrush.mjs +25 -0
- package/skills/seo-supervisor/scripts/keys/services.mjs +41 -0
- package/skills/seo-supervisor/scripts/keys/store.mjs +140 -0
- package/skills/seo-supervisor/scripts/keys/visits.mjs +58 -0
- package/skills/seo-supervisor/scripts/keys/youtube.mjs +84 -0
- package/skills/seo-supervisor/scripts/keyword-data.mjs +316 -0
- package/skills/seo-supervisor/scripts/keyword-ideas.mjs +503 -0
- package/skills/seo-supervisor/scripts/lib/args.mjs +56 -0
- package/skills/seo-supervisor/scripts/lib/business.mjs +27 -0
- package/skills/seo-supervisor/scripts/lib/cdp.mjs +242 -0
- package/skills/seo-supervisor/scripts/lib/cli.mjs +56 -0
- package/skills/seo-supervisor/scripts/lib/csv.mjs +38 -0
- package/skills/seo-supervisor/scripts/lib/findings.mjs +100 -0
- package/skills/seo-supervisor/scripts/lib/google-client.mjs +9 -0
- package/skills/seo-supervisor/scripts/lib/html.mjs +146 -0
- package/skills/seo-supervisor/scripts/lib/http.mjs +28 -0
- package/skills/seo-supervisor/scripts/lib/image-size.mjs +78 -0
- package/skills/seo-supervisor/scripts/lib/is-main.mjs +13 -0
- package/skills/seo-supervisor/scripts/lib/net.mjs +116 -0
- package/skills/seo-supervisor/scripts/lib/proxy.mjs +47 -0
- package/skills/seo-supervisor/scripts/lib/recheck.mjs +106 -0
- package/skills/seo-supervisor/scripts/lib/redact.mjs +78 -0
- package/skills/seo-supervisor/scripts/lib/robots.mjs +73 -0
- package/skills/seo-supervisor/scripts/lib/score.mjs +266 -0
- package/skills/seo-supervisor/scripts/lib/settings-dir.mjs +81 -0
- package/skills/seo-supervisor/scripts/links-import.mjs +603 -0
- package/skills/seo-supervisor/scripts/log-scan.mjs +597 -0
- package/skills/seo-supervisor/scripts/og-card.mjs +273 -0
- package/skills/seo-supervisor/scripts/osm.mjs +359 -0
- package/skills/seo-supervisor/scripts/rdap.mjs +164 -0
- package/skills/seo-supervisor/scripts/render-report.mjs +324 -690
- package/skills/seo-supervisor/scripts/report/client.js +37 -0
- package/skills/seo-supervisor/scripts/report/diff.mjs +264 -0
- package/skills/seo-supervisor/scripts/report/findings.mjs +165 -0
- package/skills/seo-supervisor/scripts/report/format.mjs +111 -0
- package/skills/seo-supervisor/scripts/report/markdown.mjs +250 -0
- package/skills/seo-supervisor/scripts/report/model.mjs +171 -0
- package/skills/seo-supervisor/scripts/report/overview-lines.mjs +158 -0
- package/skills/seo-supervisor/scripts/report/overview.mjs +224 -0
- package/skills/seo-supervisor/scripts/report/page.mjs +127 -0
- package/skills/seo-supervisor/scripts/report/panel.mjs +172 -0
- package/skills/seo-supervisor/scripts/report/panels/ai.mjs +211 -0
- package/skills/seo-supervisor/scripts/report/panels/connections.mjs +139 -0
- package/skills/seo-supervisor/scripts/report/panels/content.mjs +204 -0
- package/skills/seo-supervisor/scripts/report/panels/data-search.mjs +379 -0
- package/skills/seo-supervisor/scripts/report/panels/data-site.mjs +44 -0
- package/skills/seo-supervisor/scripts/report/panels/links.mjs +380 -0
- package/skills/seo-supervisor/scripts/report/panels/local.mjs +221 -0
- package/skills/seo-supervisor/scripts/report/panels/site.mjs +359 -0
- package/skills/seo-supervisor/scripts/report/panels/speed-media.mjs +267 -0
- package/skills/seo-supervisor/scripts/report/sources.mjs +163 -0
- package/skills/seo-supervisor/scripts/report/styles.css +223 -0
- package/skills/seo-supervisor/scripts/report/traffic.mjs +264 -0
- package/skills/seo-supervisor/scripts/report-plan.mjs +112 -33
- package/skills/seo-supervisor/scripts/schema-check.mjs +717 -0
- package/skills/seo-supervisor/scripts/seo-crawl.mjs +1086 -638
- package/skills/seo-supervisor/scripts/seo-diff.mjs +584 -0
- package/skills/seo-supervisor/scripts/update-check.mjs +82 -0
- package/skills/seo-supervisor/site-types/content.md +34 -1
- package/skills/seo-supervisor/site-types/ecommerce.md +38 -1
- package/skills/seo-supervisor/site-types/local-business.md +96 -6
- package/skills/seo-supervisor/site-types/services.md +46 -0
- package/skills/seo-supervisor/site-types/tools.md +3 -3
- package/skills/seo-supervisor/strategy.md +232 -0
- package/skills/seo-supervisor/troubleshooting.md +56 -0
|
@@ -0,0 +1,584 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @ts-check
|
|
3
|
+
// Reports what changed between two crawls. Pages are matched by path, so a local crawl compares with the public site.
|
|
4
|
+
import { readFileSync, writeFileSync, mkdirSync, readdirSync, existsSync, copyFileSync } from "node:fs";
|
|
5
|
+
import { dirname, join, resolve } from "node:path";
|
|
6
|
+
import { isMain } from "./lib/is-main.mjs";
|
|
7
|
+
import { parseArgs } from "./lib/args.mjs";
|
|
8
|
+
import { Fail, runMain } from "./lib/cli.mjs";
|
|
9
|
+
import { LIMITS, fmtCwv } from "./checks/speed.mjs";
|
|
10
|
+
|
|
11
|
+
const pathOf = u => {
|
|
12
|
+
try {
|
|
13
|
+
const x = new URL(u);
|
|
14
|
+
return x.pathname + x.search;
|
|
15
|
+
} catch {
|
|
16
|
+
return u;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const ok = s => s === 200;
|
|
20
|
+
// Retired rich-result types not marked keep: taking one off a page is no loss. FAQPage is kept, since Bing and AI
|
|
21
|
+
// engines still read it.
|
|
22
|
+
const RETIRED = new Set(
|
|
23
|
+
JSON.parse(readFileSync(new URL("./data/google-rich-results.json", import.meta.url), "utf8"))
|
|
24
|
+
.retired.filter(r => !r.keep)
|
|
25
|
+
.map(r => r.type),
|
|
26
|
+
);
|
|
27
|
+
const OG = [
|
|
28
|
+
["ogTitle", "og:title"],
|
|
29
|
+
["ogImage", "og:image"],
|
|
30
|
+
["ogDescription", "og:description"],
|
|
31
|
+
["ogUrl", "og:url"],
|
|
32
|
+
];
|
|
33
|
+
// "− old · + new" for what went and came, 8 at most.
|
|
34
|
+
const changes = (gone, came) => {
|
|
35
|
+
const l = [...gone.map(x => `− ${x}`), ...came.map(x => `+ ${x}`)];
|
|
36
|
+
return l.slice(0, 8).join(" · ") + (l.length > 8 ? ` · and ${l.length - 8} more` : "");
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Speed compares like with like, by path. Field data is slower when any Core Web Vital crosses its limit, or moves 20%
|
|
40
|
+
// and at least 300 ms (LCP), 50 ms (INP) or 0.05 (CLS). Lab runs swing more, so lab LCP must move 40% and 1 s, and a
|
|
41
|
+
// Lighthouse score 15 points. Each SPEED row: name, value by URL (null when none), verdict (-1 slower, 1 faster,
|
|
42
|
+
// 0 no real change).
|
|
43
|
+
const lcpMove = (o, n, share, ms) => {
|
|
44
|
+
const d = n.lcp - o.lcp;
|
|
45
|
+
return Math.abs(d) >= Math.max(ms, o.lcp * share) ? -Math.sign(d) : 0;
|
|
46
|
+
};
|
|
47
|
+
const crossed = (o, n, worse) =>
|
|
48
|
+
Object.entries(LIMITS).some(
|
|
49
|
+
([k, lim]) => o[k] != null && n[k] != null && (worse ? o[k] <= lim && n[k] > lim : o[k] > lim && n[k] <= lim),
|
|
50
|
+
);
|
|
51
|
+
const REAL_MOVE = { lcp: 300, inp: 50, cls: 0.05 };
|
|
52
|
+
const realMove = (o, n) => {
|
|
53
|
+
const v = Object.entries(REAL_MOVE)
|
|
54
|
+
.filter(([k]) => o[k] != null && n[k] != null)
|
|
55
|
+
.map(([k, min]) => {
|
|
56
|
+
const d = n[k] - o[k];
|
|
57
|
+
return Math.abs(d) >= Math.max(min, o[k] * 0.2) ? -Math.sign(d) : 0;
|
|
58
|
+
});
|
|
59
|
+
return v.includes(-1) ? -1 : v.includes(1) ? 1 : 0;
|
|
60
|
+
};
|
|
61
|
+
const real = (o, n) => (crossed(o, n, true) ? -1 : realMove(o, n) || (crossed(o, n, false) ? 1 : 0));
|
|
62
|
+
const field = samples => samples?.map(s => [s.url, s.field?.lcp != null ? s.field : null]);
|
|
63
|
+
/** @type {[string, (r: any) => any[], (o: any, n: any) => number, (v: any) => string][]} */
|
|
64
|
+
const SPEED = [
|
|
65
|
+
["real visitors", r => field(r.speed?.samples), real, fmtCwv],
|
|
66
|
+
["real visitors, desktop", r => field(r.speed?.desktop?.samples), real, fmtCwv],
|
|
67
|
+
[
|
|
68
|
+
"lab test",
|
|
69
|
+
r => r.labSpeed?.map(l => [l.url, l.lcp != null ? l : null]),
|
|
70
|
+
(o, n) => lcpMove(o, n, 0.4, 1000),
|
|
71
|
+
fmtCwv,
|
|
72
|
+
],
|
|
73
|
+
[
|
|
74
|
+
"Lighthouse",
|
|
75
|
+
r => r.lighthouse?.map(l => [l.url, l.scores?.performance ?? null]),
|
|
76
|
+
(o, n) => (Math.abs(n - o) >= 15 ? Math.sign(n - o) : 0),
|
|
77
|
+
v => `performance score ${v}`,
|
|
78
|
+
],
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
// Each rule is tagged with its group's user agents, so a rule moving between crawlers shows. As in the crawler, a
|
|
82
|
+
// User-agent line after a rule starts a new group.
|
|
83
|
+
function robotsLines(text) {
|
|
84
|
+
let agents = [],
|
|
85
|
+
ruled = true;
|
|
86
|
+
const out = [];
|
|
87
|
+
for (const raw of (text || "").split(/\r?\n/)) {
|
|
88
|
+
const line = raw.replace(/#.*/, "").trim(),
|
|
89
|
+
key = line.split(":")[0].trim().toLowerCase();
|
|
90
|
+
if (!line) continue;
|
|
91
|
+
if (key === "user-agent") {
|
|
92
|
+
if (ruled) agents = [];
|
|
93
|
+
ruled = false;
|
|
94
|
+
agents.push(line.slice(line.indexOf(":") + 1).trim());
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (key === "allow" || key === "disallow") {
|
|
98
|
+
ruled = true;
|
|
99
|
+
out.push(`${line} (${agents.join(", ") || "no user agent"})`);
|
|
100
|
+
} else out.push(line);
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
// Compares the first 50 KB the crawl keeps; a change past that (rare: Google reads 500 KiB) changes only the hash.
|
|
105
|
+
function robotsChange(o, n) {
|
|
106
|
+
if (o.status === n.status && o.hash === n.hash) return null;
|
|
107
|
+
const was = robotsLines(o.text),
|
|
108
|
+
now = robotsLines(n.text);
|
|
109
|
+
const gone = was.filter(l => !now.includes(l)),
|
|
110
|
+
came = now.filter(l => !was.includes(l));
|
|
111
|
+
if (o.status === n.status && !gone.length && !came.length) return null; // comments, spacing or order only
|
|
112
|
+
const detail = [
|
|
113
|
+
o.status !== n.status && `status ${o.status} → ${n.status}`,
|
|
114
|
+
(gone.length || came.length) && changes(gone, came),
|
|
115
|
+
]
|
|
116
|
+
.filter(Boolean)
|
|
117
|
+
.join("; ");
|
|
118
|
+
return {
|
|
119
|
+
path: "/robots.txt",
|
|
120
|
+
kind: "robots-changed",
|
|
121
|
+
before: `status ${o.status}`,
|
|
122
|
+
after: `status ${n.status}`,
|
|
123
|
+
detail,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
const permanent = s => s === 301 || s === 308;
|
|
127
|
+
// A redirect's target by path when it stays on the same host, in full when it leaves it; null when it never ends.
|
|
128
|
+
const target = r => {
|
|
129
|
+
if (r.to == null) return null;
|
|
130
|
+
try {
|
|
131
|
+
const t = new URL(r.to),
|
|
132
|
+
f = new URL(r.from);
|
|
133
|
+
return t.origin === f.origin ? t.pathname + t.search : t.href;
|
|
134
|
+
} catch {
|
|
135
|
+
return r.to;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const redirectText = r => (target(r) == null ? "a redirect loop" : `${r.status} to ${target(r)}`);
|
|
139
|
+
|
|
140
|
+
// Kinds where the page itself changed, so search engines should fetch it again. Links, sitemap listing, speed and pages
|
|
141
|
+
// that now fail or are noindex don't count.
|
|
142
|
+
const RECRAWL = new Set([
|
|
143
|
+
"status-fixed",
|
|
144
|
+
"noindex-removed",
|
|
145
|
+
"canonical-changed",
|
|
146
|
+
"title-changed",
|
|
147
|
+
"description-changed",
|
|
148
|
+
"h1-added",
|
|
149
|
+
"h1-removed",
|
|
150
|
+
"h1-changed",
|
|
151
|
+
"h2-changed",
|
|
152
|
+
"hreflang-changed",
|
|
153
|
+
"og-added",
|
|
154
|
+
"og-removed",
|
|
155
|
+
"content-shrunk",
|
|
156
|
+
"content-grew",
|
|
157
|
+
"schema-added",
|
|
158
|
+
"schema-removed",
|
|
159
|
+
"schema-retired-removed",
|
|
160
|
+
"schema-fields-added",
|
|
161
|
+
"schema-fields-removed",
|
|
162
|
+
"redirect-added",
|
|
163
|
+
"redirect-changed",
|
|
164
|
+
"redirect-removed",
|
|
165
|
+
]);
|
|
166
|
+
// Paths to resubmit: those changes plus added pages. Used by indexnow.mjs and connect-keys.mjs submit-bing.
|
|
167
|
+
export const changedPages = d =>
|
|
168
|
+
[...(d.regressions || []), ...(d.improvements || []), ...(d.changed || [])]
|
|
169
|
+
.filter(c => RECRAWL.has(c?.kind))
|
|
170
|
+
.map(c => c.path)
|
|
171
|
+
.concat(d.added || []);
|
|
172
|
+
|
|
173
|
+
// A burst of new pages can mean a hack (URL injection).
|
|
174
|
+
// https://support.google.com/webmasters/answer/9044101#hacked-url-injection
|
|
175
|
+
// 50 pages is more than a site usually publishes between audits; 20% of the last crawl keeps a big shop's routine
|
|
176
|
+
// products out. Folders follow the crawler's `sections` rule, and examples rotate across them, largest first, so a new
|
|
177
|
+
// folder stands out. The topic is never judged: a casino site's casino pages are normal.
|
|
178
|
+
function addedBurst(added, before, after) {
|
|
179
|
+
const was = [...before.values()].filter(p => ok(p.status)).length;
|
|
180
|
+
if (!was || added.length < 50 || added.length < was / 5) return null;
|
|
181
|
+
const parts = p => p.split("?")[0].split("/").filter(Boolean);
|
|
182
|
+
const folders = new Set(
|
|
183
|
+
[...after]
|
|
184
|
+
.filter(([, n]) => ok(n.status))
|
|
185
|
+
.map(([p]) => parts(p))
|
|
186
|
+
.filter(s => s.length > 1)
|
|
187
|
+
.map(s => s[0]),
|
|
188
|
+
),
|
|
189
|
+
groups = new Map();
|
|
190
|
+
for (const p of added) {
|
|
191
|
+
const s = parts(p)[0],
|
|
192
|
+
key = folders.has(s) ? `/${s}/` : "/";
|
|
193
|
+
groups.set(key, [...(groups.get(key) || []), p]);
|
|
194
|
+
}
|
|
195
|
+
const sorted = [...groups].sort((a, b) => b[1].length - a[1].length || (a[0] < b[0] ? -1 : 1)),
|
|
196
|
+
examples = [];
|
|
197
|
+
for (let i = 0; examples.length < Math.min(10, added.length); i++)
|
|
198
|
+
for (const [, l] of sorted) if (l[i] && examples.length < 10) examples.push(l[i]);
|
|
199
|
+
return {
|
|
200
|
+
pages: added.length,
|
|
201
|
+
before: was,
|
|
202
|
+
share: Math.round((1000 * added.length) / was) / 1000,
|
|
203
|
+
sections: sorted.slice(0, 20).map(([path, l]) => ({ path, pages: l.length })),
|
|
204
|
+
examples: examples.map(path => ({ path, title: after.get(path).title ?? null })),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function diffCrawls(oldReport, newReport) {
|
|
209
|
+
// Working pages plus the crawl's error records, so a page that now fails is a status change, not "gone".
|
|
210
|
+
const index = r => new Map([...(r.pages || []), ...(r.errors || [])].map(p => [pathOf(p.url), p]));
|
|
211
|
+
const before = index(oldReport),
|
|
212
|
+
after = index(newReport);
|
|
213
|
+
/** @typedef {{ path: string, kind: string, detail?: string, before?: any, after?: any, source?: string }} Change */
|
|
214
|
+
const regressions = /** @type {Change[]} */ ([]),
|
|
215
|
+
improvements = /** @type {Change[]} */ ([]),
|
|
216
|
+
changed = /** @type {Change[]} */ ([]),
|
|
217
|
+
compared = new Set();
|
|
218
|
+
// Sitemap listing only when both crawls read the whole sitemap: one that failed this time is sitemap-missing, and a
|
|
219
|
+
// file that failed or went unread past a limit isn't every page in it leaving. An older crawl is whole when every
|
|
220
|
+
// file answered 200.
|
|
221
|
+
const wholeSitemap = r =>
|
|
222
|
+
(r.pages || []).some(p => p.inSitemap) &&
|
|
223
|
+
(r.stats?.sitemapComplete ?? (r.stats?.sitemapFiles || []).every(f => f.status === 200));
|
|
224
|
+
const sitemaps = wholeSitemap(oldReport) && wholeSitemap(newReport);
|
|
225
|
+
if (sitemaps) compared.add("sitemap");
|
|
226
|
+
// A crawl that stopped at --max, or covered one part of the site (--include/--exclude, recorded as `section`) the
|
|
227
|
+
// other didn't, missed pages the other has: they aren't gone (or new). Internal links and section sizes only when
|
|
228
|
+
// both crawls were whole: linksIn counts links on the pages crawled.
|
|
229
|
+
const capped = r => r.stats?.capped ?? r.stats?.fetched >= r.options?.max;
|
|
230
|
+
const partial = (r, other) =>
|
|
231
|
+
capped(r)
|
|
232
|
+
? true
|
|
233
|
+
: r.section && JSON.stringify(r.section) !== JSON.stringify(other.section ?? null)
|
|
234
|
+
? "section"
|
|
235
|
+
: false;
|
|
236
|
+
const goneUnknown = partial(newReport, oldReport),
|
|
237
|
+
addedUnknown = partial(oldReport, newReport);
|
|
238
|
+
const links = !capped(oldReport) && !capped(newReport) && !oldReport.section && !newReport.section;
|
|
239
|
+
// hreflang targets on the site's own hosts compare by path, so a local crawl matches the live one.
|
|
240
|
+
const hosts = r =>
|
|
241
|
+
new Set(
|
|
242
|
+
[r.startUrl, r.siteOrigin]
|
|
243
|
+
.map(u => {
|
|
244
|
+
try {
|
|
245
|
+
return new URL(u).host;
|
|
246
|
+
} catch {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
})
|
|
250
|
+
.filter(Boolean),
|
|
251
|
+
);
|
|
252
|
+
const ownOld = hosts(oldReport),
|
|
253
|
+
ownNew = hosts(newReport);
|
|
254
|
+
const alternates = (p, own) =>
|
|
255
|
+
(p.hreflang || []).map(h => {
|
|
256
|
+
let t = String(h.href);
|
|
257
|
+
try {
|
|
258
|
+
const u = new URL(t, p.url);
|
|
259
|
+
t = own.has(u.host) || u.host === new URL(p.url).host ? u.pathname + u.search : u.href;
|
|
260
|
+
} catch {}
|
|
261
|
+
return `${String(h.lang).toLowerCase()} → ${t}`;
|
|
262
|
+
});
|
|
263
|
+
const hasRedirects = Array.isArray(oldReport.redirects) && Array.isArray(newReport.redirects);
|
|
264
|
+
const redirectsOf = r => new Map((r.redirects || []).map(x => [pathOf(x.from), x]));
|
|
265
|
+
const wasRedirect = redirectsOf(oldReport),
|
|
266
|
+
nowRedirect = hasRedirects ? redirectsOf(newReport) : new Map();
|
|
267
|
+
for (const [path, o] of before) {
|
|
268
|
+
const n = after.get(path);
|
|
269
|
+
if (!n) continue;
|
|
270
|
+
const change = (list, kind, b, a) => list.push({ path, kind, before: b ?? null, after: a ?? null });
|
|
271
|
+
if (ok(o.status) && !ok(n.status)) {
|
|
272
|
+
change(regressions, "status-error", o.status, n.status);
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
if (!ok(o.status) && ok(n.status)) {
|
|
276
|
+
change(improvements, "status-fixed", o.status, n.status);
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
if (!ok(n.status)) continue;
|
|
280
|
+
if (!o.noindex && n.noindex) change(regressions, "noindex-added", "index", "noindex");
|
|
281
|
+
if (o.noindex && !n.noindex) change(improvements, "noindex-removed", "noindex", "index");
|
|
282
|
+
const oc = o.canonical ? pathOf(o.canonical) : null,
|
|
283
|
+
nc = n.canonical ? pathOf(n.canonical) : null;
|
|
284
|
+
// Better: it now points at itself, or no longer points elsewhere. Worse: it lost its self-canonical or points away.
|
|
285
|
+
if (oc !== nc)
|
|
286
|
+
change(
|
|
287
|
+
nc === path || (nc === null && oc !== path) ? improvements : regressions,
|
|
288
|
+
"canonical-changed",
|
|
289
|
+
o.canonical,
|
|
290
|
+
n.canonical,
|
|
291
|
+
);
|
|
292
|
+
if (o.h1 > 0 && !n.h1) change(regressions, "h1-removed", o.h1, n.h1);
|
|
293
|
+
if (!o.h1 && n.h1 > 0) change(improvements, "h1-added", o.h1, n.h1);
|
|
294
|
+
const os = new Set(o.schema || []),
|
|
295
|
+
ns = new Set(n.schema || []);
|
|
296
|
+
const gone = [...os].filter(t => !ns.has(t)),
|
|
297
|
+
added = [...ns].filter(t => !os.has(t)),
|
|
298
|
+
lost = gone.filter(t => !RETIRED.has(t)),
|
|
299
|
+
retired = gone.filter(t => RETIRED.has(t));
|
|
300
|
+
if (lost.length) change(regressions, "schema-removed", lost.join(", "), [...ns].join(", ") || "none");
|
|
301
|
+
if (retired.length) change(changed, "schema-retired-removed", retired.join(", "), [...ns].join(", ") || "none");
|
|
302
|
+
if (added.length) change(improvements, "schema-added", [...os].join(", ") || "none", added.join(", "));
|
|
303
|
+
if ((o.title || "") !== (n.title || "")) change(n.title ? changed : regressions, "title-changed", o.title, n.title);
|
|
304
|
+
// Fields older crawls didn't record are compared only when both crawls have them.
|
|
305
|
+
const both = k => k in o && k in n;
|
|
306
|
+
if (both("description")) compared.add("description");
|
|
307
|
+
if (both("ogTitle") && both("ogImage")) compared.add("og");
|
|
308
|
+
if (both("words")) compared.add("words");
|
|
309
|
+
if (both("description") && (o.description || "") !== (n.description || ""))
|
|
310
|
+
change(n.description ? changed : regressions, "description-changed", o.description, n.description);
|
|
311
|
+
if (both("h1Text") && o.h1Text && n.h1Text && o.h1Text !== n.h1Text)
|
|
312
|
+
change(changed, "h1-changed", o.h1Text, n.h1Text);
|
|
313
|
+
// H2s that came or went, or a changed count (a repeated heading); a new order alone isn't a change.
|
|
314
|
+
if (both("h2s")) {
|
|
315
|
+
compared.add("h2");
|
|
316
|
+
const went = o.h2s.filter(h => !n.h2s.includes(h)),
|
|
317
|
+
came = n.h2s.filter(h => !o.h2s.includes(h));
|
|
318
|
+
if (went.length || came.length || o.h2s.length !== n.h2s.length)
|
|
319
|
+
changed.push({
|
|
320
|
+
path,
|
|
321
|
+
kind: "h2-changed",
|
|
322
|
+
before: o.h2s.length,
|
|
323
|
+
after: n.h2s.length,
|
|
324
|
+
detail: `${o.h2s.length} → ${n.h2s.length}${went.length || came.length ? `; ${changes(went, came)}` : ""}`,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
// Lost alternates: a regression; only new ones: an improvement; both: a change.
|
|
328
|
+
if (both("hreflang")) {
|
|
329
|
+
compared.add("hreflang");
|
|
330
|
+
const was = alternates(o, ownOld),
|
|
331
|
+
now = alternates(n, ownNew),
|
|
332
|
+
went = was.filter(h => !now.includes(h)),
|
|
333
|
+
came = now.filter(h => !was.includes(h));
|
|
334
|
+
if (went.length || came.length)
|
|
335
|
+
(came.length ? (went.length ? changed : improvements) : regressions).push({
|
|
336
|
+
path,
|
|
337
|
+
kind: "hreflang-changed",
|
|
338
|
+
before: was.join(", ") || "none",
|
|
339
|
+
after: now.join(", ") || "none",
|
|
340
|
+
detail: changes(went, came),
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
if (both("ogTitle") && both("ogImage")) {
|
|
344
|
+
const keys = OG.filter(([k]) => both(k)),
|
|
345
|
+
tags = r =>
|
|
346
|
+
keys
|
|
347
|
+
.filter(([k]) => r[k])
|
|
348
|
+
.map(([, t]) => t)
|
|
349
|
+
.join(", ") || null;
|
|
350
|
+
if (keys.some(([k]) => o[k] && !n[k])) change(regressions, "og-removed", tags(o), tags(n));
|
|
351
|
+
if (keys.some(([k]) => !o[k] && n[k])) change(improvements, "og-added", tags(o), tags(n));
|
|
352
|
+
}
|
|
353
|
+
// Thresholds: at least 50 words, and a third fewer or half as many again.
|
|
354
|
+
if (both("words") && o.words - n.words >= 50 && n.words * 1.5 <= o.words)
|
|
355
|
+
change(regressions, "content-shrunk", o.words, n.words);
|
|
356
|
+
if (both("words") && n.words - o.words >= 50 && n.words >= o.words * 1.5)
|
|
357
|
+
change(changed, "content-grew", o.words, n.words);
|
|
358
|
+
// Noindex pages and pages canonical elsewhere belong out of the sitemap; their own change kind says why.
|
|
359
|
+
if (sitemaps && both("inSitemap") && !n.noindex && (!nc || nc === path)) {
|
|
360
|
+
if (o.inSitemap && !n.inSitemap) change(regressions, "left-sitemap", "listed", "not listed");
|
|
361
|
+
if (!o.inSitemap && n.inSitemap) change(improvements, "joined-sitemap", "not listed", "listed");
|
|
362
|
+
}
|
|
363
|
+
if (links && both("linksIn")) compared.add("links");
|
|
364
|
+
if (links && both("linksIn") && o.linksIn - n.linksIn >= 5 && n.linksIn * 2 <= o.linksIn)
|
|
365
|
+
change(regressions, "lost-internal-links", o.linksIn, n.linksIn);
|
|
366
|
+
// Field names only, per type both crawls have: prices and dates change every crawl.
|
|
367
|
+
if (both("schemaProps")) {
|
|
368
|
+
compared.add("schemaProps");
|
|
369
|
+
for (const [type, was] of Object.entries(o.schemaProps)) {
|
|
370
|
+
const now = n.schemaProps[type];
|
|
371
|
+
if (!now || RETIRED.has(type)) continue;
|
|
372
|
+
const lost = was.filter(k => !now.includes(k)),
|
|
373
|
+
got = now.filter(k => !was.includes(k));
|
|
374
|
+
if (lost.length)
|
|
375
|
+
regressions.push({
|
|
376
|
+
path,
|
|
377
|
+
kind: "schema-fields-removed",
|
|
378
|
+
detail: `${type} lost ${lost.join(", ")}`,
|
|
379
|
+
before: was.join(", "),
|
|
380
|
+
after: now.join(", "),
|
|
381
|
+
});
|
|
382
|
+
if (got.length)
|
|
383
|
+
improvements.push({
|
|
384
|
+
path,
|
|
385
|
+
kind: "schema-fields-added",
|
|
386
|
+
detail: `${type} gained ${got.join(", ")}`,
|
|
387
|
+
before: was.join(", "),
|
|
388
|
+
after: now.join(", "),
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (oldReport.robotsTxt && newReport.robotsTxt) {
|
|
394
|
+
compared.add("robots");
|
|
395
|
+
const c = robotsChange(oldReport.robotsTxt, newReport.robotsTxt);
|
|
396
|
+
if (c) changed.push(c);
|
|
397
|
+
}
|
|
398
|
+
if (hasRedirects) {
|
|
399
|
+
compared.add("redirects");
|
|
400
|
+
for (const [path, n] of nowRedirect) {
|
|
401
|
+
const o = wasRedirect.get(path),
|
|
402
|
+
was = before.get(path);
|
|
403
|
+
// A new target or a loop is a regression; the same target made permanent is an improvement, made temporary a
|
|
404
|
+
// regression. 301 and 308, or 302, 303 and 307, swapping (a server change) is no change.
|
|
405
|
+
const moved = o && target(o) !== target(n);
|
|
406
|
+
if (o && (moved || permanent(o.status) !== permanent(n.status)))
|
|
407
|
+
(moved || permanent(o.status) ? regressions : improvements).push({
|
|
408
|
+
path,
|
|
409
|
+
kind: "redirect-changed",
|
|
410
|
+
before: redirectText(o),
|
|
411
|
+
after: redirectText(n),
|
|
412
|
+
});
|
|
413
|
+
// Only a URL the last crawl had as a page or an error: one first met this time isn't a new redirect.
|
|
414
|
+
if (!o && was) changed.push({ path, kind: "redirect-added", before: was.status, after: redirectText(n) });
|
|
415
|
+
}
|
|
416
|
+
// Only a URL this crawl reached: one no longer linked isn't a removed redirect. Ending in an error is a regression.
|
|
417
|
+
for (const [path, o] of wasRedirect) {
|
|
418
|
+
const now = after.get(path);
|
|
419
|
+
if (now && !nowRedirect.has(path))
|
|
420
|
+
(ok(now.status) ? changed : regressions).push({
|
|
421
|
+
path,
|
|
422
|
+
kind: "redirect-removed",
|
|
423
|
+
before: redirectText(o),
|
|
424
|
+
after: now.status,
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
for (const [source, read, judge, fmt] of SPEED) {
|
|
429
|
+
const was = new Map((read(oldReport) || []).filter(([, v]) => v != null).map(([u, v]) => [pathOf(u), v]));
|
|
430
|
+
for (const [u, now] of read(newReport) || []) {
|
|
431
|
+
const path = pathOf(u),
|
|
432
|
+
old = was.get(path);
|
|
433
|
+
if (now == null || old == null) continue;
|
|
434
|
+
compared.add("speed");
|
|
435
|
+
const v = judge(old, now);
|
|
436
|
+
if (v)
|
|
437
|
+
(v < 0 ? regressions : improvements).push({
|
|
438
|
+
path,
|
|
439
|
+
kind: v < 0 ? "speed-slower" : "speed-faster",
|
|
440
|
+
source,
|
|
441
|
+
before: fmt(old),
|
|
442
|
+
after: fmt(now),
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
// A section that lost half its pages and at least 10 (a deploy dropped the blog) is one regression on top of the
|
|
447
|
+
// pages gone. The list holds 50 sections, so one missing from a full list may just be past the cut.
|
|
448
|
+
if (links && Array.isArray(oldReport.sections) && Array.isArray(newReport.sections)) {
|
|
449
|
+
compared.add("sections");
|
|
450
|
+
const now = new Map(newReport.sections.map(s => [s.path, s.pages]));
|
|
451
|
+
for (const s of oldReport.sections) {
|
|
452
|
+
const n = now.get(s.path) ?? (newReport.sections.length < 50 ? 0 : null);
|
|
453
|
+
if (n != null && s.pages - n >= 10 && n * 2 <= s.pages)
|
|
454
|
+
regressions.push({ path: s.path, kind: "section-shrunk", before: s.pages, after: n });
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
// Only new pages that load: a new URL in the error list is a broken link target, not an added page. A page the last
|
|
458
|
+
// crawl didn't reach (it stopped at --max, or covered another section) isn't known to be new.
|
|
459
|
+
const added = addedUnknown
|
|
460
|
+
? []
|
|
461
|
+
: [...after]
|
|
462
|
+
.filter(([p, n]) => !before.has(p) && ok(n.status))
|
|
463
|
+
.map(([p]) => p)
|
|
464
|
+
.sort(),
|
|
465
|
+
burst = addedBurst(added, before, after);
|
|
466
|
+
return {
|
|
467
|
+
regressions,
|
|
468
|
+
improvements,
|
|
469
|
+
changed,
|
|
470
|
+
compared: [...compared], // the optional fields both crawls recorded, so the report claims only those
|
|
471
|
+
added,
|
|
472
|
+
...(burst ? { addedBurst: burst } : {}),
|
|
473
|
+
// A page that now redirects is redirect-added; a URL that failed last time and isn't met now was never a page.
|
|
474
|
+
// A page this crawl didn't reach isn't known to be gone. The reason is true (--max) or "section".
|
|
475
|
+
removed: goneUnknown
|
|
476
|
+
? []
|
|
477
|
+
: [...before]
|
|
478
|
+
.filter(([p, o]) => ok(o.status) && !after.has(p) && !nowRedirect.has(p))
|
|
479
|
+
.map(([p]) => p)
|
|
480
|
+
.sort(),
|
|
481
|
+
...(goneUnknown ? { removedUnknown: goneUnknown } : {}),
|
|
482
|
+
...(addedUnknown ? { addedUnknown } : {}),
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// One row per crawl, oldest first; each after the first counts its changes from the one before. Unknown counts are
|
|
487
|
+
// null.
|
|
488
|
+
export const timeline = crawls =>
|
|
489
|
+
crawls.map((r, i) => {
|
|
490
|
+
const d = i && diffCrawls(crawls[i - 1], r);
|
|
491
|
+
return {
|
|
492
|
+
date: r.crawledAt,
|
|
493
|
+
pages: (r.pages || []).length,
|
|
494
|
+
findings: Array.isArray(r.findings) ? r.findings.length : null,
|
|
495
|
+
...(d && {
|
|
496
|
+
regressions: d.regressions.length,
|
|
497
|
+
improvements: d.improvements.length,
|
|
498
|
+
added: d.addedUnknown ? null : d.added.length,
|
|
499
|
+
removed: d.removedUnknown ? null : d.removed.length,
|
|
500
|
+
}),
|
|
501
|
+
};
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
// One crawl per crawledAt, oldest first; an unreadable file is named and skipped. Holds every crawl in memory at
|
|
505
|
+
// once; for hundreds of history files, keep only the newest ones.
|
|
506
|
+
function filed(dir) {
|
|
507
|
+
const byTime = new Map();
|
|
508
|
+
for (const f of existsSync(dir)
|
|
509
|
+
? readdirSync(dir)
|
|
510
|
+
.filter(f => f.endsWith("-seo-crawl.json"))
|
|
511
|
+
.sort()
|
|
512
|
+
: []) {
|
|
513
|
+
let r = null;
|
|
514
|
+
try {
|
|
515
|
+
r = JSON.parse(readFileSync(join(dir, f), "utf8"));
|
|
516
|
+
} catch {}
|
|
517
|
+
if (typeof r?.crawledAt === "string") byTime.set(r.crawledAt, r);
|
|
518
|
+
else console.error(`seo-diff: skipped ${f} in ${dir}: it isn't a readable crawl.`);
|
|
519
|
+
}
|
|
520
|
+
return [...byTime.values()].sort((a, b) => (a.crawledAt < b.crawledAt ? -1 : 1));
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// Files a crawl in the history folder under its date, or its date and time when another crawl has that day; never over
|
|
524
|
+
// another crawl, and not again when a crawl with its crawledAt is there. Returns the path it wrote, or null.
|
|
525
|
+
export function fileCrawl(hist, file, crawl) {
|
|
526
|
+
if (typeof crawl?.crawledAt !== "string" || filed(hist).some(r => r.crawledAt === crawl.crawledAt)) return null;
|
|
527
|
+
const day = join(hist, `${crawl.crawledAt.slice(0, 10)}-seo-crawl.json`),
|
|
528
|
+
at = join(hist, `${crawl.crawledAt.slice(0, 19).replace(/:/g, "-")}-seo-crawl.json`);
|
|
529
|
+
mkdirSync(hist, { recursive: true });
|
|
530
|
+
const to = existsSync(day) ? at : day;
|
|
531
|
+
copyFileSync(file, to);
|
|
532
|
+
return to;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
const USAGE = `usage: node seo-diff.mjs old-crawl.json new-crawl.json [--out seo-audit/seo-diff.json]
|
|
536
|
+
node seo-diff.mjs --history seo-audit/history new-crawl.json [--out <file>]
|
|
537
|
+
[--fail-on-regressions]
|
|
538
|
+
|
|
539
|
+
What changed between two crawls from seo-crawl.mjs, matched by path. Reads local files only.
|
|
540
|
+
--out <file> where the diff is written (default seo-audit/seo-diff.json)
|
|
541
|
+
--history <folder> compare with the newest crawl filed there, add a timeline of every crawl
|
|
542
|
+
there, and file this one too (the first crawl is only filed)
|
|
543
|
+
--fail-on-regressions exit 1 after writing if anything got worse, so a scheduled run can alert
|
|
544
|
+
--help, -h show this help`;
|
|
545
|
+
|
|
546
|
+
if (isMain(import.meta.url))
|
|
547
|
+
await runMain(() => {
|
|
548
|
+
const args = parseArgs(process.argv.slice(2), {
|
|
549
|
+
flags: ["out", "history"],
|
|
550
|
+
booleans: ["fail-on-regressions"],
|
|
551
|
+
usage: USAGE,
|
|
552
|
+
});
|
|
553
|
+
const str = k => (typeof args[k] === "string" ? args[k] : null),
|
|
554
|
+
files = args._;
|
|
555
|
+
const hist = str("history"),
|
|
556
|
+
out = resolve(str("out") || "seo-audit/seo-diff.json");
|
|
557
|
+
if (files.length !== (hist ? 1 : 2)) throw new Fail(USAGE, 1);
|
|
558
|
+
const crawls = files.map(f => JSON.parse(readFileSync(f, "utf8"))),
|
|
559
|
+
newR = crawls.at(-1);
|
|
560
|
+
let oldR = crawls[0],
|
|
561
|
+
rows = null;
|
|
562
|
+
if (hist) {
|
|
563
|
+
if (typeof newR.crawledAt !== "string")
|
|
564
|
+
throw new Fail(`seo-diff: ${files[0]} has no crawledAt, so it isn't a crawl from seo-crawl.mjs.`, 1);
|
|
565
|
+
const past = filed(hist),
|
|
566
|
+
earlier = past.filter(r => r.crawledAt < newR.crawledAt);
|
|
567
|
+
fileCrawl(hist, files[0], newR);
|
|
568
|
+
oldR = earlier.at(-1);
|
|
569
|
+
rows = oldR && timeline([...earlier, newR]);
|
|
570
|
+
}
|
|
571
|
+
if (!oldR)
|
|
572
|
+
console.log(
|
|
573
|
+
`seo-diff: no earlier crawl in ${hist}, so nothing to compare. This crawl is filed there for the next run.`,
|
|
574
|
+
);
|
|
575
|
+
else {
|
|
576
|
+
const diff = { since: oldR.crawledAt || null, ...diffCrawls(oldR, newR), ...(rows ? { timeline: rows } : {}) };
|
|
577
|
+
mkdirSync(dirname(out), { recursive: true });
|
|
578
|
+
writeFileSync(out, JSON.stringify(diff, null, 2));
|
|
579
|
+
console.log(
|
|
580
|
+
`seo-diff: ${diff.regressions.length} regressions, ${diff.improvements.length} improvements, ${diff.added.length} pages added, ${diff.removed.length} gone · wrote ${out}`,
|
|
581
|
+
);
|
|
582
|
+
if (args["fail-on-regressions"] && diff.regressions.length) return 1;
|
|
583
|
+
}
|
|
584
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @ts-check
|
|
3
|
+
// Weekly at most, says when a newer version is on npm. It never updates anything and sends only the package name.
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { isMain } from "./lib/is-main.mjs";
|
|
7
|
+
import { runMain } from "./lib/cli.mjs";
|
|
8
|
+
import { parseArgs } from "./lib/args.mjs";
|
|
9
|
+
import { settingsDir } from "./lib/settings-dir.mjs";
|
|
10
|
+
|
|
11
|
+
export const VERSION = "2.0.0"; // kept equal to package.json by test/update-check.test.mjs
|
|
12
|
+
const WEEK = 7 * 864e5;
|
|
13
|
+
const dir = () => settingsDir(); // ~/.seo-supervisor, or SEO_SUPERVISOR_HOME
|
|
14
|
+
const readJson = f => {
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(readFileSync(f, "utf8"));
|
|
17
|
+
} catch {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const writeJson = (f, data) => {
|
|
22
|
+
mkdirSync(dir(), { recursive: true });
|
|
23
|
+
writeFileSync(f, JSON.stringify(data, null, 2) + "\n");
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// Numeric, so "2.10.0" > "2.9.9". A pre-release or anything unparsable is never newer.
|
|
27
|
+
export function isNewer(candidate, current) {
|
|
28
|
+
const parse = v => (/^\d+\.\d+\.\d+$/.test(String(v)) ? String(v).split(".").map(Number) : null);
|
|
29
|
+
const a = parse(candidate),
|
|
30
|
+
b = parse(current);
|
|
31
|
+
if (!a || !b) return false;
|
|
32
|
+
for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] > b[i];
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function checkForUpdate({ env = process.env, now = Date.now(), fetchFn = fetch } = {}) {
|
|
37
|
+
const settingsFile = join(dir(), "settings.json"),
|
|
38
|
+
cacheFile = join(dir(), "update-check.json");
|
|
39
|
+
if (env.SEO_SUPERVISOR_NO_UPDATE_CHECK || env.CI || readJson(settingsFile).updateCheck === false) return null;
|
|
40
|
+
let { checkedAt, latest } = readJson(cacheFile);
|
|
41
|
+
if (!checkedAt || now - Date.parse(checkedAt) > WEEK || Number.isNaN(Date.parse(checkedAt))) {
|
|
42
|
+
try {
|
|
43
|
+
const registry = (env.SEO_SUPERVISOR_REGISTRY || "https://registry.npmjs.org").replace(/\/$/, "");
|
|
44
|
+
const r = await fetchFn(`${registry}/seo-supervisor/latest`, { signal: AbortSignal.timeout(3000) });
|
|
45
|
+
if (!r.ok) return null;
|
|
46
|
+
latest = /** @type {any} */ (await r.json()).version;
|
|
47
|
+
writeJson(cacheFile, { checkedAt: new Date(now).toISOString(), latest });
|
|
48
|
+
} catch {
|
|
49
|
+
return null;
|
|
50
|
+
} // offline or blocked: say nothing
|
|
51
|
+
}
|
|
52
|
+
return isNewer(latest, VERSION) ? latest : null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const USAGE = `usage: node update-check.mjs say when a newer SEO Supervisor is on npm (weekly at most)
|
|
56
|
+
node update-check.mjs off|on turn the weekly check off or on again
|
|
57
|
+
|
|
58
|
+
It never updates anything itself, and it sends npm nothing but the package name. Also off with
|
|
59
|
+
SEO_SUPERVISOR_NO_UPDATE_CHECK=1, and in CI.
|
|
60
|
+
--help, -h show this help`;
|
|
61
|
+
|
|
62
|
+
if (isMain(import.meta.url))
|
|
63
|
+
await runMain(async () => {
|
|
64
|
+
// No option list: the weekly check takes any other words and still exits 0; only --help or -h stops it.
|
|
65
|
+
const [cmd] = parseArgs(process.argv.slice(2), { usage: USAGE })._;
|
|
66
|
+
// A bad SEO_SUPERVISOR_HOME can't save the setting; runMain prints one plain line and exits 2.
|
|
67
|
+
if (cmd === "off" || cmd === "on") {
|
|
68
|
+
const f = join(dir(), "settings.json");
|
|
69
|
+
writeJson(f, { ...readJson(f), updateCheck: cmd === "on" });
|
|
70
|
+
console.log(
|
|
71
|
+
cmd === "off"
|
|
72
|
+
? "Update notices turned off. Turn them on again with: node update-check.mjs on"
|
|
73
|
+
: "Update notices turned on (npm is checked at most once a week).",
|
|
74
|
+
);
|
|
75
|
+
} else {
|
|
76
|
+
const latest = await checkForUpdate().catch(() => null);
|
|
77
|
+
if (latest)
|
|
78
|
+
console.log(
|
|
79
|
+
`SEO Supervisor ${latest} is out (you have ${VERSION}). Update with: npx seo-supervisor@latest (plugin installs: update it from Claude Code's /plugin menu). Turn these notices off: node update-check.mjs off`,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
});
|