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,412 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @ts-check
|
|
3
|
+
// Checks that known backlinks still exist: opens each linking page and looks for an <a href> to the site.
|
|
4
|
+
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
5
|
+
import { lookup } from "node:dns";
|
|
6
|
+
import { dirname, resolve } from "node:path";
|
|
7
|
+
import { isMain } from "./lib/is-main.mjs";
|
|
8
|
+
import { parseCsv } from "./lib/csv.mjs";
|
|
9
|
+
import { parseArgs } from "./lib/args.mjs";
|
|
10
|
+
import { Fail, runMain, warnProxy } from "./lib/cli.mjs";
|
|
11
|
+
import { isPublic, pinnedGet } from "./lib/net.mjs";
|
|
12
|
+
import { foundOn } from "./lib/findings.mjs";
|
|
13
|
+
|
|
14
|
+
const USAGE =
|
|
15
|
+
"usage: node backlinks.mjs --site https://www.example.com (--keys seo-audit/keys.json | --csv links.csv | --urls links.txt) [--out seo-audit/backlinks.json] [--yes]";
|
|
16
|
+
const UA = "seo-supervisor-backlinks",
|
|
17
|
+
MAX = 100,
|
|
18
|
+
AT_ONCE = 4,
|
|
19
|
+
HOPS = 5,
|
|
20
|
+
MB = 5,
|
|
21
|
+
CAP = MB * 1024 * 1024;
|
|
22
|
+
const fail = msg => {
|
|
23
|
+
throw new Fail("backlinks: " + msg);
|
|
24
|
+
};
|
|
25
|
+
const obj = x => (x && typeof x === "object" ? x : null);
|
|
26
|
+
const bare = h => h.toLowerCase().replace(/^www\./, "");
|
|
27
|
+
|
|
28
|
+
const ATTR = /([^\s"'=<>/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+)))?/g;
|
|
29
|
+
const attrs = tag => {
|
|
30
|
+
const a = {};
|
|
31
|
+
for (const m of tag.replace(/^<\w+|>$/g, "").matchAll(ATTR)) a[m[1].toLowerCase()] ??= m[2] ?? m[3] ?? m[4] ?? "";
|
|
32
|
+
return a;
|
|
33
|
+
};
|
|
34
|
+
const ENT = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: " " };
|
|
35
|
+
const decode = s =>
|
|
36
|
+
s.replace(/&(#x[0-9a-f]{1,6}|#\d{1,7}|\w+);/gi, (m, e) => {
|
|
37
|
+
if (e[0] !== "#") return ENT[e.toLowerCase()] ?? m;
|
|
38
|
+
const n = e[1].toLowerCase() === "x" ? parseInt(e.slice(2), 16) : Number(e.slice(1));
|
|
39
|
+
return n <= 0x10ffff ? String.fromCodePoint(n) : m;
|
|
40
|
+
});
|
|
41
|
+
// A link through a redirect wrapper (youtube.com/redirect?q=…, l.facebook.com/l.php?u=…) counts for the address it
|
|
42
|
+
// wraps.
|
|
43
|
+
const WRAPS = ["q", "u", "url", "target", "to", "dest"];
|
|
44
|
+
const wrapped = u =>
|
|
45
|
+
WRAPS.flatMap(k => u.searchParams.getAll(k)).flatMap(v => {
|
|
46
|
+
try {
|
|
47
|
+
return [new URL(v)];
|
|
48
|
+
} catch {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
const clean = html => html.replace(/<!--[\s\S]*?-->|<script\b[\s\S]*?<\/script>/gi, "");
|
|
53
|
+
// Each <a href> to the site as { href, text, rel }; www, the bare domain, http and https are one site. Text falls back
|
|
54
|
+
// to an image's alt, and rel keeps only nofollow, sponsored and ugc.
|
|
55
|
+
// Raw HTML only: links a script adds aren't seen, and unread() guesses when that's the case.
|
|
56
|
+
export function linksTo(html, base, host) {
|
|
57
|
+
const out = [],
|
|
58
|
+
page = clean(html);
|
|
59
|
+
for (const m of page.matchAll(/<a\s[^>]*>/gi)) {
|
|
60
|
+
const a = attrs(m[0]);
|
|
61
|
+
let u;
|
|
62
|
+
try {
|
|
63
|
+
u = new URL(decode(a.href.trim()), base);
|
|
64
|
+
} catch {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (!/^https?:$/.test(u.protocol)) continue;
|
|
68
|
+
const to = [u, ...wrapped(u)].find(t => /^https?:$/.test(t.protocol) && bare(t.hostname) === host);
|
|
69
|
+
if (!to) continue;
|
|
70
|
+
const inner = page.slice(m.index + m[0].length, m.index + m[0].length + 3000).split(/<\/a\s*>|<a\s/i)[0];
|
|
71
|
+
const words = decode(inner.replace(/<[^>]*>/g, " "))
|
|
72
|
+
.replace(/\s+/g, " ")
|
|
73
|
+
.trim();
|
|
74
|
+
const alt = /<img\s[^>]*>/i.exec(inner);
|
|
75
|
+
const text = (
|
|
76
|
+
words ||
|
|
77
|
+
(alt
|
|
78
|
+
? decode(attrs(alt[0]).alt || "")
|
|
79
|
+
.replace(/\s+/g, " ")
|
|
80
|
+
.trim()
|
|
81
|
+
: "")
|
|
82
|
+
).slice(0, 200);
|
|
83
|
+
out.push({
|
|
84
|
+
href: to.href,
|
|
85
|
+
text,
|
|
86
|
+
rel: (a.rel || "")
|
|
87
|
+
.toLowerCase()
|
|
88
|
+
.split(/\s+/)
|
|
89
|
+
.filter(t => ["nofollow", "sponsored", "ugc"].includes(t))
|
|
90
|
+
.join(" "),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// A page-wide nofollow or none, in a robots or googlebot meta tag or an X-Robots-Tag line for all crawlers or
|
|
97
|
+
// googlebot. Rules for another crawler ("bingbot: nofollow") don't count.
|
|
98
|
+
// https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag
|
|
99
|
+
const NOFOLLOW = /^(nofollow|none)$/i;
|
|
100
|
+
export function pageNofollow(html, headerLines = []) {
|
|
101
|
+
const metas = [...clean(html).matchAll(/<meta\s[^>]*>/gi)]
|
|
102
|
+
.map(([t]) => attrs(t))
|
|
103
|
+
.filter(a => /^(robots|googlebot)$/i.test((a.name || "").trim()));
|
|
104
|
+
if (
|
|
105
|
+
metas.some(a =>
|
|
106
|
+
decode(a.content || "")
|
|
107
|
+
.split(",")
|
|
108
|
+
.some(r => NOFOLLOW.test(r.trim())),
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
return "robots meta tag";
|
|
112
|
+
for (const line of headerLines) {
|
|
113
|
+
let bot = null;
|
|
114
|
+
for (const part of String(line).split(",")) {
|
|
115
|
+
const m = /^\s*([a-z][\w-]*)\s*:\s*(.*)$/i.exec(part),
|
|
116
|
+
rule =
|
|
117
|
+
m && !/^(unavailable_after|max-snippet|max-image-preview|max-video-preview)$/i.test(m[1])
|
|
118
|
+
? ((bot = m[1].toLowerCase()), m[2])
|
|
119
|
+
: part;
|
|
120
|
+
if ((!bot || bot === "googlebot") && NOFOLLOW.test(rule.trim())) return "X-Robots-Tag header";
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
// X-Robots-Tag lines from rawHeaders, kept apart because a `bot:` prefix scopes only its own line.
|
|
126
|
+
const robotsLines = raw => raw.flatMap((v, i) => (i % 2 && raw[i - 1].toLowerCase() === "x-robots-tag" ? [v] : []));
|
|
127
|
+
|
|
128
|
+
// Why a page without the link may not really be gone: truncated, behind a consent screen, built by a script, or naming
|
|
129
|
+
// the site without a link. "" when the page was clearly read.
|
|
130
|
+
// Heuristics on text size and keywords; a headless browser would settle them, at the cost of a dependency.
|
|
131
|
+
function unread(page, cut, moved, host) {
|
|
132
|
+
if (cut) return `the page is very large: only its first ${MB} MB were read, and the link isn't in them`;
|
|
133
|
+
const html = page.replace(/<!--[\s\S]*?-->|<(script|style|noscript|template|svg)\b[\s\S]*?<\/\1\s*>/gi, " ");
|
|
134
|
+
const text = html
|
|
135
|
+
.replace(/<[^>]*>/g, " ")
|
|
136
|
+
.replace(/&#?\w+;/g, " ")
|
|
137
|
+
.replace(/\s+/g, " ")
|
|
138
|
+
.trim();
|
|
139
|
+
if (
|
|
140
|
+
(moved && /consent|gdpr|cookie/i.test(new URL(moved).hostname + new URL(moved).pathname)) ||
|
|
141
|
+
(text.length < 2000 && /\bcookies?\b/i.test(text) && /\b(accept|agree|reject|consent)/i.test(text))
|
|
142
|
+
)
|
|
143
|
+
return "it shows a cookie or privacy consent screen instead of the page, so its links couldn't be read";
|
|
144
|
+
if (
|
|
145
|
+
text.length < 200 ||
|
|
146
|
+
/<(\w+)\b[^>]*\bid\s*=\s*["']?(root|app|__next|__nuxt|react-root|app-root|__pws_root__)(?=["'\s>])[^>]*>\s*<\/\1>/i.test(
|
|
147
|
+
html,
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
return "it looks built by JavaScript: its HTML has almost no content, so its links couldn't be read";
|
|
151
|
+
if (!/<a\s/i.test(html)) return "the page has no links at all in its HTML, so a script probably adds them";
|
|
152
|
+
if (new RegExp(`(^|[^\\w.-])(www\\.)?${host.replace(/\./g, "\\.")}(?![\\w-]|\\.\\w)`, "i").test(page))
|
|
153
|
+
return `the page mentions ${host} but no link to it was found (a script may add it), so it couldn't be confirmed`;
|
|
154
|
+
return "";
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// pinnedGet follows redirects by hand so every hop gets the public-address check. robots.txt isn't read: each visit is
|
|
158
|
+
// one requested page, like opening it in a browser, not a crawl.
|
|
159
|
+
async function visit(url, host, allow, timeout, dns) {
|
|
160
|
+
const no = reason => ({ state: "unreachable", reason });
|
|
161
|
+
const read = async (r, u) => {
|
|
162
|
+
const status = r.statusCode,
|
|
163
|
+
ok = status >= 200 && status < 300,
|
|
164
|
+
type = (r.headers["content-type"] || "").split(";")[0].trim();
|
|
165
|
+
if (!ok || (type && !/html/i.test(type))) r.destroy();
|
|
166
|
+
if (status === 404 || status === 410)
|
|
167
|
+
return {
|
|
168
|
+
state: "gone",
|
|
169
|
+
reason: `the page answered ${status}: ${status === 404 ? "it no longer exists" : "it was removed"}`,
|
|
170
|
+
};
|
|
171
|
+
if (!ok)
|
|
172
|
+
return no(
|
|
173
|
+
`the site answered ${status}${status === 401 || status === 403 ? ", turning the visit away" : status >= 500 ? ", an error on their side" : ""}`,
|
|
174
|
+
);
|
|
175
|
+
if (type && !/html/i.test(type)) return no(`it isn't a web page (${type}), so its links couldn't be read`);
|
|
176
|
+
const chunks = [];
|
|
177
|
+
let n = 0;
|
|
178
|
+
for await (const c of r) {
|
|
179
|
+
chunks.push(c);
|
|
180
|
+
if ((n += c.length) > CAP) break;
|
|
181
|
+
}
|
|
182
|
+
const page = Buffer.concat(chunks).toString();
|
|
183
|
+
if (!type && !/<!doctype html|<html[\s>]/i.test(page.slice(0, 1024)))
|
|
184
|
+
return no(
|
|
185
|
+
"it didn't say what kind of file it is and doesn't look like a web page, so its links couldn't be read",
|
|
186
|
+
);
|
|
187
|
+
const links = linksTo(page, u, host);
|
|
188
|
+
if (links.length)
|
|
189
|
+
return {
|
|
190
|
+
state: "live",
|
|
191
|
+
rel: links.every(l => l.rel) ? [...new Set(links.flatMap(l => l.rel.split(" ")))].join(" ") : null,
|
|
192
|
+
links: links.slice(0, 5),
|
|
193
|
+
page: pageNofollow(page, robotsLines(r.rawHeaders)),
|
|
194
|
+
};
|
|
195
|
+
const why = unread(page, n > CAP, u !== url && u, host);
|
|
196
|
+
return why
|
|
197
|
+
? no(why)
|
|
198
|
+
: {
|
|
199
|
+
state: "gone",
|
|
200
|
+
reason: `the page loads but no longer links to your site${u !== url ? `; it now redirects to ${u}` : ""}`,
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
const r = await pinnedGet(url, {
|
|
204
|
+
allow,
|
|
205
|
+
timeout,
|
|
206
|
+
dns,
|
|
207
|
+
hops: HOPS,
|
|
208
|
+
read,
|
|
209
|
+
headers: { "user-agent": UA, accept: "text/html,application/xhtml+xml" },
|
|
210
|
+
});
|
|
211
|
+
return r.state ? r : no(r.reason);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// A #fragment is the same page.
|
|
215
|
+
const pick = urls => {
|
|
216
|
+
const all = [
|
|
217
|
+
...new Set(
|
|
218
|
+
urls.map(s => {
|
|
219
|
+
try {
|
|
220
|
+
const u = new URL(s);
|
|
221
|
+
u.hash = "";
|
|
222
|
+
return u.href;
|
|
223
|
+
} catch {
|
|
224
|
+
return String(s);
|
|
225
|
+
}
|
|
226
|
+
}),
|
|
227
|
+
),
|
|
228
|
+
];
|
|
229
|
+
return { list: all.slice(0, MAX), extra: Math.max(0, all.length - MAX) };
|
|
230
|
+
};
|
|
231
|
+
const capNote = extra => `${extra} more linking page(s) weren't checked: at most ${MAX} are visited per run.`;
|
|
232
|
+
|
|
233
|
+
// Linking sites whose every live page holds its links back (rel or page-wide nofollow), most pages first.
|
|
234
|
+
// https://developers.google.com/search/docs/crawling-indexing/qualify-outbound-links
|
|
235
|
+
export function allNofollow(live) {
|
|
236
|
+
const sites = new Map();
|
|
237
|
+
for (const r of live) {
|
|
238
|
+
let h;
|
|
239
|
+
try {
|
|
240
|
+
h = bare(new URL(r.url).hostname);
|
|
241
|
+
} catch {
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
const s = sites.get(h) || { site: h, pages: 0, followed: false };
|
|
245
|
+
s.pages++;
|
|
246
|
+
s.followed ||= !(r.rel || r.page);
|
|
247
|
+
sites.set(h, s);
|
|
248
|
+
}
|
|
249
|
+
return [...sites.values()]
|
|
250
|
+
.filter(s => !s.followed)
|
|
251
|
+
.sort((a, b) => b.pages - a.pages)
|
|
252
|
+
.map(({ site, pages }) => ({ site, pages }));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// `allow` vets each address before a request; `dns` (dns.lookup's signature) resolves the address checked and used.
|
|
256
|
+
export async function checkBacklinks(urls, site, { allow = isPublic, timeout = 15000, dns = lookup } = {}) {
|
|
257
|
+
const host = bare(new URL(site).hostname),
|
|
258
|
+
{ list, extra } = pick(urls),
|
|
259
|
+
results = [];
|
|
260
|
+
let next = 0;
|
|
261
|
+
await Promise.all(
|
|
262
|
+
Array.from({ length: Math.min(AT_ONCE, list.length) }, async () => {
|
|
263
|
+
while (next < list.length) {
|
|
264
|
+
const i = next++;
|
|
265
|
+
results[i] = { url: list[i], ...(await visit(list[i], host, allow, timeout, dns)) };
|
|
266
|
+
}
|
|
267
|
+
}),
|
|
268
|
+
);
|
|
269
|
+
const of = state => results.filter(r => r.state === state);
|
|
270
|
+
const gone = of("gone").map(({ url, reason }) => ({ url, reason }));
|
|
271
|
+
// A page is nofollow when every link to the site carries a rel value, or the whole page is nofollow.
|
|
272
|
+
const backlinks = {
|
|
273
|
+
when: new Date().toISOString(),
|
|
274
|
+
checked: list.length,
|
|
275
|
+
live: of("live").length,
|
|
276
|
+
gone,
|
|
277
|
+
unreachable: of("unreachable").map(({ url, reason }) => ({ url, reason })),
|
|
278
|
+
nofollow: of("live")
|
|
279
|
+
.filter(r => r.rel || r.page)
|
|
280
|
+
.map(({ url, rel, page }) => ({ url, rel: rel || "nofollow", ...(page && { page }) })),
|
|
281
|
+
nofollowSites: allNofollow(of("live")),
|
|
282
|
+
found: of("live").map(({ url, links, page }) => ({ url, links, ...(page && { pageNofollow: page }) })),
|
|
283
|
+
};
|
|
284
|
+
const findings = gone.length
|
|
285
|
+
? [
|
|
286
|
+
{
|
|
287
|
+
id: "B-001",
|
|
288
|
+
check: "backlinks-gone",
|
|
289
|
+
rule: "LAUNCH-05",
|
|
290
|
+
severity: "low",
|
|
291
|
+
category: "Launch & monitoring",
|
|
292
|
+
title: `${gone.length} known link(s) from other sites are gone`,
|
|
293
|
+
what: foundOn(gone.length, { url: gone[0].url, detail: gone[0].reason }),
|
|
294
|
+
why: "Links from other sites help search engines find your pages and trust them. After a redesign or a move, links quietly break or get removed, and what they brought goes with them.",
|
|
295
|
+
fix: "Open each page in a browser first to confirm the link is really gone. If the page still mentions you, ask the site to put the link back or update it. If the link pointed at a page of yours that moved or no longer works, redirect that old address to the closest live page with a 301, then ask the site to update the link.",
|
|
296
|
+
count: gone.length,
|
|
297
|
+
evidence: gone.map(g => ({ url: g.url, detail: g.reason })),
|
|
298
|
+
source: "backlinks",
|
|
299
|
+
status: "open",
|
|
300
|
+
},
|
|
301
|
+
]
|
|
302
|
+
: [];
|
|
303
|
+
return { backlinks, findings, notes: extra ? [capNote(extra)] : [] };
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export const summary = b =>
|
|
307
|
+
`${b.live} of ${b.checked} known ${b.checked === 1 ? "link is" : "links are"} still there; ${b.gone.length} gone; ${b.unreachable.length} couldn't be checked`;
|
|
308
|
+
|
|
309
|
+
// ---------- inputs ----------
|
|
310
|
+
const read = f => {
|
|
311
|
+
try {
|
|
312
|
+
return readFileSync(f, "utf8");
|
|
313
|
+
} catch (e) {
|
|
314
|
+
fail(`can't read ${f} (${e.code || e.message})`);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
// keys.json, or an audit JSON with bing copied in. backlinks.sample lists linking pages; .pages are the site's own.
|
|
318
|
+
function fromKeys(f) {
|
|
319
|
+
let j;
|
|
320
|
+
try {
|
|
321
|
+
j = JSON.parse(read(f));
|
|
322
|
+
} catch (e) {
|
|
323
|
+
if (e instanceof Fail) throw e;
|
|
324
|
+
fail(`${f} isn't JSON. Pass the keys.json that connect-keys.mjs fetch writes.`);
|
|
325
|
+
}
|
|
326
|
+
const sample = obj(obj(obj(j)?.bing)?.backlinks)?.sample;
|
|
327
|
+
return (Array.isArray(sample) ? sample : []).map(s => obj(s)?.url).filter(u => typeof u === "string");
|
|
328
|
+
}
|
|
329
|
+
// Search Console's "Latest links" export names the column "Linking page" in English; in another UI language it's
|
|
330
|
+
// the first column that holds URLs.
|
|
331
|
+
function fromCsv(f) {
|
|
332
|
+
const rows = parseCsv(read(f)),
|
|
333
|
+
heads = Object.keys(rows[0] || {});
|
|
334
|
+
const col =
|
|
335
|
+
heads.find(h => /^linking page$/i.test(h)) ||
|
|
336
|
+
heads.find(h => rows.some(r => r[h]) && rows.every(r => !r[h] || /^https?:\/\//i.test(r[h])));
|
|
337
|
+
if (!col)
|
|
338
|
+
fail(
|
|
339
|
+
`${f} has no "Linking page" column. In Search Console open Links, then Export external links → Latest links, and pass that CSV.`,
|
|
340
|
+
);
|
|
341
|
+
return rows.map(r => r[col]).filter(Boolean);
|
|
342
|
+
}
|
|
343
|
+
const fromText = f =>
|
|
344
|
+
read(f)
|
|
345
|
+
.split(/\r?\n/)
|
|
346
|
+
.map(s => s.trim())
|
|
347
|
+
.filter(s => s && !s.startsWith("#"))
|
|
348
|
+
.map(s => (/^[a-z][a-z0-9+.-]*:/i.test(s) ? s : "https://" + s));
|
|
349
|
+
// commoncrawl.mjs reads the same three inputs.
|
|
350
|
+
export const linkingPages = ({ keys, csv, urls }) => [
|
|
351
|
+
...(keys ? fromKeys(keys) : []),
|
|
352
|
+
...(csv ? fromCsv(csv) : []),
|
|
353
|
+
...(urls ? fromText(urls) : []),
|
|
354
|
+
];
|
|
355
|
+
|
|
356
|
+
async function main(argv) {
|
|
357
|
+
const args = parseArgs(argv, {
|
|
358
|
+
flags: ["site", "keys", "csv", "urls", "out"],
|
|
359
|
+
booleans: ["yes"],
|
|
360
|
+
positionals: 0,
|
|
361
|
+
usage: USAGE,
|
|
362
|
+
});
|
|
363
|
+
const str = k => (typeof args[k] === "string" ? args[k] : null);
|
|
364
|
+
if (!str("site") || !(str("keys") || str("csv") || str("urls"))) throw new Fail(USAGE);
|
|
365
|
+
let site;
|
|
366
|
+
try {
|
|
367
|
+
site = new URL(args.site);
|
|
368
|
+
} catch {}
|
|
369
|
+
if (!site || !/^https?:$/.test(site.protocol))
|
|
370
|
+
fail(`--site must be the site's address, like https://www.example.com (got ${args.site})`);
|
|
371
|
+
const urls = linkingPages({ keys: str("keys"), csv: str("csv"), urls: str("urls") });
|
|
372
|
+
const { list, extra } = pick(urls);
|
|
373
|
+
if (!list.length) {
|
|
374
|
+
console.log("backlinks: the files given list no linking pages, so there's nothing to check.");
|
|
375
|
+
return 0;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// Visiting other people's sites is an outside action, so it waits for --yes.
|
|
379
|
+
if (!args.yes) {
|
|
380
|
+
const hosts = {},
|
|
381
|
+
refused = list.filter(u => !isPublic(u));
|
|
382
|
+
for (const u of list)
|
|
383
|
+
if (isPublic(u)) {
|
|
384
|
+
const h = new URL(u).hostname;
|
|
385
|
+
hosts[h] = (hosts[h] || 0) + 1;
|
|
386
|
+
}
|
|
387
|
+
const top = Object.entries(hosts).sort((a, b) => b[1] - a[1]);
|
|
388
|
+
console.log(
|
|
389
|
+
[
|
|
390
|
+
`backlinks: dry run, nothing visited. With --yes it would visit ${list.length - refused.length} page(s) on ${top.length} site(s), ${AT_ONCE} at a time, to see whether each still links to ${site.hostname}:`,
|
|
391
|
+
...top.slice(0, 20).map(([h, n]) => ` ${h}: ${n}`),
|
|
392
|
+
...(top.length > 20 ? [` … and ${top.length - 20} more sites`] : []),
|
|
393
|
+
...(refused.length
|
|
394
|
+
? [`${refused.length} address${refused.length === 1 ? " isn't" : "es aren't"} public and would be skipped.`]
|
|
395
|
+
: []),
|
|
396
|
+
...(extra ? [capNote(extra)] : []),
|
|
397
|
+
"These are other people's sites, visited from this computer: re-run with --yes once the owner agrees.",
|
|
398
|
+
].join("\n"),
|
|
399
|
+
);
|
|
400
|
+
return 0;
|
|
401
|
+
}
|
|
402
|
+
warnProxy();
|
|
403
|
+
const result = await checkBacklinks(list, site.href);
|
|
404
|
+
const out = resolve(str("out") || "seo-audit/backlinks.json");
|
|
405
|
+
mkdirSync(dirname(out), { recursive: true });
|
|
406
|
+
writeFileSync(out, JSON.stringify(result, null, 2));
|
|
407
|
+
for (const n of result.notes) console.log("backlinks: " + n);
|
|
408
|
+
console.log(`backlinks: ${summary(result.backlinks)} · wrote ${out}`);
|
|
409
|
+
return 0;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if (isMain(import.meta.url)) await runMain(() => main(process.argv.slice(2)));
|