@cmo-so/mcp 0.12.11 → 0.12.13
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/dist/cmo-mcp.mjs +1667 -31
- package/package.json +1 -1
package/dist/cmo-mcp.mjs
CHANGED
|
@@ -7199,7 +7199,7 @@ var require_dist = __commonJS({
|
|
|
7199
7199
|
// package.json
|
|
7200
7200
|
var package_default = {
|
|
7201
7201
|
name: "@cmo-so/cli",
|
|
7202
|
-
version: "0.12.
|
|
7202
|
+
version: "0.12.13",
|
|
7203
7203
|
description: "CMO.so on the command line: your websites, ideas, blog posts, LinkedIn queue and results, plus a local MCP server for Claude Desktop, Cursor and other MCP clients.",
|
|
7204
7204
|
type: "module",
|
|
7205
7205
|
license: "MIT",
|
|
@@ -8397,26 +8397,26 @@ function createOAuthClient({ issuer, clientId, fetch: fetchImpl = globalThis.fet
|
|
|
8397
8397
|
|
|
8398
8398
|
// ../../packages/api-client/src/session.ts
|
|
8399
8399
|
function createSession({ oauth: oauth2, store, skewMs = 6e4, now = Date.now, onSignedOut }) {
|
|
8400
|
-
let
|
|
8400
|
+
let tokens2;
|
|
8401
8401
|
let refreshing = null;
|
|
8402
8402
|
async function current() {
|
|
8403
|
-
if (
|
|
8404
|
-
return
|
|
8403
|
+
if (tokens2 === void 0) tokens2 = await store.load();
|
|
8404
|
+
return tokens2;
|
|
8405
8405
|
}
|
|
8406
8406
|
async function accept(res, previous) {
|
|
8407
8407
|
const refreshToken = res.refresh_token ?? previous?.refreshToken;
|
|
8408
8408
|
if (!refreshToken) throw new SignInRequiredError("The sign-in did not return a refresh token.");
|
|
8409
|
-
|
|
8409
|
+
tokens2 = {
|
|
8410
8410
|
refreshToken,
|
|
8411
8411
|
accessToken: res.access_token,
|
|
8412
8412
|
expiresAt: now() + res.expires_in * 1e3,
|
|
8413
8413
|
scope: res.scope
|
|
8414
8414
|
};
|
|
8415
|
-
await store.save(
|
|
8416
|
-
return
|
|
8415
|
+
await store.save(tokens2);
|
|
8416
|
+
return tokens2;
|
|
8417
8417
|
}
|
|
8418
8418
|
async function end() {
|
|
8419
|
-
|
|
8419
|
+
tokens2 = null;
|
|
8420
8420
|
await store.clear();
|
|
8421
8421
|
onSignedOut?.();
|
|
8422
8422
|
}
|
|
@@ -12142,12 +12142,12 @@ var socialTools = [
|
|
|
12142
12142
|
need: write5,
|
|
12143
12143
|
risk: "W1",
|
|
12144
12144
|
gates: ["VER"],
|
|
12145
|
-
run: async (ctx, { id, words, style, text_effect, order, remove: remove3 }) => {
|
|
12145
|
+
run: async (ctx, { id, words, style, text_effect, order: order2, remove: remove3 }) => {
|
|
12146
12146
|
const out = await ws(ctx).editSocialPicture(Number(id), {
|
|
12147
12147
|
...Array.isArray(words) ? { words: words.map((w) => ({ headline: String(w.headline ?? ""), sub: String(w.sub ?? "") })) } : {},
|
|
12148
12148
|
...style ? { style } : {},
|
|
12149
12149
|
...text_effect ? { text_effect } : {},
|
|
12150
|
-
...Array.isArray(
|
|
12150
|
+
...Array.isArray(order2) ? { order: order2.map(Number) } : {},
|
|
12151
12151
|
...Array.isArray(remove3) ? { remove: remove3.map(Number) } : {}
|
|
12152
12152
|
});
|
|
12153
12153
|
return { id: out.id, pictures: out.image_urls?.length ? out.image_urls : [out.image_url], picture: out.picture };
|
|
@@ -14971,12 +14971,12 @@ async function menuGet(site, id) {
|
|
|
14971
14971
|
const nav = await menuPost(site, id);
|
|
14972
14972
|
const blocks = parse(nav.content.raw);
|
|
14973
14973
|
const other = blocks.filter((b) => b.name && !["core/navigation-link", "core/navigation-submenu"].includes(b.name)).map((b) => b.name);
|
|
14974
|
-
const
|
|
14974
|
+
const strip2 = (list3) => list3.map(({ attrs: _a3, ...i }) => ({ ...i, ...i.children ? { children: strip2(i.children) } : {} }));
|
|
14975
14975
|
return {
|
|
14976
14976
|
id: nav.id,
|
|
14977
14977
|
title: nav.title.raw,
|
|
14978
14978
|
modified: nav.modified,
|
|
14979
|
-
items:
|
|
14979
|
+
items: strip2(toItems(blocks)),
|
|
14980
14980
|
other_blocks: other
|
|
14981
14981
|
};
|
|
14982
14982
|
}
|
|
@@ -15058,8 +15058,8 @@ async function menuSet(site, ops, id) {
|
|
|
15058
15058
|
query: { _fields: "id,modified" },
|
|
15059
15059
|
body: { content }
|
|
15060
15060
|
});
|
|
15061
|
-
const
|
|
15062
|
-
return { id: nav.id, before:
|
|
15061
|
+
const strip2 = (list3) => list3.flatMap((i) => [i.label, ...(i.children ?? []).map((c) => ` ${c.label}`)]);
|
|
15062
|
+
return { id: nav.id, before: strip2(before), after: strip2(after) };
|
|
15063
15063
|
}
|
|
15064
15064
|
async function partGet(site, slug) {
|
|
15065
15065
|
const parts = await call(
|
|
@@ -15486,6 +15486,492 @@ ${rulesOf(o.current ?? "")}
|
|
|
15486
15486
|
`;
|
|
15487
15487
|
}
|
|
15488
15488
|
|
|
15489
|
+
// ../../packages/tools/src/wp/security.ts
|
|
15490
|
+
var order = ["p0", "p1", "p2", "p3", "p4"];
|
|
15491
|
+
var lower = (p, n2 = 1) => order[Math.min(4, order.indexOf(p) + n2)];
|
|
15492
|
+
function cmpVersion(a, b) {
|
|
15493
|
+
const pa = String(a).split(/[.\-+]/).map((x) => Number.parseInt(x, 10) || 0);
|
|
15494
|
+
const pb = String(b).split(/[.\-+]/).map((x) => Number.parseInt(x, 10) || 0);
|
|
15495
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
15496
|
+
const d = (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
15497
|
+
if (d) return d > 0 ? 1 : -1;
|
|
15498
|
+
}
|
|
15499
|
+
return 0;
|
|
15500
|
+
}
|
|
15501
|
+
var opOk = (v, op, bound) => {
|
|
15502
|
+
if (!bound || !op) return true;
|
|
15503
|
+
const c = cmpVersion(v, bound);
|
|
15504
|
+
return op === "lt" ? c < 0 : op === "le" ? c <= 0 : op === "gt" ? c > 0 : op === "ge" ? c >= 0 : op === "eq" ? c === 0 : true;
|
|
15505
|
+
};
|
|
15506
|
+
function affects(v, version2) {
|
|
15507
|
+
const o = v.operator ?? {};
|
|
15508
|
+
if (o.unfixed === "1" && !o.max_version) return true;
|
|
15509
|
+
return opOk(version2, o.min_operator, o.min_version) && opOk(version2, o.max_operator, o.max_version);
|
|
15510
|
+
}
|
|
15511
|
+
var sevPriority = (sev, score) => sev === "c" || score >= 9 ? "p0" : sev === "h" || score >= 7 ? "p0" : sev === "m" || score >= 4 ? "p1" : "p2";
|
|
15512
|
+
var decode2 = (s) => s.replace(/–|–/g, "\u2013").replace(/&/g, "&").replace(/’/g, "\u2019").replace(/'|'/g, "'").replace(/"/g, '"');
|
|
15513
|
+
async function vulnDb(kind, slug) {
|
|
15514
|
+
const ctl = AbortSignal.timeout(15e3);
|
|
15515
|
+
const r = await fetch(`https://www.wpvulnerability.net/${kind}/${encodeURIComponent(slug)}/`, {
|
|
15516
|
+
signal: ctl,
|
|
15517
|
+
headers: { Accept: "application/json", "User-Agent": "CMO.so security check" }
|
|
15518
|
+
}).catch(() => null);
|
|
15519
|
+
if (!r || !r.ok) return null;
|
|
15520
|
+
const j = await r.json().catch(() => null);
|
|
15521
|
+
return j && !j.error ? j.data ?? null : null;
|
|
15522
|
+
}
|
|
15523
|
+
async function pool(items3, n2, fn) {
|
|
15524
|
+
const out = new Array(items3.length);
|
|
15525
|
+
let i = 0;
|
|
15526
|
+
await Promise.all(
|
|
15527
|
+
Array.from({ length: Math.min(n2, items3.length) }, async () => {
|
|
15528
|
+
while (i < items3.length) {
|
|
15529
|
+
const k = i++;
|
|
15530
|
+
out[k] = await fn(items3[k]);
|
|
15531
|
+
}
|
|
15532
|
+
})
|
|
15533
|
+
);
|
|
15534
|
+
return out;
|
|
15535
|
+
}
|
|
15536
|
+
var PHP_EOL = {
|
|
15537
|
+
"7.4": "2022-11-28",
|
|
15538
|
+
"8.0": "2023-11-26",
|
|
15539
|
+
"8.1": "2025-12-31",
|
|
15540
|
+
"8.2": "2026-12-31",
|
|
15541
|
+
"8.3": "2027-12-31",
|
|
15542
|
+
"8.4": "2028-12-31",
|
|
15543
|
+
"8.5": "2029-12-31"
|
|
15544
|
+
};
|
|
15545
|
+
async function outside(url, path2, opts = {}) {
|
|
15546
|
+
const r = await fetch(`${url}${path2}`, {
|
|
15547
|
+
redirect: opts.redirect ?? "manual",
|
|
15548
|
+
signal: AbortSignal.timeout(12e3),
|
|
15549
|
+
headers: { "User-Agent": "Mozilla/5.0 (compatible; CMO.so security check)" }
|
|
15550
|
+
}).catch(() => null);
|
|
15551
|
+
if (!r) return null;
|
|
15552
|
+
const text3 = r.status === 200 ? (await r.text().catch(() => "")).slice(0, 4e3) : "";
|
|
15553
|
+
return { status: r.status, headers: r.headers, location: r.headers.get("location") ?? "", text: text3 };
|
|
15554
|
+
}
|
|
15555
|
+
async function componentFindings(plugins, themes, core, updates, degraded) {
|
|
15556
|
+
const out = [];
|
|
15557
|
+
const upd = updates?.plugins && !Array.isArray(updates.plugins) ? updates.plugins : {};
|
|
15558
|
+
const pluginsData = await pool(plugins, 6, (p) => vulnDb("plugin", p.plugin.split("/")[0]));
|
|
15559
|
+
plugins.forEach((p, i) => {
|
|
15560
|
+
const d = pluginsData[i];
|
|
15561
|
+
const id = p.plugin.replace(/\.php$/, "");
|
|
15562
|
+
const active = p.status === "active";
|
|
15563
|
+
const newer = upd[id]?.new_version;
|
|
15564
|
+
if (d === null) degraded.push(`vulnerabilities of ${p.name}`);
|
|
15565
|
+
const hits = (d?.vulnerability ?? []).filter((v) => affects(v, p.version));
|
|
15566
|
+
if (hits.length) {
|
|
15567
|
+
const worst = hits.reduce(
|
|
15568
|
+
(m, v) => {
|
|
15569
|
+
const label2 = `${v.name} ${(v.source ?? []).map((x) => x.name).join(" ")}`;
|
|
15570
|
+
const pr = v.impact?.cvss?.severity ? sevPriority(v.impact.cvss.severity, Number(v.impact.cvss.score ?? 0)) : /unauthenticated/i.test(label2) ? "p0" : "p1";
|
|
15571
|
+
return order.indexOf(pr) < order.indexOf(m.p) ? { p: pr, v } : m;
|
|
15572
|
+
},
|
|
15573
|
+
{ p: "p2", v: hits[0] }
|
|
15574
|
+
);
|
|
15575
|
+
const unfixed = hits.some((v) => v.operator?.unfixed === "1");
|
|
15576
|
+
const fixedIn = hits.map((v) => v.operator?.max_version).filter(Boolean);
|
|
15577
|
+
const cves = hits.flatMap((v) => (v.source ?? []).map((s) => s.id)).filter((x) => /^CVE-/.test(x));
|
|
15578
|
+
out.push({
|
|
15579
|
+
id: `vuln:${id}`,
|
|
15580
|
+
priority: active ? worst.p : lower(worst.p),
|
|
15581
|
+
area: "plugins",
|
|
15582
|
+
title: `${p.name} ${p.version} has ${hits.length} known ${hits.length === 1 ? "vulnerability" : "vulnerabilities"}${active ? "" : " (inactive)"}`,
|
|
15583
|
+
why: `${decode2(worst.v.name)}${cves.length ? ` (${[...new Set(cves)].slice(0, 3).join(", ")})` : ""}. ${active ? "Attackers scan for these." : "Inactive plugins can still be reached through their files."}`,
|
|
15584
|
+
fix: newer && !unfixed ? `Update to ${newer}${fixedIn.length ? ` (fixed from ${fixedIn.sort(cmpVersion).pop()})` : ""}.` : unfixed ? "No fixed version yet: deactivate it and replace it, or delete it if unused." : "Update it when a fixed version appears, or replace it.",
|
|
15585
|
+
...newer && !unfixed ? { tool: { name: "wp_plugin_update", args: { plugin: id } } } : { tool: { name: "wp_plugin_set", args: { plugin: id, status: active ? "inactive" : "deleted" } } },
|
|
15586
|
+
source: "wpvulnerability.net"
|
|
15587
|
+
});
|
|
15588
|
+
} else if (newer)
|
|
15589
|
+
out.push({
|
|
15590
|
+
id: `update:${id}`,
|
|
15591
|
+
priority: "p2",
|
|
15592
|
+
area: "plugins",
|
|
15593
|
+
title: `${p.name} can be updated (${p.version} \u2192 ${newer})`,
|
|
15594
|
+
why: "Updates often fix security problems before they are published.",
|
|
15595
|
+
fix: "Update it, then check the site.",
|
|
15596
|
+
tool: { name: "wp_plugin_update", args: { plugin: id } }
|
|
15597
|
+
});
|
|
15598
|
+
if (d?.closed)
|
|
15599
|
+
out.push({
|
|
15600
|
+
id: `closed:${id}`,
|
|
15601
|
+
priority: active ? "p1" : "p2",
|
|
15602
|
+
area: "plugins",
|
|
15603
|
+
title: `${p.name} was closed on WordPress.org`,
|
|
15604
|
+
why: `${d.closed_reason ? `Reason: ${d.closed_reason}. ` : ""}It gets no more updates, so new flaws stay open.`,
|
|
15605
|
+
fix: "Replace it with a maintained plugin, then delete it.",
|
|
15606
|
+
tool: { name: "wp_plugin_set", args: { plugin: id, status: active ? "inactive" : "deleted" } }
|
|
15607
|
+
});
|
|
15608
|
+
if (!active && !hits.length && !d?.closed)
|
|
15609
|
+
out.push({
|
|
15610
|
+
id: `inactive:${id}`,
|
|
15611
|
+
priority: "p4",
|
|
15612
|
+
area: "plugins",
|
|
15613
|
+
title: `${p.name} is installed but inactive`,
|
|
15614
|
+
why: "Unused plugins are code on the server that nobody watches.",
|
|
15615
|
+
fix: "Delete it if the site doesn't need it.",
|
|
15616
|
+
tool: { name: "wp_plugin_set", args: { plugin: id, status: "deleted" } }
|
|
15617
|
+
});
|
|
15618
|
+
});
|
|
15619
|
+
const themeData = await pool(themes, 4, (t) => vulnDb("theme", t.stylesheet));
|
|
15620
|
+
themes.forEach((t, i) => {
|
|
15621
|
+
const hits = (themeData[i]?.vulnerability ?? []).filter((v) => affects(v, t.version));
|
|
15622
|
+
if (hits.length)
|
|
15623
|
+
out.push({
|
|
15624
|
+
id: `vuln:theme:${t.stylesheet}`,
|
|
15625
|
+
priority: t.status === "active" ? "p0" : "p2",
|
|
15626
|
+
area: "themes",
|
|
15627
|
+
title: `Theme ${t.name ?? t.stylesheet} ${t.version} has known vulnerabilities`,
|
|
15628
|
+
why: decode2(hits[0]?.name ?? ""),
|
|
15629
|
+
fix: t.status === "active" ? "Update the theme." : "Delete the unused theme in wp-admin \u2192 Appearance.",
|
|
15630
|
+
source: "wpvulnerability.net"
|
|
15631
|
+
});
|
|
15632
|
+
});
|
|
15633
|
+
if (core) {
|
|
15634
|
+
const d = await vulnDb("core", core);
|
|
15635
|
+
if (d === null) degraded.push("WordPress core vulnerabilities");
|
|
15636
|
+
const names = [
|
|
15637
|
+
...new Set((d?.vulnerability ?? []).flatMap((v) => (v.source ?? []).map((x) => decode2(x.name))).filter(Boolean))
|
|
15638
|
+
];
|
|
15639
|
+
const unauth = names.filter((n2) => /unauthenticated/i.test(n2));
|
|
15640
|
+
if (names.length || updates?.core)
|
|
15641
|
+
out.push({
|
|
15642
|
+
id: "core",
|
|
15643
|
+
priority: unauth.length ? "p0" : names.length ? "p1" : "p2",
|
|
15644
|
+
area: "core",
|
|
15645
|
+
title: `WordPress ${core}${updates?.core ? ` \u2192 ${updates.core} available` : ""}${names.length ? ` (${names.length} known vulnerabilities${unauth.length ? `, ${unauth.length} without login` : ""})` : ""}`,
|
|
15646
|
+
why: names.length ? `For example: ${unauth[0] ?? names[0]}.` : "Minor WordPress releases are security releases.",
|
|
15647
|
+
fix: "Update WordPress (wp-admin \u2192 Dashboard \u2192 Updates, or the host's one-click update). Back up first.",
|
|
15648
|
+
source: names.length ? "wpvulnerability.net" : void 0
|
|
15649
|
+
});
|
|
15650
|
+
}
|
|
15651
|
+
return out;
|
|
15652
|
+
}
|
|
15653
|
+
function healthFindings(h) {
|
|
15654
|
+
const out = [];
|
|
15655
|
+
const s = h.settings;
|
|
15656
|
+
const add = (f) => out.push(f);
|
|
15657
|
+
if (s.debug_display)
|
|
15658
|
+
add({
|
|
15659
|
+
id: "debug-display",
|
|
15660
|
+
priority: "p1",
|
|
15661
|
+
area: "settings",
|
|
15662
|
+
title: "PHP errors are shown to visitors (WP_DEBUG_DISPLAY)",
|
|
15663
|
+
why: "Error messages reveal file paths and versions to attackers.",
|
|
15664
|
+
fix: "In wp-config.php set WP_DEBUG to false (or WP_DEBUG_DISPLAY to false). Host or developer task."
|
|
15665
|
+
});
|
|
15666
|
+
if (s.registration && !["subscriber", ""].includes(String(s.default_role)))
|
|
15667
|
+
add({
|
|
15668
|
+
id: "registration-role",
|
|
15669
|
+
priority: "p0",
|
|
15670
|
+
area: "settings",
|
|
15671
|
+
title: `Anyone can register and becomes ${s.default_role}`,
|
|
15672
|
+
why: "Strangers get accounts that can publish or change the site.",
|
|
15673
|
+
fix: "wp-admin \u2192 Settings \u2192 General: untick \u201CAnyone can register\u201D, or set the new user role to Subscriber."
|
|
15674
|
+
});
|
|
15675
|
+
else if (s.registration)
|
|
15676
|
+
add({
|
|
15677
|
+
id: "registration",
|
|
15678
|
+
priority: "p3",
|
|
15679
|
+
area: "settings",
|
|
15680
|
+
title: "Anyone can register an account",
|
|
15681
|
+
why: "Open registration attracts spam accounts; fine only if the site needs it.",
|
|
15682
|
+
fix: "wp-admin \u2192 Settings \u2192 General: untick \u201CAnyone can register\u201D if visitors don't need accounts."
|
|
15683
|
+
});
|
|
15684
|
+
if (!s.https)
|
|
15685
|
+
add({
|
|
15686
|
+
id: "https",
|
|
15687
|
+
priority: "p1",
|
|
15688
|
+
area: "settings",
|
|
15689
|
+
title: "The site address is not https",
|
|
15690
|
+
why: "Logins and forms travel unencrypted; browsers mark the site as not secure.",
|
|
15691
|
+
fix: "Install a certificate at the host and change the WordPress and site address to https."
|
|
15692
|
+
});
|
|
15693
|
+
if (s.file_edit)
|
|
15694
|
+
add({
|
|
15695
|
+
id: "file-edit",
|
|
15696
|
+
priority: "p3",
|
|
15697
|
+
area: "settings",
|
|
15698
|
+
title: "Plugin and theme files can be edited in wp-admin",
|
|
15699
|
+
why: "A stolen admin login can then run any code on the server.",
|
|
15700
|
+
fix: "Add define( 'DISALLOW_FILE_EDIT', true ); to wp-config.php (host or developer). CMO.so's tools keep working."
|
|
15701
|
+
});
|
|
15702
|
+
if (s.xmlrpc)
|
|
15703
|
+
add({
|
|
15704
|
+
id: "xmlrpc",
|
|
15705
|
+
priority: "p3",
|
|
15706
|
+
area: "settings",
|
|
15707
|
+
title: "XML-RPC is on",
|
|
15708
|
+
why: "Old remote API used for password guessing at scale; most sites don't need it (the CMO.so tools don't).",
|
|
15709
|
+
fix: "Block /xmlrpc.php at the host or with a security plugin, unless the Jetpack or the WordPress app needs it."
|
|
15710
|
+
});
|
|
15711
|
+
const perms = String(s.wp_config_perms ?? "");
|
|
15712
|
+
if (/^\d{3}$/.test(perms) && Number(perms[2]) >= 4)
|
|
15713
|
+
add({
|
|
15714
|
+
id: "wp-config-perms",
|
|
15715
|
+
priority: Number(perms[2]) >= 6 ? "p1" : "p3",
|
|
15716
|
+
area: "server",
|
|
15717
|
+
title: `wp-config.php is readable by every user on the server (${perms})`,
|
|
15718
|
+
why: "It holds the database password; on shared hosting other accounts could read it.",
|
|
15719
|
+
fix: "Ask the host to set it to 640 or 600."
|
|
15720
|
+
});
|
|
15721
|
+
const php = h.versions.php.split(".").slice(0, 2).join(".");
|
|
15722
|
+
const eol = PHP_EOL[php];
|
|
15723
|
+
const today2 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
15724
|
+
if (eol && eol < today2)
|
|
15725
|
+
add({
|
|
15726
|
+
id: "php-eol",
|
|
15727
|
+
priority: "p1",
|
|
15728
|
+
area: "server",
|
|
15729
|
+
title: `PHP ${h.versions.php} gets no more security fixes (since ${eol})`,
|
|
15730
|
+
why: "Flaws found in PHP now stay open on this server.",
|
|
15731
|
+
fix: "Ask the host to move the site to PHP 8.3 or newer (test the site after)."
|
|
15732
|
+
});
|
|
15733
|
+
else if (eol && eol < new Date(Date.now() + 120 * 864e5).toISOString().slice(0, 10))
|
|
15734
|
+
add({
|
|
15735
|
+
id: "php-eol-soon",
|
|
15736
|
+
priority: "p3",
|
|
15737
|
+
area: "server",
|
|
15738
|
+
title: `PHP ${h.versions.php} stops getting security fixes on ${eol}`,
|
|
15739
|
+
why: "Plan the move before it ends.",
|
|
15740
|
+
fix: "Ask the host to move the site to PHP 8.3 or newer."
|
|
15741
|
+
});
|
|
15742
|
+
const db = /^(\d+\.\d+)/.exec(h.versions.database)?.[1] ?? "";
|
|
15743
|
+
if (!/mariadb/i.test(h.versions.database) && ["5.7", "8.0"].includes(db))
|
|
15744
|
+
add({
|
|
15745
|
+
id: "mysql-eol",
|
|
15746
|
+
priority: "p3",
|
|
15747
|
+
area: "server",
|
|
15748
|
+
title: `MySQL ${db} has reached end of life`,
|
|
15749
|
+
why: "No more security fixes from Oracle.",
|
|
15750
|
+
fix: "Ask the host to move the database to MySQL 8.4 LTS (or MariaDB 11)."
|
|
15751
|
+
});
|
|
15752
|
+
const admins = h.users.admins;
|
|
15753
|
+
if (admins.some((a) => a.login_is_admin))
|
|
15754
|
+
add({
|
|
15755
|
+
id: "admin-login",
|
|
15756
|
+
priority: "p2",
|
|
15757
|
+
area: "users",
|
|
15758
|
+
title: "An Administrator logs in as \u201Cadmin\u201D",
|
|
15759
|
+
why: "It is the first name password-guessing bots try.",
|
|
15760
|
+
fix: "Create a new Administrator with another name, move the content to it, then delete \u201Cadmin\u201D."
|
|
15761
|
+
});
|
|
15762
|
+
if ((h.users.by_role.administrator ?? 0) > 3)
|
|
15763
|
+
add({
|
|
15764
|
+
id: "many-admins",
|
|
15765
|
+
priority: "p3",
|
|
15766
|
+
area: "users",
|
|
15767
|
+
title: `${h.users.by_role.administrator} Administrator accounts`,
|
|
15768
|
+
why: "Each one can change everything; fewer admins, fewer ways in.",
|
|
15769
|
+
fix: "Give people who only write or edit the Editor or Author role."
|
|
15770
|
+
});
|
|
15771
|
+
const old = new Date(Date.now() - 90 * 864e5).toISOString().slice(0, 10);
|
|
15772
|
+
const stale = admins.filter(
|
|
15773
|
+
(a) => a.app_passwords > 0 && (!a.app_password_last_use || a.app_password_last_use < old)
|
|
15774
|
+
);
|
|
15775
|
+
if (stale.length)
|
|
15776
|
+
add({
|
|
15777
|
+
id: "stale-app-passwords",
|
|
15778
|
+
priority: "p3",
|
|
15779
|
+
area: "users",
|
|
15780
|
+
title: `${stale.length} Administrator${stale.length > 1 ? "s have" : " has"} application passwords unused for 90 days`,
|
|
15781
|
+
why: "Old application passwords are keys nobody remembers handing out.",
|
|
15782
|
+
fix: "wp-admin \u2192 Users \u2192 Profile \u2192 Application Passwords: revoke the ones no tool uses (keep the CMO.so one)."
|
|
15783
|
+
});
|
|
15784
|
+
const orphans = h.cron.filter((j) => !j.handled && !j.core);
|
|
15785
|
+
for (const j of orphans.slice(0, 10))
|
|
15786
|
+
add({
|
|
15787
|
+
id: `cron-orphan:${j.hook}`,
|
|
15788
|
+
priority: "p3",
|
|
15789
|
+
area: "cron",
|
|
15790
|
+
title: `Scheduled job \u201C${j.hook}\u201D has nothing to run it`,
|
|
15791
|
+
why: "Usually left behind by a removed plugin; it keeps waking WordPress for nothing.",
|
|
15792
|
+
fix: "Remove it.",
|
|
15793
|
+
tool: { name: "wp_cron_unschedule", args: { hook: j.hook } }
|
|
15794
|
+
});
|
|
15795
|
+
const late = h.cron.filter((j) => j.schedule !== "once" && j.overdue_min > 120);
|
|
15796
|
+
if (late.length)
|
|
15797
|
+
add({
|
|
15798
|
+
id: "cron-late",
|
|
15799
|
+
priority: s.wp_cron_disabled ? "p2" : "p3",
|
|
15800
|
+
area: "cron",
|
|
15801
|
+
title: `${late.length} scheduled jobs are more than 2 hours late`,
|
|
15802
|
+
why: s.wp_cron_disabled ? "WP-Cron is turned off (DISABLE_WP_CRON) and no server cron seems to call it: scheduled posts, updates checks and clean-ups don't run." : "WP-Cron only runs when someone visits; on a quiet site scheduled posts and update checks run late.",
|
|
15803
|
+
fix: "Ask the host for a server cron that calls wp-cron.php every 5 minutes (and set DISABLE_WP_CRON)."
|
|
15804
|
+
});
|
|
15805
|
+
if (h.plugins.must_use.length || h.plugins.dropins.length)
|
|
15806
|
+
add({
|
|
15807
|
+
id: "mu-dropins",
|
|
15808
|
+
priority: "p4",
|
|
15809
|
+
area: "plugins",
|
|
15810
|
+
title: `Hidden plugins: ${[...h.plugins.must_use, ...h.plugins.dropins].join(", ")}`,
|
|
15811
|
+
why: "Must-use plugins and drop-ins run on every page and don't show in the plugin list. Usually the host's; worth knowing.",
|
|
15812
|
+
fix: "Ask the host what they are if you don't recognise them."
|
|
15813
|
+
});
|
|
15814
|
+
return out;
|
|
15815
|
+
}
|
|
15816
|
+
async function outsideFindings(url, h) {
|
|
15817
|
+
const out = [];
|
|
15818
|
+
const home = await outside(url, "/", { redirect: "follow" });
|
|
15819
|
+
if (home) {
|
|
15820
|
+
const want = [
|
|
15821
|
+
["strict-transport-security", "HSTS"],
|
|
15822
|
+
["x-content-type-options", "X-Content-Type-Options"],
|
|
15823
|
+
["referrer-policy", "Referrer-Policy"]
|
|
15824
|
+
];
|
|
15825
|
+
const missing = want.filter(([hname]) => !home.headers.get(hname)).map(([, label2]) => label2);
|
|
15826
|
+
const csp = home.headers.get("content-security-policy") ?? "";
|
|
15827
|
+
if (!home.headers.get("x-frame-options") && !/frame-ancestors/i.test(csp))
|
|
15828
|
+
missing.push("X-Frame-Options or CSP frame-ancestors");
|
|
15829
|
+
if (missing.length)
|
|
15830
|
+
out.push({
|
|
15831
|
+
id: "headers",
|
|
15832
|
+
priority: "p3",
|
|
15833
|
+
area: "outside",
|
|
15834
|
+
title: `Missing security headers: ${missing.join(", ")}`,
|
|
15835
|
+
why: "They stop click-jacking, MIME sniffing and downgrade to http in browsers.",
|
|
15836
|
+
fix: "Add them at the web server or CDN (Cloudflare \u2192 Rules \u2192 Transform rules), or with a security plugin."
|
|
15837
|
+
});
|
|
15838
|
+
const gen = /<meta name="generator" content="WordPress ([\d.]+)/i.exec(home.text)?.[1];
|
|
15839
|
+
if (gen)
|
|
15840
|
+
out.push({
|
|
15841
|
+
id: "version-visible",
|
|
15842
|
+
priority: "p4",
|
|
15843
|
+
area: "outside",
|
|
15844
|
+
title: `The WordPress version (${gen}) is visible in the page`,
|
|
15845
|
+
why: "Bots use it to pick attacks; keeping WordPress updated matters more than hiding it.",
|
|
15846
|
+
fix: "Optional: remove the generator tag with a security plugin."
|
|
15847
|
+
});
|
|
15848
|
+
}
|
|
15849
|
+
const probes = [
|
|
15850
|
+
{ path: "/.env", id: "env", title: "/.env is public", test: (t) => /^[A-Z_]+=/m.test(t), priority: "p0" },
|
|
15851
|
+
{
|
|
15852
|
+
path: "/.git/HEAD",
|
|
15853
|
+
id: "git",
|
|
15854
|
+
title: "The .git folder is public",
|
|
15855
|
+
test: (t) => t.startsWith("ref:"),
|
|
15856
|
+
priority: "p0"
|
|
15857
|
+
},
|
|
15858
|
+
{
|
|
15859
|
+
path: "/wp-config.php.bak",
|
|
15860
|
+
id: "config-bak",
|
|
15861
|
+
title: "A copy of wp-config.php is public",
|
|
15862
|
+
test: (t) => /DB_(NAME|PASSWORD)/.test(t),
|
|
15863
|
+
priority: "p0"
|
|
15864
|
+
},
|
|
15865
|
+
{
|
|
15866
|
+
path: "/wp-config.php~",
|
|
15867
|
+
id: "config-tilde",
|
|
15868
|
+
title: "A copy of wp-config.php is public",
|
|
15869
|
+
test: (t) => /DB_(NAME|PASSWORD)/.test(t),
|
|
15870
|
+
priority: "p0"
|
|
15871
|
+
},
|
|
15872
|
+
{
|
|
15873
|
+
path: "/wp-content/debug.log",
|
|
15874
|
+
id: "debug-log",
|
|
15875
|
+
title: "The PHP error log is public",
|
|
15876
|
+
test: (t) => /PHP (Notice|Warning|Fatal|Deprecated)|\[\d{2}-\w{3}-\d{4}/.test(t),
|
|
15877
|
+
priority: "p1"
|
|
15878
|
+
}
|
|
15879
|
+
];
|
|
15880
|
+
const got = await pool(probes, 5, (p) => outside(url, p.path));
|
|
15881
|
+
probes.forEach((p, i) => {
|
|
15882
|
+
const r = got[i];
|
|
15883
|
+
if (r && r.status === 200 && p.test(r.text))
|
|
15884
|
+
out.push({
|
|
15885
|
+
id: `exposed:${p.id}`,
|
|
15886
|
+
priority: p.priority,
|
|
15887
|
+
area: "outside",
|
|
15888
|
+
title: p.title,
|
|
15889
|
+
why: "Anyone can download it: it can hold passwords, keys or the site's code.",
|
|
15890
|
+
fix: `Delete or block ${p.path} at the host today${p.id === "env" || p.id.startsWith("config") ? ", then change every password and key it holds" : ""}.`
|
|
15891
|
+
});
|
|
15892
|
+
});
|
|
15893
|
+
const author = await outside(url, "/?author=1");
|
|
15894
|
+
if (author && [301, 302].includes(author.status) && /\/author\/[^/]+/.test(author.location))
|
|
15895
|
+
out.push({
|
|
15896
|
+
id: "user-enum",
|
|
15897
|
+
priority: "p3",
|
|
15898
|
+
area: "outside",
|
|
15899
|
+
title: "Login names can be found from /?author=1",
|
|
15900
|
+
why: "It gives password-guessing bots half of a login.",
|
|
15901
|
+
fix: "Block ?author= requests for visitors with a security plugin or a server rule."
|
|
15902
|
+
});
|
|
15903
|
+
const users = await outside(url, "/wp-json/wp/v2/users");
|
|
15904
|
+
if (users && users.status === 200 && /"slug"\s*:/.test(users.text))
|
|
15905
|
+
out.push({
|
|
15906
|
+
id: "users-api",
|
|
15907
|
+
priority: "p3",
|
|
15908
|
+
area: "outside",
|
|
15909
|
+
title: "The list of authors is public at /wp-json/wp/v2/users",
|
|
15910
|
+
why: "It shows login names (slugs) to anyone.",
|
|
15911
|
+
fix: "Limit the users endpoint to signed-in users with a security plugin."
|
|
15912
|
+
});
|
|
15913
|
+
const xmlrpc = h?.settings.xmlrpc ? await outside(url, "/xmlrpc.php") : null;
|
|
15914
|
+
if (xmlrpc && xmlrpc.status === 405) {
|
|
15915
|
+
const f = out.find((x) => x.id === "xmlrpc");
|
|
15916
|
+
if (f) f.why += " It answers from the internet.";
|
|
15917
|
+
}
|
|
15918
|
+
return out;
|
|
15919
|
+
}
|
|
15920
|
+
async function securityScan(site, o = {}) {
|
|
15921
|
+
const degraded = [];
|
|
15922
|
+
const notes = [];
|
|
15923
|
+
const h = await site.request({ path: "/maggie-core/v1/health" }).then((r) => r.status === 200 ? r.data : null).catch(() => null);
|
|
15924
|
+
if (!h)
|
|
15925
|
+
notes.push(
|
|
15926
|
+
"Maggie Core 0.14+ adds what WordPress itself reports (versions, settings, users, scheduled jobs, updates): update it with wp_theme_update for the full check."
|
|
15927
|
+
);
|
|
15928
|
+
const plugins = await call(site, {
|
|
15929
|
+
path: "/wp/v2/plugins",
|
|
15930
|
+
query: { _fields: "plugin,name,version,status,auto_update" }
|
|
15931
|
+
}).catch((e) => {
|
|
15932
|
+
degraded.push(`plugin list (${e.message})`);
|
|
15933
|
+
return [];
|
|
15934
|
+
});
|
|
15935
|
+
const themes = await call(site, { path: "/wp/v2/themes", query: { _fields: "stylesheet,version,status,name" } }).then(
|
|
15936
|
+
(rows) => rows.map((t) => ({ ...t, name: typeof t.name === "string" ? t.name : t.name?.raw ?? t.stylesheet }))
|
|
15937
|
+
).catch(() => []);
|
|
15938
|
+
const core = h?.versions.wordpress ?? "";
|
|
15939
|
+
const findings = [];
|
|
15940
|
+
if (o.vulnerabilities !== false)
|
|
15941
|
+
findings.push(...await componentFindings(plugins, themes, core, h?.updates ?? null, degraded));
|
|
15942
|
+
if (h) findings.push(...healthFindings(h));
|
|
15943
|
+
if (o.outside !== false && site.url) findings.push(...await outsideFindings(site.url, h));
|
|
15944
|
+
findings.sort((a, b) => order.indexOf(a.priority) - order.indexOf(b.priority));
|
|
15945
|
+
const count = Object.fromEntries(order.map((p) => [p, findings.filter((f) => f.priority === p).length]));
|
|
15946
|
+
return {
|
|
15947
|
+
site: site.url ?? "",
|
|
15948
|
+
checked: (/* @__PURE__ */ new Date()).toISOString(),
|
|
15949
|
+
summary: {
|
|
15950
|
+
...count,
|
|
15951
|
+
plugins: plugins.length,
|
|
15952
|
+
active_plugins: plugins.filter((p) => p.status === "active").length,
|
|
15953
|
+
themes: themes.length,
|
|
15954
|
+
wordpress: core || null,
|
|
15955
|
+
php: h?.versions.php ?? null,
|
|
15956
|
+
scheduled_jobs: h?.cron.length ?? null
|
|
15957
|
+
},
|
|
15958
|
+
words: { p0: "fix today", p1: "this week", p2: "this month", p3: "when convenient", p4: "for information" },
|
|
15959
|
+
findings,
|
|
15960
|
+
...h ? {
|
|
15961
|
+
cron: h.cron.filter((j) => !j.core).map((j) => ({
|
|
15962
|
+
hook: j.hook,
|
|
15963
|
+
schedule: j.schedule,
|
|
15964
|
+
next: j.next,
|
|
15965
|
+
handled: j.handled,
|
|
15966
|
+
late_min: j.overdue_min
|
|
15967
|
+
}))
|
|
15968
|
+
} : {},
|
|
15969
|
+
...degraded.length ? { degraded: [...new Set(degraded)].slice(0, 12) } : {},
|
|
15970
|
+
...notes.length ? { notes } : {},
|
|
15971
|
+
source: "Vulnerability data: WPVulnerability (wpvulnerability.net)."
|
|
15972
|
+
};
|
|
15973
|
+
}
|
|
15974
|
+
|
|
15489
15975
|
// ../../packages/tools/src/wp/site.ts
|
|
15490
15976
|
async function siteStatus(site) {
|
|
15491
15977
|
const me = await call(site, {
|
|
@@ -15780,8 +16266,8 @@ async function relatedCards(site, parent, template, exclude = [], n2 = 3) {
|
|
|
15780
16266
|
},
|
|
15781
16267
|
300
|
|
15782
16268
|
);
|
|
15783
|
-
const
|
|
15784
|
-
const picks =
|
|
16269
|
+
const pool4 = pages.filter((p) => !exclude.includes(p.id) && (!template || p.template === template));
|
|
16270
|
+
const picks = pool4.slice(0, n2);
|
|
15785
16271
|
const media = picks.filter((p) => p.featured_media).map((p) => p.featured_media);
|
|
15786
16272
|
const urls = {};
|
|
15787
16273
|
if (media.length) {
|
|
@@ -16046,7 +16532,7 @@ async function seoImport(site, overwrite = false) {
|
|
|
16046
16532
|
body: { overwrite }
|
|
16047
16533
|
});
|
|
16048
16534
|
}
|
|
16049
|
-
async function
|
|
16535
|
+
async function pool2(items3, n2, fn) {
|
|
16050
16536
|
const out = new Array(items3.length);
|
|
16051
16537
|
let i = 0;
|
|
16052
16538
|
await Promise.all(
|
|
@@ -16068,7 +16554,7 @@ async function seoAudit(site, o = {}) {
|
|
|
16068
16554
|
o.posts
|
|
16069
16555
|
) : [];
|
|
16070
16556
|
const items3 = [...pages.map((p) => ({ ...p, kind: "page" })), ...posts.map((p) => ({ ...p, kind: "post" }))];
|
|
16071
|
-
const heads = await
|
|
16557
|
+
const heads = await pool2(items3, 6, (p) => renderedHead(site, p.link).catch(() => null));
|
|
16072
16558
|
const issues = [];
|
|
16073
16559
|
const titles = /* @__PURE__ */ new Map();
|
|
16074
16560
|
const descs = /* @__PURE__ */ new Map();
|
|
@@ -16172,7 +16658,7 @@ async function seoAudit(site, o = {}) {
|
|
|
16172
16658
|
});
|
|
16173
16659
|
const unknown2 = [...allLinks].filter((l) => !known.has(l) && !/^\/(category|tag|author|page|blogs?)\//.test(l)).slice(0, 60);
|
|
16174
16660
|
const base = site.url ?? "";
|
|
16175
|
-
const checked = await
|
|
16661
|
+
const checked = await pool2(unknown2, 6, async (l) => ({
|
|
16176
16662
|
l,
|
|
16177
16663
|
s: site.fetchPage ? (await site.fetchPage(`${base}${l}`).catch(() => ({ status: 0 }))).status : 200
|
|
16178
16664
|
}));
|
|
@@ -16202,8 +16688,8 @@ async function seoAudit(site, o = {}) {
|
|
|
16202
16688
|
path: "/wp-sitemap.xml",
|
|
16203
16689
|
detail: `The sitemap answers ${sitemap.status || "nothing"}.`
|
|
16204
16690
|
});
|
|
16205
|
-
const
|
|
16206
|
-
issues.sort((a, b) =>
|
|
16691
|
+
const order2 = { high: 0, medium: 1, low: 2 };
|
|
16692
|
+
issues.sort((a, b) => order2[a.severity] - order2[b.severity] || a.code.localeCompare(b.code));
|
|
16207
16693
|
const byCode = {};
|
|
16208
16694
|
for (const i of issues) byCode[i.code] = (byCode[i.code] ?? 0) + 1;
|
|
16209
16695
|
return {
|
|
@@ -16214,6 +16700,888 @@ async function seoAudit(site, o = {}) {
|
|
|
16214
16700
|
};
|
|
16215
16701
|
}
|
|
16216
16702
|
|
|
16703
|
+
// ../../packages/tools/src/wp/seo-tech.ts
|
|
16704
|
+
var UA = "Mozilla/5.0 (compatible; CMO.so SEO check)";
|
|
16705
|
+
async function get(url, redirect = "manual") {
|
|
16706
|
+
const r = await fetch(url, { redirect, signal: AbortSignal.timeout(15e3), headers: { "User-Agent": UA } }).catch(
|
|
16707
|
+
() => null
|
|
16708
|
+
);
|
|
16709
|
+
if (!r) return null;
|
|
16710
|
+
const text3 = r.status === 200 ? await r.text().catch(() => "") : "";
|
|
16711
|
+
return {
|
|
16712
|
+
status: r.status,
|
|
16713
|
+
text: text3,
|
|
16714
|
+
location: r.headers.get("location") ?? "",
|
|
16715
|
+
type: r.headers.get("content-type") ?? ""
|
|
16716
|
+
};
|
|
16717
|
+
}
|
|
16718
|
+
async function pool3(items3, n2, fn) {
|
|
16719
|
+
const out = new Array(items3.length);
|
|
16720
|
+
let i = 0;
|
|
16721
|
+
await Promise.all(
|
|
16722
|
+
Array.from({ length: Math.min(n2, items3.length) }, async () => {
|
|
16723
|
+
while (i < items3.length) {
|
|
16724
|
+
const k = i++;
|
|
16725
|
+
out[k] = await fn(items3[k]);
|
|
16726
|
+
}
|
|
16727
|
+
})
|
|
16728
|
+
);
|
|
16729
|
+
return out;
|
|
16730
|
+
}
|
|
16731
|
+
function sitePath(href, base) {
|
|
16732
|
+
try {
|
|
16733
|
+
const u = new URL(href, `${base}/`);
|
|
16734
|
+
const b = new URL(base);
|
|
16735
|
+
if (u.hostname.replace(/^www\./, "") !== b.hostname.replace(/^www\./, "")) return null;
|
|
16736
|
+
if (!/^https?:$/.test(u.protocol)) return null;
|
|
16737
|
+
let p = u.pathname.replace(/\/+/g, "/");
|
|
16738
|
+
if (!p.endsWith("/") && !/\.[a-z0-9]{2,5}$/i.test(p)) p += "/";
|
|
16739
|
+
return `${p}${u.searchParams.get("p") || u.searchParams.get("page_id") ? `?${u.searchParams.toString()}` : ""}`;
|
|
16740
|
+
} catch {
|
|
16741
|
+
return null;
|
|
16742
|
+
}
|
|
16743
|
+
}
|
|
16744
|
+
var strip = (h) => h.replace(/<[^>]+>/g, " ").replace(/ /g, " ").replace(/&/g, "&").replace(/’|’/g, "\u2019").replace(/–|–/g, "\u2013").replace(/"/g, '"').replace(/'|'/g, "'").replace(/\s+/g, " ").trim();
|
|
16745
|
+
function scanHtml(html2, url, base) {
|
|
16746
|
+
const head = /<head[\s\S]*?<\/head>/i.exec(html2)?.[0] ?? html2;
|
|
16747
|
+
const attr2 = (re) => re.exec(head)?.[1] ?? "";
|
|
16748
|
+
const main = /<main[\s\S]*?<\/main>/i.exec(html2)?.[0] ?? html2.replace(/<header[\s\S]*?<\/header>/gi, "").replace(/<nav[\s\S]*?<\/nav>/gi, "").replace(/<footer[\s\S]*?<\/footer>/gi, "");
|
|
16749
|
+
const body = main.replace(/<script[\s\S]*?<\/script>|<style[\s\S]*?<\/style>/gi, " ");
|
|
16750
|
+
const links2 = [];
|
|
16751
|
+
for (const m of body.matchAll(/<a\b[^>]*href=["']([^"'#]+)[^"']*["'][^>]*>([\s\S]*?)<\/a>/gi)) {
|
|
16752
|
+
const p = sitePath(m[1], base);
|
|
16753
|
+
if (p && !/\/(wp-admin|wp-login|wp-json|feed)\b|\.(jpg|jpeg|png|webp|gif|svg|pdf|zip)$/i.test(p))
|
|
16754
|
+
links2.push({ path: p, text: strip(m[2]).slice(0, 80) });
|
|
16755
|
+
}
|
|
16756
|
+
const imgs = [...body.matchAll(/<img\b[^>]*>/gi)].map((m) => m[0]);
|
|
16757
|
+
const schema = [];
|
|
16758
|
+
let schemaErrors = 0;
|
|
16759
|
+
for (const m of html2.matchAll(/<script[^>]+application\/ld\+json[^>]*>([\s\S]*?)<\/script>/gi)) {
|
|
16760
|
+
try {
|
|
16761
|
+
const j = JSON.parse(m[1]);
|
|
16762
|
+
const items3 = Array.isArray(j) ? j : j["@graph"] ? j["@graph"] : [j];
|
|
16763
|
+
for (const it of items3) {
|
|
16764
|
+
const t = it?.["@type"];
|
|
16765
|
+
for (const x of Array.isArray(t) ? t : [t]) if (typeof x === "string") schema.push(x);
|
|
16766
|
+
}
|
|
16767
|
+
} catch {
|
|
16768
|
+
schemaErrors++;
|
|
16769
|
+
}
|
|
16770
|
+
}
|
|
16771
|
+
return {
|
|
16772
|
+
url,
|
|
16773
|
+
path: sitePath(url, base) ?? url,
|
|
16774
|
+
title: strip(/<title[^>]*>([\s\S]*?)<\/title>/i.exec(head)?.[1] ?? ""),
|
|
16775
|
+
description: strip(attr2(/<meta[^>]+name=["']description["'][^>]+content=["']([^"']*)["']/i)),
|
|
16776
|
+
canonical: attr2(/<link[^>]+rel=["']canonical["'][^>]+href=["']([^"']+)["']/i),
|
|
16777
|
+
robots: attr2(/<meta[^>]+name=["']robots["'][^>]+content=["']([^"']*)["']/i).toLowerCase(),
|
|
16778
|
+
h1: (body.match(/<h1\b/gi) ?? []).length || (html2.match(/<h1\b/gi) ?? []).length,
|
|
16779
|
+
images: imgs.length,
|
|
16780
|
+
// No alt at all is a problem; alt="" is right for decoration (cover backgrounds), wrong on content pictures.
|
|
16781
|
+
imagesNoAlt: imgs.filter((i) => {
|
|
16782
|
+
if (/aria-hidden|role=["']presentation|wp-block-cover__image-background/i.test(i)) return false;
|
|
16783
|
+
if (!/\balt=/i.test(i)) return true;
|
|
16784
|
+
return /\balt=["']\s*["']/i.test(i) && /\bwp-image-\d+/.test(i);
|
|
16785
|
+
}).length,
|
|
16786
|
+
schema: [...new Set(schema)],
|
|
16787
|
+
schemaErrors,
|
|
16788
|
+
links: links2,
|
|
16789
|
+
words: strip(body).split(" ").filter(Boolean).length
|
|
16790
|
+
};
|
|
16791
|
+
}
|
|
16792
|
+
async function sitemapUrls(base, robotsTxt, max = 500) {
|
|
16793
|
+
const fromRobots = [...robotsTxt.matchAll(/^sitemap:\s*(\S+)/gim)].map((m) => m[1]);
|
|
16794
|
+
const candidates = [...fromRobots, `${base}/wp-sitemap.xml`, `${base}/sitemap_index.xml`, `${base}/sitemap.xml`];
|
|
16795
|
+
for (const sm of candidates) {
|
|
16796
|
+
const r = await get(sm, "follow");
|
|
16797
|
+
if (!r || r.status !== 200 || !/<(urlset|sitemapindex)/i.test(r.text)) continue;
|
|
16798
|
+
const urls = [];
|
|
16799
|
+
const queue = [r.text];
|
|
16800
|
+
let fetched = 0;
|
|
16801
|
+
while (queue.length && urls.length < max && fetched < 30) {
|
|
16802
|
+
const xml = queue.shift();
|
|
16803
|
+
const locs = [...xml.matchAll(/<loc>\s*([^<\s]+)\s*<\/loc>/gi)].map(
|
|
16804
|
+
(m) => m[1].replace(/&/g, "&")
|
|
16805
|
+
);
|
|
16806
|
+
if (/<sitemapindex/i.test(xml)) {
|
|
16807
|
+
for (const l of locs) {
|
|
16808
|
+
const s = await get(l, "follow");
|
|
16809
|
+
fetched++;
|
|
16810
|
+
if (s?.status === 200) queue.push(s.text);
|
|
16811
|
+
}
|
|
16812
|
+
} else urls.push(...locs);
|
|
16813
|
+
}
|
|
16814
|
+
return { urls: [...new Set(urls)].slice(0, max), sitemap: sm };
|
|
16815
|
+
}
|
|
16816
|
+
return { urls: [], sitemap: null };
|
|
16817
|
+
}
|
|
16818
|
+
var AI_BOTS = [
|
|
16819
|
+
"GPTBot",
|
|
16820
|
+
"OAI-SearchBot",
|
|
16821
|
+
"ChatGPT-User",
|
|
16822
|
+
"ClaudeBot",
|
|
16823
|
+
"Claude-SearchBot",
|
|
16824
|
+
"PerplexityBot",
|
|
16825
|
+
"Google-Extended",
|
|
16826
|
+
"CCBot"
|
|
16827
|
+
];
|
|
16828
|
+
function robotsBlocked(robots, agents) {
|
|
16829
|
+
const groups = [];
|
|
16830
|
+
let cur = null;
|
|
16831
|
+
for (const raw of robots.split(/\r?\n/)) {
|
|
16832
|
+
const line = raw.replace(/#.*/, "").trim();
|
|
16833
|
+
const m = /^([a-z-]+)\s*:\s*(.*)$/i.exec(line);
|
|
16834
|
+
if (!m) continue;
|
|
16835
|
+
const [k, v] = [m[1].toLowerCase(), m[2].trim()];
|
|
16836
|
+
if (k === "user-agent") {
|
|
16837
|
+
if (!cur || cur.rules.length) {
|
|
16838
|
+
cur = { agents: [], rules: [] };
|
|
16839
|
+
groups.push(cur);
|
|
16840
|
+
}
|
|
16841
|
+
cur.agents.push(v.toLowerCase());
|
|
16842
|
+
} else if (cur && (k === "disallow" || k === "allow")) cur.rules.push(`${k}:${v}`);
|
|
16843
|
+
}
|
|
16844
|
+
const blocks = (g) => g.rules.includes("disallow:/") && !g.rules.some((r) => r === "allow:/");
|
|
16845
|
+
return agents.filter((a) => {
|
|
16846
|
+
const own3 = groups.find((g2) => g2.agents.includes(a.toLowerCase()));
|
|
16847
|
+
const g = own3 ?? groups.find((x) => x.agents.includes("*"));
|
|
16848
|
+
return g ? blocks(g) : false;
|
|
16849
|
+
});
|
|
16850
|
+
}
|
|
16851
|
+
function groupFindings(list3, min = 4) {
|
|
16852
|
+
const kinds = /* @__PURE__ */ new Map();
|
|
16853
|
+
for (const f of list3) {
|
|
16854
|
+
const k = f.id.includes(":") ? f.id.split(":")[0] : f.id;
|
|
16855
|
+
kinds.set(k, [...kinds.get(k) ?? [], f]);
|
|
16856
|
+
}
|
|
16857
|
+
const out = [];
|
|
16858
|
+
for (const [k, fs] of kinds) {
|
|
16859
|
+
if (fs.length < min || !fs[0]?.id.includes(":")) {
|
|
16860
|
+
out.push(...fs);
|
|
16861
|
+
continue;
|
|
16862
|
+
}
|
|
16863
|
+
const paths = fs.map((f) => f.id.slice(k.length + 1));
|
|
16864
|
+
const first = fs[0];
|
|
16865
|
+
const label2 = {
|
|
16866
|
+
"title-long": "have SEO titles longer than 65 characters",
|
|
16867
|
+
alt: "have pictures without alt text",
|
|
16868
|
+
desc: "have no meta description",
|
|
16869
|
+
h1: "don't have exactly one H1",
|
|
16870
|
+
thin: "have fewer than 120 words",
|
|
16871
|
+
"noindex-in-sitemap": "are noindex but in the sitemap",
|
|
16872
|
+
canonical: "point their canonical elsewhere",
|
|
16873
|
+
"schema-error": "have broken structured data",
|
|
16874
|
+
"sitemap-status": "are in the sitemap but don't answer 200",
|
|
16875
|
+
orphan: "get no links from other pages",
|
|
16876
|
+
broken: "are linked but broken"
|
|
16877
|
+
};
|
|
16878
|
+
const seoTool = first.tool?.name === "wp_seo_set";
|
|
16879
|
+
out.push({
|
|
16880
|
+
...first,
|
|
16881
|
+
id: `${k}:*`,
|
|
16882
|
+
title: `${fs.length} pages ${label2[k] ?? first.title}`,
|
|
16883
|
+
why: first.why,
|
|
16884
|
+
fix: `${first.fix.replace(/\.$/, "")}. Pages: ${paths.slice(0, 12).join(", ")}${paths.length > 12 ? ` +${paths.length - 12} more` : ""}.`,
|
|
16885
|
+
...seoTool ? { tool: { name: "wp_seo_set", args: { items: paths.slice(0, 50).map((x) => ({ page: x })) } } } : {},
|
|
16886
|
+
pages: paths
|
|
16887
|
+
});
|
|
16888
|
+
}
|
|
16889
|
+
return out;
|
|
16890
|
+
}
|
|
16891
|
+
async function techAudit(site, o = {}) {
|
|
16892
|
+
const base = (site.url ?? "").replace(/\/+$/, "");
|
|
16893
|
+
if (!base) throw new Error("The site's address is unknown.");
|
|
16894
|
+
const limit = Math.min(Math.max(o.limit ?? 60, 5), 200);
|
|
16895
|
+
const findings = [];
|
|
16896
|
+
const add = (f) => findings.push(f);
|
|
16897
|
+
const robotsR = await get(`${base}/robots.txt`, "follow");
|
|
16898
|
+
const robots = robotsR?.status === 200 ? robotsR.text : "";
|
|
16899
|
+
const visible = await site.request({ path: "/wp/v2/settings", query: { _fields: "blog_public" } }).then((r) => r.status === 200 && r.data.blog_public != null ? !!Number(r.data.blog_public) : null).catch(() => null);
|
|
16900
|
+
const engagedOff = visible === false;
|
|
16901
|
+
let { urls, sitemap } = await sitemapUrls(base, robots);
|
|
16902
|
+
let discovered = "sitemap";
|
|
16903
|
+
if (!urls.length) {
|
|
16904
|
+
const rows = await Promise.all(
|
|
16905
|
+
["/wp/v2/pages", "/wp/v2/posts"].map(
|
|
16906
|
+
(path2) => all(site, path2, { status: "publish", _fields: "link", per_page: 100 }, limit).catch(() => [])
|
|
16907
|
+
)
|
|
16908
|
+
);
|
|
16909
|
+
urls = [...new Set(rows.flat().map((r) => r.link))];
|
|
16910
|
+
discovered = "wordpress";
|
|
16911
|
+
}
|
|
16912
|
+
if (engagedOff)
|
|
16913
|
+
add({
|
|
16914
|
+
id: "search-engines-off",
|
|
16915
|
+
priority: "p1",
|
|
16916
|
+
area: "settings",
|
|
16917
|
+
title: "Search engines are switched off for this site",
|
|
16918
|
+
why: "WordPress tells every search engine not to index it (noindex on every page, no sitemap). Right for a test or unfinished site; check MEMORY.md before changing it.",
|
|
16919
|
+
fix: "When the site is ready: wp_settings_set search_engines true.",
|
|
16920
|
+
tool: { name: "wp_settings_set", args: { search_engines: true } }
|
|
16921
|
+
});
|
|
16922
|
+
if (!robotsR || robotsR.status !== 200)
|
|
16923
|
+
add({
|
|
16924
|
+
id: "robots-missing",
|
|
16925
|
+
priority: "p3",
|
|
16926
|
+
area: "settings",
|
|
16927
|
+
title: "No robots.txt",
|
|
16928
|
+
why: "Crawlers look for it first.",
|
|
16929
|
+
fix: "WordPress makes one by itself unless a file or plugin blocks it: check the host."
|
|
16930
|
+
});
|
|
16931
|
+
if (/^disallow:\s*\/\s*$/im.test(robots) && robotsBlocked(robots, ["Googlebot"]).length)
|
|
16932
|
+
add({
|
|
16933
|
+
id: "robots-all",
|
|
16934
|
+
priority: "p0",
|
|
16935
|
+
area: "settings",
|
|
16936
|
+
title: "robots.txt blocks Google from the whole site",
|
|
16937
|
+
why: "Nothing can be indexed.",
|
|
16938
|
+
fix: "Turn search engines on (wp_settings_set search_engines true) or fix the robots.txt file.",
|
|
16939
|
+
tool: { name: "wp_settings_set", args: { search_engines: true } }
|
|
16940
|
+
});
|
|
16941
|
+
if (robots && !engagedOff && !/^sitemap:/im.test(robots))
|
|
16942
|
+
add({
|
|
16943
|
+
id: "robots-sitemap",
|
|
16944
|
+
priority: "p3",
|
|
16945
|
+
area: "settings",
|
|
16946
|
+
title: "robots.txt doesn't point to the sitemap",
|
|
16947
|
+
why: "It helps every crawler find all pages.",
|
|
16948
|
+
fix: "Maggie Core adds the Sitemap line when search engines are on; otherwise add it to robots.txt."
|
|
16949
|
+
});
|
|
16950
|
+
const aiBlocked = robotsBlocked(robots, AI_BOTS);
|
|
16951
|
+
if (aiBlocked.length)
|
|
16952
|
+
add({
|
|
16953
|
+
id: "ai-crawlers",
|
|
16954
|
+
priority: "p2",
|
|
16955
|
+
area: "settings",
|
|
16956
|
+
title: `AI crawlers are blocked: ${aiBlocked.join(", ")}`,
|
|
16957
|
+
why: "ChatGPT, Claude, Perplexity and Google's AI answers can't read or cite the site.",
|
|
16958
|
+
fix: "Allow them in robots.txt unless the owner chose to block AI."
|
|
16959
|
+
});
|
|
16960
|
+
if (!sitemap && !engagedOff)
|
|
16961
|
+
add({
|
|
16962
|
+
id: "sitemap-missing",
|
|
16963
|
+
priority: "p1",
|
|
16964
|
+
area: "settings",
|
|
16965
|
+
title: "No sitemap found",
|
|
16966
|
+
why: "Search engines find new pages slower without one.",
|
|
16967
|
+
fix: "WordPress publishes /wp-sitemap.xml when search engines are on; check nothing turns it off."
|
|
16968
|
+
});
|
|
16969
|
+
const llms = await get(`${base}/llms.txt`, "follow");
|
|
16970
|
+
const hasLlms = !!llms && llms.status === 200 && /^#\s/m.test(llms.text) && !/<html/i.test(llms.text);
|
|
16971
|
+
if (!hasLlms)
|
|
16972
|
+
add({
|
|
16973
|
+
id: "llms-missing",
|
|
16974
|
+
priority: "p3",
|
|
16975
|
+
area: "settings",
|
|
16976
|
+
title: "No llms.txt",
|
|
16977
|
+
why: "A short Markdown map of the site helps AI assistants describe it correctly.",
|
|
16978
|
+
fix: "Generate it from the site.",
|
|
16979
|
+
tool: { name: "wp_llms_txt_set", args: { generate: true } }
|
|
16980
|
+
});
|
|
16981
|
+
const crawl = urls.length ? urls.slice(0, limit) : [`${base}/`];
|
|
16982
|
+
if (!crawl.some((u) => sitePath(u, base) === "/")) crawl.unshift(`${base}/`);
|
|
16983
|
+
const scans = await pool3(crawl, 6, async (u) => {
|
|
16984
|
+
const r = await get(u);
|
|
16985
|
+
if (!r) return null;
|
|
16986
|
+
if (r.status !== 200) return { ...scanHtml("", u, base), status: r.status, redirect: r.location || void 0 };
|
|
16987
|
+
return { ...scanHtml(r.text, u, base), status: 200 };
|
|
16988
|
+
});
|
|
16989
|
+
const pages = scans.filter(Boolean);
|
|
16990
|
+
const ok2 = pages.filter((p) => p.status === 200);
|
|
16991
|
+
const bad = pages.filter((p) => p.status !== 200);
|
|
16992
|
+
for (const p of bad)
|
|
16993
|
+
add({
|
|
16994
|
+
id: `sitemap-status:${p.path}`,
|
|
16995
|
+
priority: p.status >= 400 ? "p1" : "p2",
|
|
16996
|
+
area: "outside",
|
|
16997
|
+
title: `The sitemap lists ${p.path}, which answers ${p.status}${p.redirect ? ` \u2192 ${p.redirect}` : ""}`,
|
|
16998
|
+
why: "Sitemaps should list only live pages; search engines lose trust in it.",
|
|
16999
|
+
fix: p.status >= 400 ? "Publish the page again, or remove it (wp_post_delete / wp_page_publish)." : "List the final address; the redirect is fine for visitors."
|
|
17000
|
+
});
|
|
17001
|
+
for (const p of ok2) {
|
|
17002
|
+
if (/noindex/.test(p.robots) && !engagedOff && discovered === "sitemap")
|
|
17003
|
+
add({
|
|
17004
|
+
id: `noindex-in-sitemap:${p.path}`,
|
|
17005
|
+
priority: "p1",
|
|
17006
|
+
area: "outside",
|
|
17007
|
+
title: `${p.path} is noindex but in the sitemap`,
|
|
17008
|
+
why: "Mixed signals: either it should be found, or it shouldn't be listed.",
|
|
17009
|
+
fix: 'Remove noindex if the page should rank (wp_seo_set robots "").',
|
|
17010
|
+
tool: { name: "wp_seo_set", args: { page: p.path, robots: "" } }
|
|
17011
|
+
});
|
|
17012
|
+
if (p.canonical && sitePath(p.canonical, base) !== p.path)
|
|
17013
|
+
add({
|
|
17014
|
+
id: `canonical:${p.path}`,
|
|
17015
|
+
priority: "p2",
|
|
17016
|
+
area: "outside",
|
|
17017
|
+
title: `${p.path} points its canonical to ${p.canonical}`,
|
|
17018
|
+
why: "Google will index the other address instead of this page.",
|
|
17019
|
+
fix: 'Clear the custom canonical unless it is on purpose (wp_seo_set canonical "").',
|
|
17020
|
+
tool: { name: "wp_seo_set", args: { page: p.path, canonical: "" } }
|
|
17021
|
+
});
|
|
17022
|
+
if (p.h1 !== 1)
|
|
17023
|
+
add({
|
|
17024
|
+
id: `h1:${p.path}`,
|
|
17025
|
+
priority: "p2",
|
|
17026
|
+
area: "outside",
|
|
17027
|
+
title: `${p.path} has ${p.h1} H1 headings`,
|
|
17028
|
+
why: "One H1 says what the page is about.",
|
|
17029
|
+
fix: p.h1 ? "Make the extra H1s H2 (wp_section_update edits)." : "Give the page a main heading (the hero's title)."
|
|
17030
|
+
});
|
|
17031
|
+
if (p.imagesNoAlt)
|
|
17032
|
+
add({
|
|
17033
|
+
id: `alt:${p.path}`,
|
|
17034
|
+
priority: "p3",
|
|
17035
|
+
area: "outside",
|
|
17036
|
+
title: `${p.path}: ${p.imagesNoAlt} of ${p.images} pictures have no alt text`,
|
|
17037
|
+
why: "Alt text is how search engines, AI and screen readers know what a picture shows.",
|
|
17038
|
+
fix: "Add alt text (wp_section_update images alt, or the media library)."
|
|
17039
|
+
});
|
|
17040
|
+
if (p.schemaErrors)
|
|
17041
|
+
add({
|
|
17042
|
+
id: `schema-error:${p.path}`,
|
|
17043
|
+
priority: "p2",
|
|
17044
|
+
area: "outside",
|
|
17045
|
+
title: `${p.path}: ${p.schemaErrors} structured-data block(s) are not valid JSON`,
|
|
17046
|
+
why: "Google ignores broken structured data.",
|
|
17047
|
+
fix: "Fix or remove the page's custom schema (wp_seo_set schema)."
|
|
17048
|
+
});
|
|
17049
|
+
if (p.words < 120 && !/\?/.test(p.path))
|
|
17050
|
+
add({
|
|
17051
|
+
id: `thin:${p.path}`,
|
|
17052
|
+
priority: "p3",
|
|
17053
|
+
area: "outside",
|
|
17054
|
+
title: `${p.path} has only ${p.words} words`,
|
|
17055
|
+
why: "Very short pages rarely rank or get cited.",
|
|
17056
|
+
fix: "Add useful text: what, for whom, price or next step, questions."
|
|
17057
|
+
});
|
|
17058
|
+
if (!p.description)
|
|
17059
|
+
add({
|
|
17060
|
+
id: `desc:${p.path}`,
|
|
17061
|
+
priority: "p2",
|
|
17062
|
+
area: "outside",
|
|
17063
|
+
title: `${p.path} has no meta description`,
|
|
17064
|
+
why: "Google writes its own snippet, often a poor one.",
|
|
17065
|
+
fix: "Write one (140\u2013160 characters).",
|
|
17066
|
+
tool: { name: "wp_seo_set", args: { page: p.path } }
|
|
17067
|
+
});
|
|
17068
|
+
if (p.title.length > 65)
|
|
17069
|
+
add({
|
|
17070
|
+
id: `title-long:${p.path}`,
|
|
17071
|
+
priority: "p3",
|
|
17072
|
+
area: "outside",
|
|
17073
|
+
title: `${p.path}: title is ${p.title.length} characters`,
|
|
17074
|
+
why: "Search results cut it after about 60.",
|
|
17075
|
+
fix: "Shorten the SEO title.",
|
|
17076
|
+
tool: { name: "wp_seo_set", args: { page: p.path } }
|
|
17077
|
+
});
|
|
17078
|
+
}
|
|
17079
|
+
const dup = (key) => {
|
|
17080
|
+
const by = /* @__PURE__ */ new Map();
|
|
17081
|
+
for (const p of ok2) if (p[key]) by.set(p[key], [...by.get(p[key]) ?? [], p.path]);
|
|
17082
|
+
for (const [v, ps] of by)
|
|
17083
|
+
if (ps.length > 1)
|
|
17084
|
+
add({
|
|
17085
|
+
id: `dup-${key}:${v.slice(0, 40)}`,
|
|
17086
|
+
priority: "p2",
|
|
17087
|
+
area: "outside",
|
|
17088
|
+
title: `${ps.length} pages share the same ${key}: \u201C${v.slice(0, 70)}\u201D`,
|
|
17089
|
+
why: "Search engines can't tell them apart.",
|
|
17090
|
+
fix: `Give each its own ${key} (wp_seo_set items).`,
|
|
17091
|
+
tool: { name: "wp_seo_set", args: { items: ps.slice(0, 10).map((x) => ({ page: x })) } }
|
|
17092
|
+
});
|
|
17093
|
+
};
|
|
17094
|
+
dup("title");
|
|
17095
|
+
dup("description");
|
|
17096
|
+
const home = ok2.find((p) => p.path === "/");
|
|
17097
|
+
if (home && !home.schema.some((t) => /Organization|LocalBusiness|WebSite|Person|Store|Restaurant|Service/i.test(t)))
|
|
17098
|
+
add({
|
|
17099
|
+
id: "schema-home",
|
|
17100
|
+
priority: "p2",
|
|
17101
|
+
area: "outside",
|
|
17102
|
+
title: "The homepage has no Organization / LocalBusiness structured data",
|
|
17103
|
+
why: "It tells Google and AI who the business is, where and how to reach it.",
|
|
17104
|
+
fix: "Fill the business details (wp_seo_site_set business).",
|
|
17105
|
+
tool: { name: "wp_seo_site_set", args: {} }
|
|
17106
|
+
});
|
|
17107
|
+
const inbound = /* @__PURE__ */ new Map();
|
|
17108
|
+
for (const p of ok2)
|
|
17109
|
+
for (const l of new Set(p.links.map((x) => x.path))) if (l !== p.path) inbound.set(l, (inbound.get(l) ?? 0) + 1);
|
|
17110
|
+
const known = new Set(pages.map((p) => p.path));
|
|
17111
|
+
const targets = [...new Set(ok2.flatMap((p) => p.links.map((l) => l.path)))].filter((t) => !known.has(t)).slice(0, 80);
|
|
17112
|
+
const checked = await pool3(targets, 6, async (t) => ({ t, r: await get(`${base}${t}`) }));
|
|
17113
|
+
const broken = checked.filter((c) => c.r && c.r.status >= 400);
|
|
17114
|
+
const redirected = checked.filter((c) => c.r && [301, 302, 307, 308].includes(c.r.status));
|
|
17115
|
+
for (const b of broken) {
|
|
17116
|
+
const from = ok2.filter((p) => p.links.some((l) => l.path === b.t)).map((p) => p.path);
|
|
17117
|
+
add({
|
|
17118
|
+
id: `broken:${b.t}`,
|
|
17119
|
+
priority: "p1",
|
|
17120
|
+
area: "outside",
|
|
17121
|
+
title: `Broken link to ${b.t} (${b.r?.status}) on ${from.slice(0, 3).join(", ")}${from.length > 3 ? ` +${from.length - 3}` : ""}`,
|
|
17122
|
+
why: "Visitors hit a dead end and crawlers waste their visit.",
|
|
17123
|
+
fix: "Point the link to a live page (wp_section_update links) or add a redirect (wp_redirect_set).",
|
|
17124
|
+
tool: { name: "wp_redirect_set", args: { from: b.t } }
|
|
17125
|
+
});
|
|
17126
|
+
}
|
|
17127
|
+
if (redirected.length)
|
|
17128
|
+
add({
|
|
17129
|
+
id: "links-redirected",
|
|
17130
|
+
priority: "p3",
|
|
17131
|
+
area: "outside",
|
|
17132
|
+
title: `${redirected.length} internal links go through a redirect`,
|
|
17133
|
+
why: "Each hop slows visitors and loses a little link value.",
|
|
17134
|
+
fix: `Link straight to the final address: ${redirected.slice(0, 5).map((c) => `${c.t} \u2192 ${c.r?.location}`).join(", ")}.`
|
|
17135
|
+
});
|
|
17136
|
+
const generic = ok2.flatMap(
|
|
17137
|
+
(p) => p.links.filter((l) => /^(click here|here|read more|learn more|more|this|link|點此|更多)$/i.test(l.text)).map(() => p.path)
|
|
17138
|
+
);
|
|
17139
|
+
if (generic.length)
|
|
17140
|
+
add({
|
|
17141
|
+
id: "anchors-generic",
|
|
17142
|
+
priority: "p3",
|
|
17143
|
+
area: "outside",
|
|
17144
|
+
title: `${generic.length} links say only \u201Cread more\u201D, \u201Cclick here\u201D or similar`,
|
|
17145
|
+
why: "Link words tell search engines what the target page is about.",
|
|
17146
|
+
fix: `Use the target's topic as the link text (pages: ${[...new Set(generic)].slice(0, 5).join(", ")}).`
|
|
17147
|
+
});
|
|
17148
|
+
let speed = null;
|
|
17149
|
+
if (o.speed) speed = await pageSpeed(`${base}/`);
|
|
17150
|
+
if (speed?.lcp_ms && Number(speed.lcp_ms) > 2500)
|
|
17151
|
+
add({
|
|
17152
|
+
id: "lcp",
|
|
17153
|
+
priority: Number(speed.lcp_ms) > 4e3 ? "p1" : "p2",
|
|
17154
|
+
area: "outside",
|
|
17155
|
+
title: `The homepage's main content shows after ${(Number(speed.lcp_ms) / 1e3).toFixed(1)} s on phones (LCP)`,
|
|
17156
|
+
why: "Google wants under 2.5 s; slow pages lose visitors and rankings.",
|
|
17157
|
+
fix: "Smaller hero picture (WebP, under 200 KB), fewer fonts and scripts above the fold."
|
|
17158
|
+
});
|
|
17159
|
+
if (speed?.cls != null && Number(speed.cls) > 0.1)
|
|
17160
|
+
add({
|
|
17161
|
+
id: "cls",
|
|
17162
|
+
priority: "p2",
|
|
17163
|
+
area: "outside",
|
|
17164
|
+
title: `The homepage moves while loading (CLS ${speed.cls})`,
|
|
17165
|
+
why: "Google wants under 0.1.",
|
|
17166
|
+
fix: "Give pictures width and height; don't insert banners above content after load."
|
|
17167
|
+
});
|
|
17168
|
+
const order2 = ["p0", "p1", "p2", "p3", "p4"];
|
|
17169
|
+
const grouped = groupFindings(findings);
|
|
17170
|
+
grouped.sort((a, b) => order2.indexOf(a.priority) - order2.indexOf(b.priority));
|
|
17171
|
+
findings.length = 0;
|
|
17172
|
+
findings.push(...grouped);
|
|
17173
|
+
return {
|
|
17174
|
+
site: base,
|
|
17175
|
+
checked: (/* @__PURE__ */ new Date()).toISOString(),
|
|
17176
|
+
summary: {
|
|
17177
|
+
...Object.fromEntries(order2.map((p) => [p, findings.filter((f) => f.priority === p).length])),
|
|
17178
|
+
sitemap,
|
|
17179
|
+
pages_from: discovered,
|
|
17180
|
+
search_engines: visible,
|
|
17181
|
+
sitemap_urls: discovered === "sitemap" ? urls.length : 0,
|
|
17182
|
+
crawled: pages.length,
|
|
17183
|
+
live: ok2.length,
|
|
17184
|
+
llms_txt: hasLlms,
|
|
17185
|
+
ai_crawlers_blocked: aiBlocked,
|
|
17186
|
+
internal_links: ok2.reduce((n2, p) => n2 + p.links.length, 0)
|
|
17187
|
+
},
|
|
17188
|
+
pages: ok2.map((p) => ({
|
|
17189
|
+
path: p.path,
|
|
17190
|
+
title: p.title,
|
|
17191
|
+
words: p.words,
|
|
17192
|
+
h1: p.h1,
|
|
17193
|
+
links_out: new Set(p.links.map((l) => l.path)).size,
|
|
17194
|
+
links_in: inbound.get(p.path) ?? 0,
|
|
17195
|
+
schema: p.schema
|
|
17196
|
+
})),
|
|
17197
|
+
findings,
|
|
17198
|
+
...speed ? { speed } : {},
|
|
17199
|
+
...urls.length > crawl.length ? { note: `Crawled the first ${crawl.length} of ${urls.length} sitemap addresses (limit up to 200).` } : {}
|
|
17200
|
+
};
|
|
17201
|
+
}
|
|
17202
|
+
async function pageSpeed(url) {
|
|
17203
|
+
const key = globalThis.process?.env?.PAGESPEED_API_KEY;
|
|
17204
|
+
const q3 = new URLSearchParams({ url, strategy: "mobile", category: "performance" });
|
|
17205
|
+
if (key) q3.set("key", key);
|
|
17206
|
+
const r = await fetch(`https://www.googleapis.com/pagespeedonline/v5/runPagespeed?${q3}`, {
|
|
17207
|
+
signal: AbortSignal.timeout(9e4)
|
|
17208
|
+
}).catch(() => null);
|
|
17209
|
+
if (!r || !r.ok)
|
|
17210
|
+
return {
|
|
17211
|
+
error: `PageSpeed Insights didn't answer (${r?.status ?? "timeout"})${r?.status === 429 && !key ? ": the server needs a PAGESPEED_API_KEY (Google Cloud, free)" : ""}.`
|
|
17212
|
+
};
|
|
17213
|
+
const j = await r.json();
|
|
17214
|
+
const f = j.loadingExperience?.metrics ?? {};
|
|
17215
|
+
const a = j.lighthouseResult?.audits ?? {};
|
|
17216
|
+
const field = !!f.LARGEST_CONTENTFUL_PAINT_MS;
|
|
17217
|
+
return {
|
|
17218
|
+
source: field ? "real visitors (Chrome UX Report, 28 days)" : "lab test (no real-visitor data yet)",
|
|
17219
|
+
score: Math.round((j.lighthouseResult?.categories?.performance?.score ?? 0) * 100),
|
|
17220
|
+
lcp_ms: field ? f.LARGEST_CONTENTFUL_PAINT_MS?.percentile : Math.round(a["largest-contentful-paint"]?.numericValue ?? 0),
|
|
17221
|
+
cls: field ? (f.CUMULATIVE_LAYOUT_SHIFT_SCORE?.percentile ?? 0) / 100 : Number((a["cumulative-layout-shift"]?.numericValue ?? 0).toFixed(3)),
|
|
17222
|
+
inp_ms: f.INTERACTION_TO_NEXT_PAINT?.percentile ?? null,
|
|
17223
|
+
tbt_ms: Math.round(a["total-blocking-time"]?.numericValue ?? 0)
|
|
17224
|
+
};
|
|
17225
|
+
}
|
|
17226
|
+
var STOP = new Set(
|
|
17227
|
+
"the a an and or of to in for on with by at from is are be your our you we it this that how what why best guide near vs and/or my me us".split(
|
|
17228
|
+
" "
|
|
17229
|
+
)
|
|
17230
|
+
);
|
|
17231
|
+
var tokens = (s) => new Set(
|
|
17232
|
+
s.toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu, " ").split(/[\s-]+/).filter((w) => w.length > 2 && !STOP.has(w)).map((w) => w.replace(/(ies)$/, "y").replace(/(es|s)$/, ""))
|
|
17233
|
+
);
|
|
17234
|
+
var overlap = (a, b, idf = () => 1) => {
|
|
17235
|
+
let dot = 0;
|
|
17236
|
+
let na = 0;
|
|
17237
|
+
let nb = 0;
|
|
17238
|
+
for (const w of a) {
|
|
17239
|
+
const x = idf(w) ** 2;
|
|
17240
|
+
na += x;
|
|
17241
|
+
if (b.has(w)) dot += x;
|
|
17242
|
+
}
|
|
17243
|
+
for (const w of b) nb += idf(w) ** 2;
|
|
17244
|
+
return dot / Math.sqrt(Math.max(1e-9, na) * Math.max(1e-9, nb));
|
|
17245
|
+
};
|
|
17246
|
+
function contentLinks(raw, base) {
|
|
17247
|
+
const out = /* @__PURE__ */ new Set();
|
|
17248
|
+
for (const m of raw.matchAll(/href=["']([^"'#]+)["']/gi)) {
|
|
17249
|
+
const p = sitePath(m[1], base);
|
|
17250
|
+
if (p) out.add(p);
|
|
17251
|
+
}
|
|
17252
|
+
for (const m of raw.matchAll(/"url":"([^"]+)"/g)) {
|
|
17253
|
+
const p = sitePath(m[1].replace(/\\\//g, "/"), base);
|
|
17254
|
+
if (p) out.add(p);
|
|
17255
|
+
}
|
|
17256
|
+
return out;
|
|
17257
|
+
}
|
|
17258
|
+
var flatMenu = (items3) => items3.flatMap((i) => [{ url: i.url, label: i.label }, ...flatMenu(i.children ?? [])]);
|
|
17259
|
+
async function linksPlan(site, o = {}) {
|
|
17260
|
+
const base = (site.url ?? "").replace(/\/+$/, "");
|
|
17261
|
+
const pages = await listPages(site, { status: "publish", withContent: true });
|
|
17262
|
+
const posts = await all(
|
|
17263
|
+
site,
|
|
17264
|
+
"/wp/v2/posts",
|
|
17265
|
+
{
|
|
17266
|
+
context: "edit",
|
|
17267
|
+
status: "publish",
|
|
17268
|
+
per_page: 100,
|
|
17269
|
+
_fields: "id,link,title,categories,content,meta",
|
|
17270
|
+
orderby: "date",
|
|
17271
|
+
order: "desc"
|
|
17272
|
+
},
|
|
17273
|
+
o.posts ?? 200
|
|
17274
|
+
);
|
|
17275
|
+
const cats = await all(site, "/wp/v2/categories", {
|
|
17276
|
+
per_page: 100,
|
|
17277
|
+
_fields: "id,name,link,count"
|
|
17278
|
+
});
|
|
17279
|
+
const catName = new Map(cats.map((c) => [c.id, c.name]));
|
|
17280
|
+
const settings = await site.request({
|
|
17281
|
+
path: "/wp/v2/settings",
|
|
17282
|
+
query: { _fields: "page_on_front,page_for_posts" }
|
|
17283
|
+
}).then((r) => r.status === 200 ? r.data : {});
|
|
17284
|
+
const docs = [
|
|
17285
|
+
...pages.map((p) => ({
|
|
17286
|
+
id: p.id,
|
|
17287
|
+
kind: "page",
|
|
17288
|
+
path: sitePath(p.link, base) ?? p.link,
|
|
17289
|
+
url: p.link,
|
|
17290
|
+
title: titleOf(p.title),
|
|
17291
|
+
parent: p.parent,
|
|
17292
|
+
links: contentLinks(p.content?.raw ?? "", base),
|
|
17293
|
+
words: tokens(
|
|
17294
|
+
`${titleOf(p.title)} ${p.slug} ${p.meta?.maggie_seo_title ?? ""} ${p.meta?.maggie_seo_keywords ?? ""}`
|
|
17295
|
+
),
|
|
17296
|
+
description: String(p.meta?.maggie_seo_description ?? "")
|
|
17297
|
+
})),
|
|
17298
|
+
...posts.map((p) => ({
|
|
17299
|
+
id: p.id,
|
|
17300
|
+
kind: "post",
|
|
17301
|
+
path: sitePath(p.link, base) ?? p.link,
|
|
17302
|
+
url: p.link,
|
|
17303
|
+
title: p.title.raw ?? "",
|
|
17304
|
+
cats: p.categories.map((c) => catName.get(c) ?? "").filter(Boolean),
|
|
17305
|
+
links: contentLinks(p.content.raw, base),
|
|
17306
|
+
words: tokens(
|
|
17307
|
+
`${p.title.raw ?? ""} ${p.categories.map((c) => catName.get(c) ?? "").join(" ")} ${p.meta?.maggie_seo_keywords ?? ""}`
|
|
17308
|
+
),
|
|
17309
|
+
description: String(p.meta?.maggie_seo_description ?? "")
|
|
17310
|
+
}))
|
|
17311
|
+
];
|
|
17312
|
+
const byPath = new Map(docs.map((d) => [d.path, d]));
|
|
17313
|
+
const menu = await menuGet(site).catch(() => null);
|
|
17314
|
+
const menuPaths = new Set(
|
|
17315
|
+
flatMenu(menu?.items ?? []).map((i) => sitePath(i.url, base)).filter(Boolean)
|
|
17316
|
+
);
|
|
17317
|
+
const footer = await partGet(site, "footer").catch(() => null);
|
|
17318
|
+
const footerPaths = footer ? contentLinks(footer.content, base) : /* @__PURE__ */ new Set();
|
|
17319
|
+
const header = await partGet(site, "header").catch(() => null);
|
|
17320
|
+
const headerPaths = header ? contentLinks(header.content, base) : /* @__PURE__ */ new Set();
|
|
17321
|
+
const chrome = /* @__PURE__ */ new Set([...menuPaths, ...footerPaths, ...headerPaths]);
|
|
17322
|
+
const inbound = /* @__PURE__ */ new Map();
|
|
17323
|
+
for (const d of docs)
|
|
17324
|
+
for (const l of d.links) if (l !== d.path) inbound.set(l, /* @__PURE__ */ new Set([...inbound.get(l) ?? [], d.path]));
|
|
17325
|
+
const home = docs.find((d) => d.id === settings.page_on_front && d.kind === "page");
|
|
17326
|
+
const blogPage = docs.find((d) => d.id === settings.page_for_posts && d.kind === "page");
|
|
17327
|
+
const actions = [];
|
|
17328
|
+
const findings = [];
|
|
17329
|
+
const sample = docs.filter(
|
|
17330
|
+
(d) => d.kind === "page" && (/\/sample-page\/$/.test(d.path) || d.title === "Sample Page") || d.kind === "post" && (/\/hello-world\/$/.test(d.path) || d.title === "Hello world!")
|
|
17331
|
+
);
|
|
17332
|
+
for (const d of sample)
|
|
17333
|
+
findings.push({
|
|
17334
|
+
id: `sample:${d.path}`,
|
|
17335
|
+
priority: "p2",
|
|
17336
|
+
area: "outside",
|
|
17337
|
+
title: `WordPress's sample ${d.kind === "page" ? "page" : "article"} \u201C${d.title}\u201D is still published`,
|
|
17338
|
+
why: "It tells visitors and search engines the site isn't finished, and dilutes the real pages.",
|
|
17339
|
+
fix: "Move it to the trash.",
|
|
17340
|
+
tool: {
|
|
17341
|
+
name: d.kind === "page" ? "wp_page_delete" : "wp_post_delete",
|
|
17342
|
+
args: d.kind === "page" ? { page: d.id } : { post: d.id }
|
|
17343
|
+
}
|
|
17344
|
+
});
|
|
17345
|
+
const pageDocs = docs.filter((d) => d.kind === "page" && d !== home && !sample.includes(d));
|
|
17346
|
+
const postDocs = docs.filter((d) => d.kind === "post" && !sample.includes(d));
|
|
17347
|
+
const menuItems = flatMenu(menu?.items ?? []);
|
|
17348
|
+
const top = (menu?.items ?? []).length;
|
|
17349
|
+
for (const i of menuItems) {
|
|
17350
|
+
const p = sitePath(i.url, base);
|
|
17351
|
+
if (p && p !== "/" && !byPath.has(p) && !/\/(category|tag|author)\//.test(p) && !p.startsWith("/?"))
|
|
17352
|
+
findings.push({
|
|
17353
|
+
id: `menu-dead:${p}`,
|
|
17354
|
+
priority: "p1",
|
|
17355
|
+
area: "outside",
|
|
17356
|
+
title: `The menu links to ${p} (\u201C${i.label}\u201D), which isn't a published page or post`,
|
|
17357
|
+
why: "Visitors hit a dead end from every page.",
|
|
17358
|
+
fix: "Point it to a live page or remove it (wp_menu_set).",
|
|
17359
|
+
tool: { name: "wp_menu_set", args: {} }
|
|
17360
|
+
});
|
|
17361
|
+
}
|
|
17362
|
+
if (top > 7)
|
|
17363
|
+
findings.push({
|
|
17364
|
+
id: "menu-long",
|
|
17365
|
+
priority: "p3",
|
|
17366
|
+
area: "outside",
|
|
17367
|
+
title: `The menu has ${top} top-level items`,
|
|
17368
|
+
why: "More than 7 makes choosing hard; group them under submenus.",
|
|
17369
|
+
fix: "Group related pages under a parent item (wp_menu_set)."
|
|
17370
|
+
});
|
|
17371
|
+
const hubs = pageDocs.filter((d) => pageDocs.some((c) => c.parent === d.id));
|
|
17372
|
+
const topLevel = pageDocs.filter((d) => !d.parent);
|
|
17373
|
+
const wantMenu = [.../* @__PURE__ */ new Set([...hubs, ...topLevel.slice(0, 6)])].filter(
|
|
17374
|
+
(d) => !chrome.has(d.path) && !/privacy|terms|cookie|legal|impressum|datenschutz|thank/i.test(d.path)
|
|
17375
|
+
);
|
|
17376
|
+
if (wantMenu.length)
|
|
17377
|
+
actions.push({
|
|
17378
|
+
type: "menu",
|
|
17379
|
+
why: "Main pages every visitor should reach in one click.",
|
|
17380
|
+
add: wantMenu.slice(0, 6).map((d) => ({ label: d.title, url: d.url })),
|
|
17381
|
+
tool: "wp_menu_set"
|
|
17382
|
+
});
|
|
17383
|
+
if (postDocs.length && blogPage && !chrome.has(blogPage.path))
|
|
17384
|
+
actions.push({
|
|
17385
|
+
type: "menu",
|
|
17386
|
+
why: "The blog isn't reachable from the menu.",
|
|
17387
|
+
add: [{ label: blogPage.title || "Blog", url: blogPage.url }],
|
|
17388
|
+
tool: "wp_menu_set"
|
|
17389
|
+
});
|
|
17390
|
+
const legal = pageDocs.filter(
|
|
17391
|
+
(d) => /privacy|terms|cookie|legal|impressum|datenschutz|accessib/i.test(`${d.path} ${d.title}`)
|
|
17392
|
+
);
|
|
17393
|
+
const contact = pageDocs.filter((d) => /contact|about|book|location|faq/i.test(`${d.path} ${d.title}`));
|
|
17394
|
+
const footerMissing = [...legal, ...contact].filter((d) => !footerPaths.has(d.path));
|
|
17395
|
+
if (footerMissing.length)
|
|
17396
|
+
actions.push({
|
|
17397
|
+
type: "footer",
|
|
17398
|
+
why: "Legal, contact and about pages belong in the footer of every page (trust, and Google's quality raters look for them).",
|
|
17399
|
+
add: footerMissing.slice(0, 8).map((d) => ({ label: d.title, url: d.url })),
|
|
17400
|
+
tool: "wp_footer_set"
|
|
17401
|
+
});
|
|
17402
|
+
for (const hub of hubs) {
|
|
17403
|
+
const kids = pageDocs.filter((c) => c.parent === hub.id);
|
|
17404
|
+
const missing = kids.filter((k) => !hub.links.has(k.path));
|
|
17405
|
+
if (missing.length)
|
|
17406
|
+
actions.push({
|
|
17407
|
+
type: "page_related",
|
|
17408
|
+
page: hub.id,
|
|
17409
|
+
path: hub.path,
|
|
17410
|
+
heading: `More in ${hub.title}`,
|
|
17411
|
+
why: `${hub.title} doesn't link to ${missing.length} of its own sub-pages.`,
|
|
17412
|
+
links: missing.map((k) => ({ url: k.url, label: k.title }))
|
|
17413
|
+
});
|
|
17414
|
+
for (const k of kids)
|
|
17415
|
+
if (!k.links.has(hub.path)) {
|
|
17416
|
+
const sib = kids.filter((s) => s !== k).slice(0, 3);
|
|
17417
|
+
actions.push({
|
|
17418
|
+
type: "page_related",
|
|
17419
|
+
page: k.id,
|
|
17420
|
+
path: k.path,
|
|
17421
|
+
heading: "Related",
|
|
17422
|
+
why: `${k.title} doesn't link back to ${hub.title}${sib.length ? " or its sister pages" : ""}.`,
|
|
17423
|
+
links: [{ url: hub.url, label: hub.title }, ...sib.map((s) => ({ url: s.url, label: s.title }))]
|
|
17424
|
+
});
|
|
17425
|
+
}
|
|
17426
|
+
}
|
|
17427
|
+
const df = /* @__PURE__ */ new Map();
|
|
17428
|
+
for (const d of docs) for (const w of d.words) df.set(w, (df.get(w) ?? 0) + 1);
|
|
17429
|
+
const idf = (w) => Math.log(1 + docs.length / (1 + (df.get(w) ?? 0)));
|
|
17430
|
+
const forPage = /* @__PURE__ */ new Map();
|
|
17431
|
+
for (const post of postDocs) {
|
|
17432
|
+
let best = null;
|
|
17433
|
+
let score = 0;
|
|
17434
|
+
for (const pg of home ? [...pageDocs, home] : pageDocs) {
|
|
17435
|
+
if (pg === blogPage) continue;
|
|
17436
|
+
const s = overlap(post.words, pg.words, idf);
|
|
17437
|
+
if (s > score) [best, score] = [pg, s];
|
|
17438
|
+
}
|
|
17439
|
+
if (!best || score < 0.3) continue;
|
|
17440
|
+
forPage.set(best, [...forPage.get(best) ?? [], post]);
|
|
17441
|
+
if (!post.links.has(best.path))
|
|
17442
|
+
actions.push({
|
|
17443
|
+
type: "post_link",
|
|
17444
|
+
post: post.id,
|
|
17445
|
+
path: post.path,
|
|
17446
|
+
why: `\u201C${post.title}\u201D is about ${best.title} but doesn't link to that page.`,
|
|
17447
|
+
url: best.url,
|
|
17448
|
+
label: best.title,
|
|
17449
|
+
match: Math.round(score * 100)
|
|
17450
|
+
});
|
|
17451
|
+
}
|
|
17452
|
+
for (const [pg, ps] of forPage) {
|
|
17453
|
+
const missing = ps.filter((p) => !pg.links.has(p.path));
|
|
17454
|
+
if (missing.length >= 2)
|
|
17455
|
+
actions.push({
|
|
17456
|
+
type: "page_related",
|
|
17457
|
+
page: pg.id,
|
|
17458
|
+
path: pg.path,
|
|
17459
|
+
heading: "From the blog",
|
|
17460
|
+
why: `${missing.length} articles about ${pg.title} aren't linked from the page.`,
|
|
17461
|
+
links: missing.slice(0, 5).map((p) => ({ url: p.url, label: p.title }))
|
|
17462
|
+
});
|
|
17463
|
+
}
|
|
17464
|
+
const lonelyPosts = [];
|
|
17465
|
+
for (const d of docs) {
|
|
17466
|
+
if (d === home || d === blogPage || sample.includes(d)) continue;
|
|
17467
|
+
const ins = inbound.get(d.path);
|
|
17468
|
+
if (ins && ins.size || chrome.has(d.path)) continue;
|
|
17469
|
+
if (d.kind === "post") lonelyPosts.push(d);
|
|
17470
|
+
else
|
|
17471
|
+
findings.push({
|
|
17472
|
+
id: `orphan:${d.path}`,
|
|
17473
|
+
priority: "p2",
|
|
17474
|
+
area: "outside",
|
|
17475
|
+
title: `Nothing links to the page \u201C${d.title}\u201D (${d.path})`,
|
|
17476
|
+
why: "Pages that only the sitemap knows are found late and rank poorly.",
|
|
17477
|
+
fix: "Link to it from its parent or a related page, or put it in the menu or footer"
|
|
17478
|
+
});
|
|
17479
|
+
}
|
|
17480
|
+
if (lonelyPosts.length)
|
|
17481
|
+
findings.push({
|
|
17482
|
+
id: "orphan-posts",
|
|
17483
|
+
priority: "p3",
|
|
17484
|
+
area: "outside",
|
|
17485
|
+
title: `${lonelyPosts.length} of ${postDocs.length} articles get no links from pages or other articles (only from the blog list)`,
|
|
17486
|
+
why: "Links from related pages and articles tell search engines which articles matter and keep readers on the site.",
|
|
17487
|
+
fix: "Apply the post_link and page_related actions: each article links to its page, each page shows its articles."
|
|
17488
|
+
});
|
|
17489
|
+
const grouped = groupFindings(findings);
|
|
17490
|
+
findings.length = 0;
|
|
17491
|
+
findings.push(...grouped);
|
|
17492
|
+
return {
|
|
17493
|
+
site: base,
|
|
17494
|
+
counts: {
|
|
17495
|
+
pages: pageDocs.length + (home ? 1 : 0),
|
|
17496
|
+
posts: postDocs.length,
|
|
17497
|
+
menu_items: menuItems.length,
|
|
17498
|
+
footer_links: footerPaths.size,
|
|
17499
|
+
content_links: docs.reduce((n2, d) => n2 + d.links.size, 0),
|
|
17500
|
+
orphan_pages: findings.reduce(
|
|
17501
|
+
(n2, f) => n2 + (f.id.startsWith("orphan:") ? f.pages?.length ?? 1 : 0),
|
|
17502
|
+
0
|
|
17503
|
+
),
|
|
17504
|
+
orphan_posts: lonelyPosts.length
|
|
17505
|
+
},
|
|
17506
|
+
action_counts: Object.fromEntries(
|
|
17507
|
+
["menu", "footer", "page_related", "post_link"].map((t) => [t, actions.filter((x) => x.type === t).length])
|
|
17508
|
+
),
|
|
17509
|
+
actions: [
|
|
17510
|
+
...actions.filter((x) => x.type === "menu" || x.type === "footer"),
|
|
17511
|
+
...actions.filter((x) => x.type === "post_link").sort((x, y) => Number(y.match) - Number(x.match)).slice(0, 30),
|
|
17512
|
+
...actions.filter((x) => x.type === "page_related").slice(0, 30)
|
|
17513
|
+
],
|
|
17514
|
+
findings,
|
|
17515
|
+
how: "Apply page_related and post_link actions with wp_internal_links_apply (preview first); menu actions with wp_menu_set, footer with wp_footer_set."
|
|
17516
|
+
};
|
|
17517
|
+
}
|
|
17518
|
+
var esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
17519
|
+
function relatedBlock(heading2, links2) {
|
|
17520
|
+
const items3 = links2.map((l) => `<!-- wp:list-item -->
|
|
17521
|
+
<li><a href="${esc(l.url)}">${esc(l.label)}</a></li>
|
|
17522
|
+
<!-- /wp:list-item -->`).join("\n");
|
|
17523
|
+
return `<!-- wp:group {"metadata":{"name":"Related links","maggie":{"type":"related-links","version":1}},"align":"wide","className":"maggie-related-links","layout":{"type":"constrained"}} -->
|
|
17524
|
+
<div class="wp-block-group alignwide maggie-related-links"><!-- wp:heading {"level":2} -->
|
|
17525
|
+
<h2 class="wp-block-heading">${esc(heading2)}</h2>
|
|
17526
|
+
<!-- /wp:heading -->
|
|
17527
|
+
|
|
17528
|
+
<!-- wp:list -->
|
|
17529
|
+
<ul class="wp-block-list">${items3}</ul>
|
|
17530
|
+
<!-- /wp:list --></div>
|
|
17531
|
+
<!-- /wp:group -->`;
|
|
17532
|
+
}
|
|
17533
|
+
function postLinkBlock(text3, url, label2) {
|
|
17534
|
+
return `<!-- wp:paragraph {"className":"maggie-related-link"} -->
|
|
17535
|
+
<p class="maggie-related-link">${esc(text3)} <a href="${esc(url)}">${esc(label2)}</a></p>
|
|
17536
|
+
<!-- /wp:paragraph -->`;
|
|
17537
|
+
}
|
|
17538
|
+
async function llmsTxt(site, o = {}) {
|
|
17539
|
+
const base = (site.url ?? "").replace(/\/+$/, "");
|
|
17540
|
+
const s = await site.request({
|
|
17541
|
+
path: "/wp/v2/settings",
|
|
17542
|
+
query: { _fields: "title,description,page_on_front,page_for_posts" }
|
|
17543
|
+
}).then((r) => r.status === 200 ? r.data : {});
|
|
17544
|
+
const pages = await listPages(site, { status: "publish" });
|
|
17545
|
+
const posts = await all(
|
|
17546
|
+
site,
|
|
17547
|
+
"/wp/v2/posts",
|
|
17548
|
+
{ status: "publish", per_page: 100, _fields: "link,title,excerpt,meta", orderby: "date", order: "desc" },
|
|
17549
|
+
o.posts ?? 25
|
|
17550
|
+
);
|
|
17551
|
+
const desc = (m, fallback = "") => String(m?.maggie_seo_description || fallback).replace(/\s+/g, " ").trim();
|
|
17552
|
+
const home = pages.find((p) => p.id === s.page_on_front);
|
|
17553
|
+
const noise = /privacy|terms|cookie|thank|cart|checkout|my-account|login/i;
|
|
17554
|
+
const visible = pages.filter((p) => p.id !== s.page_on_front && p.id !== s.page_for_posts && !noise.test(p.link));
|
|
17555
|
+
const byParent = /* @__PURE__ */ new Map();
|
|
17556
|
+
for (const p of visible) byParent.set(p.parent, [...byParent.get(p.parent) ?? [], p]);
|
|
17557
|
+
const line = (title, url, d) => `- [${title.replace(/[[\]]/g, "")}](${url})${d ? `: ${d}` : ""}`;
|
|
17558
|
+
const out = [`# ${s.title || base.replace(/^https?:\/\//, "")}`, ""];
|
|
17559
|
+
const summary = desc(home?.meta, s.description ?? "");
|
|
17560
|
+
if (summary) out.push(`> ${summary}`, "");
|
|
17561
|
+
const top = byParent.get(0) ?? [];
|
|
17562
|
+
if (top.length) {
|
|
17563
|
+
out.push("## Pages", "");
|
|
17564
|
+
for (const p of top) {
|
|
17565
|
+
out.push(line(titleOf(p.title), p.link, desc(p.meta)));
|
|
17566
|
+
for (const c of byParent.get(p.id) ?? []) out.push(` ${line(titleOf(c.title), c.link, desc(c.meta))}`);
|
|
17567
|
+
}
|
|
17568
|
+
out.push("");
|
|
17569
|
+
}
|
|
17570
|
+
if (posts.length) {
|
|
17571
|
+
out.push("## Articles", "");
|
|
17572
|
+
for (const p of posts)
|
|
17573
|
+
out.push(
|
|
17574
|
+
line(strip(p.title.rendered ?? ""), p.link, desc(p.meta, strip(p.excerpt?.rendered ?? "").slice(0, 160)))
|
|
17575
|
+
);
|
|
17576
|
+
out.push("");
|
|
17577
|
+
}
|
|
17578
|
+
const legal = pages.filter((p) => /privacy|terms/i.test(p.link));
|
|
17579
|
+
out.push("## Optional", "", line("Sitemap", `${base}/wp-sitemap.xml`, "every page and article"));
|
|
17580
|
+
for (const p of legal) out.push(line(titleOf(p.title), p.link, ""));
|
|
17581
|
+
return `${out.join("\n").replace(/\n{3,}/g, "\n\n").trim()}
|
|
17582
|
+
`;
|
|
17583
|
+
}
|
|
17584
|
+
|
|
16217
17585
|
// ../../packages/tools/src/wordpress.ts
|
|
16218
17586
|
var sites = /* @__PURE__ */ new WeakMap();
|
|
16219
17587
|
function siteOf(ctx) {
|
|
@@ -18715,8 +20083,276 @@ var fullTools = [
|
|
|
18715
20083
|
}
|
|
18716
20084
|
})
|
|
18717
20085
|
];
|
|
20086
|
+
var securityTools = [
|
|
20087
|
+
tool({
|
|
20088
|
+
name: "wp_security_scan",
|
|
20089
|
+
description: "Security check of the connected WordPress site: plugins, themes and WordPress against known vulnerabilities (WPVulnerability), available updates and plugins closed on WordPress.org; with Maggie Core 0.14+ also PHP/database end of life, risky settings (errors shown, open registration, file editing, XML-RPC), Administrators and old application passwords, and WP-Cron jobs (late, or left by removed plugins); from outside: security headers, public .env/.git/config backups/error logs, login-name leaks. Findings are ranked p0 (fix today) \u2026 p4 (for information), each with why and the fix (a tool when one can do it). Read-only.",
|
|
20090
|
+
parameters: {
|
|
20091
|
+
type: "object",
|
|
20092
|
+
properties: {
|
|
20093
|
+
vulnerabilities: bool("Check known vulnerabilities (default true)."),
|
|
20094
|
+
outside: bool("Check from outside like a visitor (default true).")
|
|
20095
|
+
}
|
|
20096
|
+
},
|
|
20097
|
+
group: "site",
|
|
20098
|
+
need: READ,
|
|
20099
|
+
risk: "R0",
|
|
20100
|
+
gates: ["WP"],
|
|
20101
|
+
run: (ctx, a) => securityScan(siteOf(ctx), { vulnerabilities: a.vulnerabilities !== false, outside: a.outside !== false })
|
|
20102
|
+
}),
|
|
20103
|
+
tool({
|
|
20104
|
+
name: "wp_plugin_update",
|
|
20105
|
+
description: "Update one installed plugin to its latest version (plugin id from wp_plugins_list or wp_security_scan, e.g. wpforms-lite/wpforms), then check the homepage still opens. Needs Maggie Core 0.14+. WordPress keeps no copy of the old version: for a big plugin (shop, page builder) suggest a backup first.",
|
|
20106
|
+
parameters: { type: "object", properties: { plugin: str2("Plugin id (folder/file).") }, required: ["plugin"] },
|
|
20107
|
+
group: "site",
|
|
20108
|
+
need: WRITE,
|
|
20109
|
+
risk: "W3",
|
|
20110
|
+
gates: [...GATES],
|
|
20111
|
+
confirm: (a, lang) => say(
|
|
20112
|
+
lang,
|
|
20113
|
+
`Update the plugin ${q2(a.plugin, "")} on your website to its latest version (the old version is not kept).`,
|
|
20114
|
+
`\u628A\u7DB2\u7AD9\u4E0A\u7684\u63D2\u4EF6 ${q2(a.plugin, "")} \u66F4\u65B0\u5230\u6700\u65B0\u7248\uFF08\u4E0D\u4FDD\u7559\u820A\u7248\uFF09\u3002`
|
|
20115
|
+
),
|
|
20116
|
+
run: async (ctx, a) => {
|
|
20117
|
+
const site = siteOf(ctx);
|
|
20118
|
+
const r = await call(site, {
|
|
20119
|
+
method: "POST",
|
|
20120
|
+
path: "/maggie-core/v1/plugins/update",
|
|
20121
|
+
body: { plugin: String(a.plugin ?? "").replace(/\.php$/, "") }
|
|
20122
|
+
});
|
|
20123
|
+
const home = site.url ? await check(site, `${site.url}/`, "publish") : null;
|
|
20124
|
+
return {
|
|
20125
|
+
...r,
|
|
20126
|
+
check: home,
|
|
20127
|
+
...home && !home.ok ? {
|
|
20128
|
+
warning: "The homepage has a problem after the update: deactivate the plugin (wp_plugin_set inactive) and tell the owner."
|
|
20129
|
+
} : {}
|
|
20130
|
+
};
|
|
20131
|
+
}
|
|
20132
|
+
}),
|
|
20133
|
+
tool({
|
|
20134
|
+
name: "wp_cron_unschedule",
|
|
20135
|
+
description: "Remove a WP-Cron job that nothing runs any more (left by a removed plugin; wp_security_scan lists them). WordPress's own jobs and jobs a plugin still handles are refused. Needs Maggie Core 0.14+.",
|
|
20136
|
+
parameters: { type: "object", properties: { hook: str2("The job's hook name.") }, required: ["hook"] },
|
|
20137
|
+
group: "site",
|
|
20138
|
+
need: WRITE,
|
|
20139
|
+
risk: "W2",
|
|
20140
|
+
gates: [...GATES],
|
|
20141
|
+
confirm: (a, lang) => say(
|
|
20142
|
+
lang,
|
|
20143
|
+
`Remove the scheduled job ${q2(a.hook, "")} from your website (nothing runs it any more).`,
|
|
20144
|
+
`\u79FB\u9664\u7DB2\u7AD9\u4E0A\u5DF2\u7121\u7A0B\u5F0F\u8655\u7406\u7684\u6392\u7A0B\u5DE5\u4F5C ${q2(a.hook, "")}\u3002`
|
|
20145
|
+
),
|
|
20146
|
+
run: (ctx, a) => call(siteOf(ctx), {
|
|
20147
|
+
method: "POST",
|
|
20148
|
+
path: "/maggie-core/v1/cron/unschedule",
|
|
20149
|
+
body: { hook: String(a.hook ?? "") }
|
|
20150
|
+
})
|
|
20151
|
+
})
|
|
20152
|
+
];
|
|
20153
|
+
var LINK_ACTION = obj("One action from wp_internal_links_plan.", {
|
|
20154
|
+
type: { type: "string", enum: ["page_related", "post_link"], description: "page_related or post_link." },
|
|
20155
|
+
page: int2("page_related: the page id."),
|
|
20156
|
+
heading: str2(`page_related: the band's heading, e.g. "Related" or "From the blog".`),
|
|
20157
|
+
links: arr("page_related: links to list.", obj("", { url: str2(""), label: str2("") })),
|
|
20158
|
+
post: int2("post_link: the article id."),
|
|
20159
|
+
url: str2("post_link: the page to link to."),
|
|
20160
|
+
label: str2("post_link: the link text (the page's topic)."),
|
|
20161
|
+
text: str2('post_link: words before the link (default "Related:").')
|
|
20162
|
+
});
|
|
20163
|
+
function withRelated(blocks, heading2, links2) {
|
|
20164
|
+
const band2 = parse(relatedBlock(heading2, links2)).filter((b) => b.name);
|
|
20165
|
+
const isBand = (b) => String(b.attrs.className ?? "").includes("maggie-related-links") && serialize([b]).includes(`>${heading2.replace(/&/g, "&").replace(/</g, "<")}</h2>`);
|
|
20166
|
+
const at = blocks.findIndex(isBand);
|
|
20167
|
+
if (at >= 0) return [...blocks.slice(0, at), ...band2, ...blocks.slice(at + 1)];
|
|
20168
|
+
const real = blocks.map((b, i) => [b, i]).filter(([b]) => b.name);
|
|
20169
|
+
const last = real[real.length - 1];
|
|
20170
|
+
const lastType = last ? classify(last[0], "main") : "";
|
|
20171
|
+
if (last && /cta|form|map-contact|contact/.test(lastType))
|
|
20172
|
+
return [...blocks.slice(0, last[1]), ...band2, ...blocks.slice(last[1])];
|
|
20173
|
+
return [...blocks, ...band2];
|
|
20174
|
+
}
|
|
20175
|
+
var seoTechTools = [
|
|
20176
|
+
tool({
|
|
20177
|
+
name: "wp_seo_tech_audit",
|
|
20178
|
+
description: "Technical SEO check of the connected site, like a crawler: robots.txt (sitemap line, Google or AI crawlers blocked), the sitemap and every page it lists (status, redirects, noindex in the sitemap, canonicals pointing elsewhere, H1 count, missing or duplicate titles and descriptions, long titles, pictures without alt text, broken structured data, thin pages), broken and redirected internal links, generic link words, llms.txt; speed: true adds Core Web Vitals for the homepage (PageSpeed Insights). Findings ranked p0\u2026p4 with the fix and a tool when one can do it. Read-only. Internal-link layout: wp_internal_links_plan.",
|
|
20179
|
+
parameters: {
|
|
20180
|
+
type: "object",
|
|
20181
|
+
properties: {
|
|
20182
|
+
limit: int2("Pages to crawl from the sitemap (default 60, max 200)."),
|
|
20183
|
+
speed: bool("Also measure the homepage's speed on phones (slower, about 30 s).")
|
|
20184
|
+
}
|
|
20185
|
+
},
|
|
20186
|
+
group: "site",
|
|
20187
|
+
need: READ,
|
|
20188
|
+
risk: "R0",
|
|
20189
|
+
gates: ["WP"],
|
|
20190
|
+
run: (ctx, a) => techAudit(siteOf(ctx), { limit: typeof a.limit === "number" ? a.limit : void 0, speed: !!a.speed })
|
|
20191
|
+
}),
|
|
20192
|
+
tool({
|
|
20193
|
+
name: "wp_internal_links_plan",
|
|
20194
|
+
description: "Plan the site's internal links from its own pages, articles, menu, header and footer: menu items that lead nowhere, main pages missing from the menu, legal/contact/about pages missing from the footer, hub pages that don't list their sub-pages and sub-pages that don't link back, articles that don't link to the page they are about (matched by topic) and pages that don't show their articles, and pages or articles nothing links to. Returns actions ready for wp_internal_links_apply (page_related, post_link) or wp_menu_set / wp_footer_set. Read-only.",
|
|
20195
|
+
parameters: { type: "object", properties: { posts: int2("Articles to include (default 200, newest first).") } },
|
|
20196
|
+
group: "site",
|
|
20197
|
+
need: READ,
|
|
20198
|
+
risk: "R0",
|
|
20199
|
+
gates: ["WP"],
|
|
20200
|
+
run: (ctx, a) => linksPlan(siteOf(ctx), { posts: typeof a.posts === "number" ? a.posts : void 0 })
|
|
20201
|
+
}),
|
|
20202
|
+
tool({
|
|
20203
|
+
name: "wp_internal_links_apply",
|
|
20204
|
+
description: 'Apply internal-link actions from wp_internal_links_plan: page_related puts a "Related" band (heading + list of links) in a page, replacing its own earlier band with the same heading, placed before a closing call-to-action; post_link adds one "Related: <page>" line at the end of an article (replacing its earlier one). preview: true shows the changes and saves nothing. Pages: wp_page_undo; articles: their revisions.',
|
|
20205
|
+
parameters: {
|
|
20206
|
+
type: "object",
|
|
20207
|
+
properties: { actions: arr("Up to 20 actions.", LINK_ACTION), preview: PREVIEW },
|
|
20208
|
+
required: ["actions"]
|
|
20209
|
+
},
|
|
20210
|
+
group: "site",
|
|
20211
|
+
need: WRITE,
|
|
20212
|
+
risk: "W3",
|
|
20213
|
+
gates: [...GATES],
|
|
20214
|
+
confirm: (a, lang) => {
|
|
20215
|
+
const n2 = Array.isArray(a.actions) ? a.actions.length : 0;
|
|
20216
|
+
return say(
|
|
20217
|
+
lang,
|
|
20218
|
+
`Add internal links on your website (${n2} ${n2 === 1 ? "change" : "changes"}: related-links bands on pages, a related line at the end of articles).`,
|
|
20219
|
+
`\u5728\u7DB2\u7AD9\u4E0A\u52A0\u5165\u5167\u90E8\u9023\u7D50\uFF08${n2} \u9805\uFF1A\u9801\u9762\u7684\u76F8\u95DC\u9023\u7D50\u5340\u584A\u3001\u6587\u7AE0\u7D50\u5C3E\u7684\u76F8\u95DC\u9023\u7D50\uFF09\u3002`
|
|
20220
|
+
);
|
|
20221
|
+
},
|
|
20222
|
+
run: async (ctx, a) => {
|
|
20223
|
+
const site = siteOf(ctx);
|
|
20224
|
+
const acts = Array.isArray(a.actions) ? a.actions : [];
|
|
20225
|
+
if (!acts.length) throw new Error("actions: give at least one action from wp_internal_links_plan.");
|
|
20226
|
+
if (acts.length > 20) throw new Error("actions: up to 20 at a time.");
|
|
20227
|
+
const results = [];
|
|
20228
|
+
const byPage = /* @__PURE__ */ new Map();
|
|
20229
|
+
for (const x of acts) {
|
|
20230
|
+
if (x.type === "page_related") {
|
|
20231
|
+
if (!x.page || !x.links?.length) throw new Error("page_related needs page and links.");
|
|
20232
|
+
byPage.set(x.page, [...byPage.get(x.page) ?? [], x]);
|
|
20233
|
+
} else if (x.type === "post_link") {
|
|
20234
|
+
if (!x.post || !x.url || !x.label) throw new Error("post_link needs post, url and label.");
|
|
20235
|
+
} else throw new Error(`Unknown action type ${x.type}.`);
|
|
20236
|
+
}
|
|
20237
|
+
for (const [page, list3] of byPage) {
|
|
20238
|
+
const r = await changePage(ctx, { page, preview: !!a.preview }, (blocks) => {
|
|
20239
|
+
let next = blocks;
|
|
20240
|
+
for (const x of list3)
|
|
20241
|
+
next = withRelated(next, (x.heading || "Related").slice(0, 80), (x.links ?? []).slice(0, 12));
|
|
20242
|
+
return { blocks: next, note: { related: list3.map((x) => x.heading || "Related") } };
|
|
20243
|
+
});
|
|
20244
|
+
results.push({ type: "page_related", page_id: page, ...r });
|
|
20245
|
+
}
|
|
20246
|
+
for (const x of acts.filter((y) => y.type === "post_link")) {
|
|
20247
|
+
const post = await call(site, {
|
|
20248
|
+
path: `/wp/v2/posts/${Number(x.post)}`,
|
|
20249
|
+
query: { context: "edit", _fields: "id,link,content,modified" }
|
|
20250
|
+
});
|
|
20251
|
+
const kept = parse(post.content.raw).filter(
|
|
20252
|
+
(b) => !(b.name === "core/paragraph" && String(b.attrs.className ?? "").includes("maggie-related-link"))
|
|
20253
|
+
);
|
|
20254
|
+
const line = parse(postLinkBlock(x.text || "Related:", String(x.url), String(x.label))).filter((b) => b.name);
|
|
20255
|
+
const content = serialize([...kept, ...line]);
|
|
20256
|
+
if (a.preview) {
|
|
20257
|
+
results.push({
|
|
20258
|
+
type: "post_link",
|
|
20259
|
+
post: post.id,
|
|
20260
|
+
path: post.link,
|
|
20261
|
+
preview: true,
|
|
20262
|
+
adds: `${x.text || "Related:"} ${x.label} \u2192 ${x.url}`
|
|
20263
|
+
});
|
|
20264
|
+
continue;
|
|
20265
|
+
}
|
|
20266
|
+
const saved = await call(site, {
|
|
20267
|
+
method: "POST",
|
|
20268
|
+
path: `/wp/v2/posts/${post.id}`,
|
|
20269
|
+
query: { _fields: "id,link,modified" },
|
|
20270
|
+
body: { content }
|
|
20271
|
+
});
|
|
20272
|
+
results.push({
|
|
20273
|
+
type: "post_link",
|
|
20274
|
+
post: saved.id,
|
|
20275
|
+
path: saved.link,
|
|
20276
|
+
saved: true,
|
|
20277
|
+
modified: saved.modified,
|
|
20278
|
+
link: { url: x.url, label: x.label }
|
|
20279
|
+
});
|
|
20280
|
+
}
|
|
20281
|
+
return {
|
|
20282
|
+
results,
|
|
20283
|
+
...a.preview ? { preview: true } : { undo: "Pages: wp_page_undo; articles: restore the earlier revision in the editor." }
|
|
20284
|
+
};
|
|
20285
|
+
}
|
|
20286
|
+
}),
|
|
20287
|
+
tool({
|
|
20288
|
+
name: "wp_llms_txt_get",
|
|
20289
|
+
description: "The site's llms.txt (a Markdown map of the site for AI assistants, served at /llms.txt): the saved text, whether /llms.txt answers, and whether a file on the server overrides it. Needs Maggie Core 0.14+.",
|
|
20290
|
+
parameters: { type: "object", properties: {} },
|
|
20291
|
+
group: "site",
|
|
20292
|
+
need: READ,
|
|
20293
|
+
risk: "R0",
|
|
20294
|
+
gates: ["WP"],
|
|
20295
|
+
run: async (ctx) => {
|
|
20296
|
+
const site = siteOf(ctx);
|
|
20297
|
+
const saved = await call(site, { path: "/maggie-core/v1/llms" });
|
|
20298
|
+
const live = site.url ? await fetch(`${site.url}/llms.txt`, { signal: AbortSignal.timeout(1e4) }).then(async (r) => ({ status: r.status, same: r.ok && (await r.text()).trim() === saved.text.trim() })).catch(() => null) : null;
|
|
20299
|
+
return {
|
|
20300
|
+
...saved,
|
|
20301
|
+
live,
|
|
20302
|
+
...saved.file ? {
|
|
20303
|
+
note: "A real llms.txt file on the server is served instead of the saved text: delete it at the host to use this one."
|
|
20304
|
+
} : {}
|
|
20305
|
+
};
|
|
20306
|
+
}
|
|
20307
|
+
}),
|
|
20308
|
+
tool({
|
|
20309
|
+
name: "wp_llms_txt_set",
|
|
20310
|
+
description: `Write the site's llms.txt (served at /llms.txt): generate: true builds it from the site (name and summary, pages with their SEO descriptions grouped under their parents, the latest articles, sitemap); or give text (Markdown); "" turns it off. preview: true returns the text without saving. Needs Maggie Core 0.14+.`,
|
|
20311
|
+
parameters: {
|
|
20312
|
+
type: "object",
|
|
20313
|
+
properties: {
|
|
20314
|
+
generate: bool("Build it from the site."),
|
|
20315
|
+
text: str2("The llms.txt Markdown to save."),
|
|
20316
|
+
posts: int2("Articles to list when generating (default 25)."),
|
|
20317
|
+
preview: PREVIEW
|
|
20318
|
+
}
|
|
20319
|
+
},
|
|
20320
|
+
group: "site",
|
|
20321
|
+
need: WRITE,
|
|
20322
|
+
risk: "W2",
|
|
20323
|
+
gates: [...GATES],
|
|
20324
|
+
confirm: (a, lang) => say(
|
|
20325
|
+
lang,
|
|
20326
|
+
a.text === "" ? "Turn off your website's llms.txt." : "Write your website's llms.txt (the map of the site for AI assistants, at /llms.txt).",
|
|
20327
|
+
a.text === "" ? "\u95DC\u9589\u7DB2\u7AD9\u7684 llms.txt\u3002" : "\u5BEB\u5165\u7DB2\u7AD9\u7684 llms.txt\uFF08\u7D66 AI \u52A9\u7406\u7684\u7DB2\u7AD9\u5730\u5716\uFF0C\u4F4D\u65BC /llms.txt\uFF09\u3002"
|
|
20328
|
+
),
|
|
20329
|
+
run: async (ctx, a) => {
|
|
20330
|
+
const site = siteOf(ctx);
|
|
20331
|
+
const text3 = typeof a.text === "string" ? a.text : a.generate ? await llmsTxt(site, { posts: typeof a.posts === "number" ? a.posts : void 0 }) : null;
|
|
20332
|
+
if (text3 == null) throw new Error("Give text, or generate: true.");
|
|
20333
|
+
if (/<\?(php|=)?|<script\b/i.test(text3)) throw new Error("llms.txt: plain Markdown only.");
|
|
20334
|
+
if (a.preview) return { preview: true, text: text3, characters: text3.length };
|
|
20335
|
+
const r = await call(site, {
|
|
20336
|
+
method: "POST",
|
|
20337
|
+
path: "/maggie-core/v1/llms",
|
|
20338
|
+
body: { text: text3 }
|
|
20339
|
+
});
|
|
20340
|
+
return {
|
|
20341
|
+
saved: r.saved,
|
|
20342
|
+
url: r.url,
|
|
20343
|
+
characters: text3.length,
|
|
20344
|
+
before_characters: r.before.length,
|
|
20345
|
+
...r.file ? { note: "A real llms.txt file on the server is served instead: delete it at the host." } : {},
|
|
20346
|
+
undo: r.before ? "wp_llms_txt_set text with the earlier text (before is kept in this result)" : 'wp_llms_txt_set text ""',
|
|
20347
|
+
before: r.before
|
|
20348
|
+
};
|
|
20349
|
+
}
|
|
20350
|
+
})
|
|
20351
|
+
];
|
|
18718
20352
|
var wordpressTools = [
|
|
18719
20353
|
...fullTools,
|
|
20354
|
+
...securityTools,
|
|
20355
|
+
...seoTechTools,
|
|
18720
20356
|
...siteTools,
|
|
18721
20357
|
...pageTools,
|
|
18722
20358
|
...sectionTools,
|
|
@@ -18794,7 +20430,7 @@ __export(util_exports, {
|
|
|
18794
20430
|
defineLazy: () => defineLazy,
|
|
18795
20431
|
defineLazyInternal: () => defineLazyInternal,
|
|
18796
20432
|
derived: () => derived,
|
|
18797
|
-
esc: () =>
|
|
20433
|
+
esc: () => esc2,
|
|
18798
20434
|
escapeRegex: () => escapeRegex,
|
|
18799
20435
|
explicitlyAborted: () => explicitlyAborted,
|
|
18800
20436
|
extend: () => extend,
|
|
@@ -19025,7 +20661,7 @@ function randomString(length = 10) {
|
|
|
19025
20661
|
}
|
|
19026
20662
|
return str3;
|
|
19027
20663
|
}
|
|
19028
|
-
function
|
|
20664
|
+
function esc2(str3) {
|
|
19029
20665
|
return JSON.stringify(str3);
|
|
19030
20666
|
}
|
|
19031
20667
|
function slugify(input) {
|
|
@@ -21174,14 +22810,14 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
21174
22810
|
const desc = Object.getOwnPropertyDescriptor(def, "shape");
|
|
21175
22811
|
const sh = desc?.get ? desc.get.raw : def.shape ?? {};
|
|
21176
22812
|
if (sh) {
|
|
21177
|
-
const
|
|
22813
|
+
const get2 = () => {
|
|
21178
22814
|
const newSh = { ...sh };
|
|
21179
22815
|
Object.defineProperty(def, "shape", { value: newSh });
|
|
21180
|
-
|
|
22816
|
+
get2.raw = newSh;
|
|
21181
22817
|
return newSh;
|
|
21182
22818
|
};
|
|
21183
|
-
|
|
21184
|
-
Object.defineProperty(def, "shape", { get });
|
|
22819
|
+
get2.raw = sh;
|
|
22820
|
+
Object.defineProperty(def, "shape", { get: get2 });
|
|
21185
22821
|
}
|
|
21186
22822
|
const _normalized = cached(() => normalizeDef(def));
|
|
21187
22823
|
defineLazyInternal(inst, "propValues", (zod) => {
|
|
@@ -21280,7 +22916,7 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
21280
22916
|
if (key === "__proto__")
|
|
21281
22917
|
continue;
|
|
21282
22918
|
const id = ids2[key];
|
|
21283
|
-
const k = typeof key === "symbol" ? `syms[${syms.indexOf(key)}]` :
|
|
22919
|
+
const k = typeof key === "symbol" ? `syms[${syms.indexOf(key)}]` : esc2(key);
|
|
21284
22920
|
const isPresent = `${k} in input`;
|
|
21285
22921
|
const schema = shape[key];
|
|
21286
22922
|
const optin = schema?._zod?.optin;
|
|
@@ -24252,7 +25888,7 @@ var parseAsync2 = /* @__PURE__ */ _parseAsync(ZodRealError);
|
|
|
24252
25888
|
var safeParse3 = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
24253
25889
|
var safeParseAsync2 = /* @__PURE__ */ _safeParseAsync(ZodRealError);
|
|
24254
25890
|
var encode2 = /* @__PURE__ */ _encode(ZodRealError);
|
|
24255
|
-
var
|
|
25891
|
+
var decode4 = /* @__PURE__ */ _decode(ZodRealError);
|
|
24256
25892
|
var encodeAsync2 = /* @__PURE__ */ _encodeAsync(ZodRealError);
|
|
24257
25893
|
var decodeAsync2 = /* @__PURE__ */ _decodeAsync(ZodRealError);
|
|
24258
25894
|
var safeEncode2 = /* @__PURE__ */ _safeEncode(ZodRealError);
|
|
@@ -24412,7 +26048,7 @@ var ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
|
|
|
24412
26048
|
return encode2(this, data, params, { callee: _encode2 });
|
|
24413
26049
|
},
|
|
24414
26050
|
decode: function _decode2(data, params) {
|
|
24415
|
-
return
|
|
26051
|
+
return decode4(this, data, params, { callee: _decode2 });
|
|
24416
26052
|
},
|
|
24417
26053
|
encodeAsync: async function _encodeAsync2(data, params) {
|
|
24418
26054
|
return await encodeAsync2(this, data, params, { callee: _encodeAsync2 });
|
|
@@ -29297,7 +30933,7 @@ var fileStore = () => {
|
|
|
29297
30933
|
const file = join(configDir(), "credentials.json");
|
|
29298
30934
|
return {
|
|
29299
30935
|
load: () => readJson(file),
|
|
29300
|
-
save: (
|
|
30936
|
+
save: (tokens2) => writePrivate(file, tokens2),
|
|
29301
30937
|
clear: () => rm(file, { force: true })
|
|
29302
30938
|
};
|
|
29303
30939
|
};
|