@cmo-so/cli 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.mjs +1698 -32
- package/package.json +1 -1
package/dist/cmo.mjs
CHANGED
|
@@ -8337,26 +8337,26 @@ function createOAuthClient({ issuer, clientId, fetch: fetchImpl = globalThis.fet
|
|
|
8337
8337
|
|
|
8338
8338
|
// ../../packages/api-client/src/session.ts
|
|
8339
8339
|
function createSession({ oauth: oauth2, store, skewMs = 6e4, now = Date.now, onSignedOut }) {
|
|
8340
|
-
let
|
|
8340
|
+
let tokens2;
|
|
8341
8341
|
let refreshing = null;
|
|
8342
8342
|
async function current() {
|
|
8343
|
-
if (
|
|
8344
|
-
return
|
|
8343
|
+
if (tokens2 === void 0) tokens2 = await store.load();
|
|
8344
|
+
return tokens2;
|
|
8345
8345
|
}
|
|
8346
8346
|
async function accept(res, previous) {
|
|
8347
8347
|
const refreshToken = res.refresh_token ?? previous?.refreshToken;
|
|
8348
8348
|
if (!refreshToken) throw new SignInRequiredError("The sign-in did not return a refresh token.");
|
|
8349
|
-
|
|
8349
|
+
tokens2 = {
|
|
8350
8350
|
refreshToken,
|
|
8351
8351
|
accessToken: res.access_token,
|
|
8352
8352
|
expiresAt: now() + res.expires_in * 1e3,
|
|
8353
8353
|
scope: res.scope
|
|
8354
8354
|
};
|
|
8355
|
-
await store.save(
|
|
8356
|
-
return
|
|
8355
|
+
await store.save(tokens2);
|
|
8356
|
+
return tokens2;
|
|
8357
8357
|
}
|
|
8358
8358
|
async function end() {
|
|
8359
|
-
|
|
8359
|
+
tokens2 = null;
|
|
8360
8360
|
await store.clear();
|
|
8361
8361
|
onSignedOut?.();
|
|
8362
8362
|
}
|
|
@@ -12082,12 +12082,12 @@ var socialTools = [
|
|
|
12082
12082
|
need: write5,
|
|
12083
12083
|
risk: "W1",
|
|
12084
12084
|
gates: ["VER"],
|
|
12085
|
-
run: async (ctx, { id, words, style, text_effect, order, remove: remove3 }) => {
|
|
12085
|
+
run: async (ctx, { id, words, style, text_effect, order: order2, remove: remove3 }) => {
|
|
12086
12086
|
const out = await ws(ctx).editSocialPicture(Number(id), {
|
|
12087
12087
|
...Array.isArray(words) ? { words: words.map((w) => ({ headline: String(w.headline ?? ""), sub: String(w.sub ?? "") })) } : {},
|
|
12088
12088
|
...style ? { style } : {},
|
|
12089
12089
|
...text_effect ? { text_effect } : {},
|
|
12090
|
-
...Array.isArray(
|
|
12090
|
+
...Array.isArray(order2) ? { order: order2.map(Number) } : {},
|
|
12091
12091
|
...Array.isArray(remove3) ? { remove: remove3.map(Number) } : {}
|
|
12092
12092
|
});
|
|
12093
12093
|
return { id: out.id, pictures: out.image_urls?.length ? out.image_urls : [out.image_url], picture: out.picture };
|
|
@@ -15011,12 +15011,12 @@ async function menuGet(site, id) {
|
|
|
15011
15011
|
const nav = await menuPost(site, id);
|
|
15012
15012
|
const blocks = parse(nav.content.raw);
|
|
15013
15013
|
const other = blocks.filter((b) => b.name && !["core/navigation-link", "core/navigation-submenu"].includes(b.name)).map((b) => b.name);
|
|
15014
|
-
const
|
|
15014
|
+
const strip2 = (list3) => list3.map(({ attrs: _a3, ...i }) => ({ ...i, ...i.children ? { children: strip2(i.children) } : {} }));
|
|
15015
15015
|
return {
|
|
15016
15016
|
id: nav.id,
|
|
15017
15017
|
title: nav.title.raw,
|
|
15018
15018
|
modified: nav.modified,
|
|
15019
|
-
items:
|
|
15019
|
+
items: strip2(toItems(blocks)),
|
|
15020
15020
|
other_blocks: other
|
|
15021
15021
|
};
|
|
15022
15022
|
}
|
|
@@ -15098,8 +15098,8 @@ async function menuSet(site, ops2, id) {
|
|
|
15098
15098
|
query: { _fields: "id,modified" },
|
|
15099
15099
|
body: { content }
|
|
15100
15100
|
});
|
|
15101
|
-
const
|
|
15102
|
-
return { id: nav.id, before:
|
|
15101
|
+
const strip2 = (list3) => list3.flatMap((i) => [i.label, ...(i.children ?? []).map((c) => ` ${c.label}`)]);
|
|
15102
|
+
return { id: nav.id, before: strip2(before), after: strip2(after) };
|
|
15103
15103
|
}
|
|
15104
15104
|
async function partGet(site, slug) {
|
|
15105
15105
|
const parts = await call(
|
|
@@ -15603,6 +15603,492 @@ ${rulesOf(o.current ?? "")}
|
|
|
15603
15603
|
`;
|
|
15604
15604
|
}
|
|
15605
15605
|
|
|
15606
|
+
// ../../packages/tools/src/wp/security.ts
|
|
15607
|
+
var order = ["p0", "p1", "p2", "p3", "p4"];
|
|
15608
|
+
var lower = (p, n2 = 1) => order[Math.min(4, order.indexOf(p) + n2)];
|
|
15609
|
+
function cmpVersion(a, b) {
|
|
15610
|
+
const pa = String(a).split(/[.\-+]/).map((x) => Number.parseInt(x, 10) || 0);
|
|
15611
|
+
const pb = String(b).split(/[.\-+]/).map((x) => Number.parseInt(x, 10) || 0);
|
|
15612
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
15613
|
+
const d = (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
15614
|
+
if (d) return d > 0 ? 1 : -1;
|
|
15615
|
+
}
|
|
15616
|
+
return 0;
|
|
15617
|
+
}
|
|
15618
|
+
var opOk = (v, op, bound) => {
|
|
15619
|
+
if (!bound || !op) return true;
|
|
15620
|
+
const c = cmpVersion(v, bound);
|
|
15621
|
+
return op === "lt" ? c < 0 : op === "le" ? c <= 0 : op === "gt" ? c > 0 : op === "ge" ? c >= 0 : op === "eq" ? c === 0 : true;
|
|
15622
|
+
};
|
|
15623
|
+
function affects(v, version2) {
|
|
15624
|
+
const o = v.operator ?? {};
|
|
15625
|
+
if (o.unfixed === "1" && !o.max_version) return true;
|
|
15626
|
+
return opOk(version2, o.min_operator, o.min_version) && opOk(version2, o.max_operator, o.max_version);
|
|
15627
|
+
}
|
|
15628
|
+
var sevPriority = (sev, score) => sev === "c" || score >= 9 ? "p0" : sev === "h" || score >= 7 ? "p0" : sev === "m" || score >= 4 ? "p1" : "p2";
|
|
15629
|
+
var decode2 = (s) => s.replace(/–|–/g, "\u2013").replace(/&/g, "&").replace(/’/g, "\u2019").replace(/'|'/g, "'").replace(/"/g, '"');
|
|
15630
|
+
async function vulnDb(kind, slug) {
|
|
15631
|
+
const ctl = AbortSignal.timeout(15e3);
|
|
15632
|
+
const r = await fetch(`https://www.wpvulnerability.net/${kind}/${encodeURIComponent(slug)}/`, {
|
|
15633
|
+
signal: ctl,
|
|
15634
|
+
headers: { Accept: "application/json", "User-Agent": "CMO.so security check" }
|
|
15635
|
+
}).catch(() => null);
|
|
15636
|
+
if (!r || !r.ok) return null;
|
|
15637
|
+
const j = await r.json().catch(() => null);
|
|
15638
|
+
return j && !j.error ? j.data ?? null : null;
|
|
15639
|
+
}
|
|
15640
|
+
async function pool(items3, n2, fn) {
|
|
15641
|
+
const out = new Array(items3.length);
|
|
15642
|
+
let i = 0;
|
|
15643
|
+
await Promise.all(
|
|
15644
|
+
Array.from({ length: Math.min(n2, items3.length) }, async () => {
|
|
15645
|
+
while (i < items3.length) {
|
|
15646
|
+
const k = i++;
|
|
15647
|
+
out[k] = await fn(items3[k]);
|
|
15648
|
+
}
|
|
15649
|
+
})
|
|
15650
|
+
);
|
|
15651
|
+
return out;
|
|
15652
|
+
}
|
|
15653
|
+
var PHP_EOL = {
|
|
15654
|
+
"7.4": "2022-11-28",
|
|
15655
|
+
"8.0": "2023-11-26",
|
|
15656
|
+
"8.1": "2025-12-31",
|
|
15657
|
+
"8.2": "2026-12-31",
|
|
15658
|
+
"8.3": "2027-12-31",
|
|
15659
|
+
"8.4": "2028-12-31",
|
|
15660
|
+
"8.5": "2029-12-31"
|
|
15661
|
+
};
|
|
15662
|
+
async function outside(url, path3, opts = {}) {
|
|
15663
|
+
const r = await fetch(`${url}${path3}`, {
|
|
15664
|
+
redirect: opts.redirect ?? "manual",
|
|
15665
|
+
signal: AbortSignal.timeout(12e3),
|
|
15666
|
+
headers: { "User-Agent": "Mozilla/5.0 (compatible; CMO.so security check)" }
|
|
15667
|
+
}).catch(() => null);
|
|
15668
|
+
if (!r) return null;
|
|
15669
|
+
const text3 = r.status === 200 ? (await r.text().catch(() => "")).slice(0, 4e3) : "";
|
|
15670
|
+
return { status: r.status, headers: r.headers, location: r.headers.get("location") ?? "", text: text3 };
|
|
15671
|
+
}
|
|
15672
|
+
async function componentFindings(plugins, themes, core, updates, degraded) {
|
|
15673
|
+
const out = [];
|
|
15674
|
+
const upd = updates?.plugins && !Array.isArray(updates.plugins) ? updates.plugins : {};
|
|
15675
|
+
const pluginsData = await pool(plugins, 6, (p) => vulnDb("plugin", p.plugin.split("/")[0]));
|
|
15676
|
+
plugins.forEach((p, i) => {
|
|
15677
|
+
const d = pluginsData[i];
|
|
15678
|
+
const id = p.plugin.replace(/\.php$/, "");
|
|
15679
|
+
const active = p.status === "active";
|
|
15680
|
+
const newer = upd[id]?.new_version;
|
|
15681
|
+
if (d === null) degraded.push(`vulnerabilities of ${p.name}`);
|
|
15682
|
+
const hits = (d?.vulnerability ?? []).filter((v) => affects(v, p.version));
|
|
15683
|
+
if (hits.length) {
|
|
15684
|
+
const worst = hits.reduce(
|
|
15685
|
+
(m, v) => {
|
|
15686
|
+
const label2 = `${v.name} ${(v.source ?? []).map((x) => x.name).join(" ")}`;
|
|
15687
|
+
const pr = v.impact?.cvss?.severity ? sevPriority(v.impact.cvss.severity, Number(v.impact.cvss.score ?? 0)) : /unauthenticated/i.test(label2) ? "p0" : "p1";
|
|
15688
|
+
return order.indexOf(pr) < order.indexOf(m.p) ? { p: pr, v } : m;
|
|
15689
|
+
},
|
|
15690
|
+
{ p: "p2", v: hits[0] }
|
|
15691
|
+
);
|
|
15692
|
+
const unfixed = hits.some((v) => v.operator?.unfixed === "1");
|
|
15693
|
+
const fixedIn = hits.map((v) => v.operator?.max_version).filter(Boolean);
|
|
15694
|
+
const cves = hits.flatMap((v) => (v.source ?? []).map((s) => s.id)).filter((x) => /^CVE-/.test(x));
|
|
15695
|
+
out.push({
|
|
15696
|
+
id: `vuln:${id}`,
|
|
15697
|
+
priority: active ? worst.p : lower(worst.p),
|
|
15698
|
+
area: "plugins",
|
|
15699
|
+
title: `${p.name} ${p.version} has ${hits.length} known ${hits.length === 1 ? "vulnerability" : "vulnerabilities"}${active ? "" : " (inactive)"}`,
|
|
15700
|
+
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."}`,
|
|
15701
|
+
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.",
|
|
15702
|
+
...newer && !unfixed ? { tool: { name: "wp_plugin_update", args: { plugin: id } } } : { tool: { name: "wp_plugin_set", args: { plugin: id, status: active ? "inactive" : "deleted" } } },
|
|
15703
|
+
source: "wpvulnerability.net"
|
|
15704
|
+
});
|
|
15705
|
+
} else if (newer)
|
|
15706
|
+
out.push({
|
|
15707
|
+
id: `update:${id}`,
|
|
15708
|
+
priority: "p2",
|
|
15709
|
+
area: "plugins",
|
|
15710
|
+
title: `${p.name} can be updated (${p.version} \u2192 ${newer})`,
|
|
15711
|
+
why: "Updates often fix security problems before they are published.",
|
|
15712
|
+
fix: "Update it, then check the site.",
|
|
15713
|
+
tool: { name: "wp_plugin_update", args: { plugin: id } }
|
|
15714
|
+
});
|
|
15715
|
+
if (d?.closed)
|
|
15716
|
+
out.push({
|
|
15717
|
+
id: `closed:${id}`,
|
|
15718
|
+
priority: active ? "p1" : "p2",
|
|
15719
|
+
area: "plugins",
|
|
15720
|
+
title: `${p.name} was closed on WordPress.org`,
|
|
15721
|
+
why: `${d.closed_reason ? `Reason: ${d.closed_reason}. ` : ""}It gets no more updates, so new flaws stay open.`,
|
|
15722
|
+
fix: "Replace it with a maintained plugin, then delete it.",
|
|
15723
|
+
tool: { name: "wp_plugin_set", args: { plugin: id, status: active ? "inactive" : "deleted" } }
|
|
15724
|
+
});
|
|
15725
|
+
if (!active && !hits.length && !d?.closed)
|
|
15726
|
+
out.push({
|
|
15727
|
+
id: `inactive:${id}`,
|
|
15728
|
+
priority: "p4",
|
|
15729
|
+
area: "plugins",
|
|
15730
|
+
title: `${p.name} is installed but inactive`,
|
|
15731
|
+
why: "Unused plugins are code on the server that nobody watches.",
|
|
15732
|
+
fix: "Delete it if the site doesn't need it.",
|
|
15733
|
+
tool: { name: "wp_plugin_set", args: { plugin: id, status: "deleted" } }
|
|
15734
|
+
});
|
|
15735
|
+
});
|
|
15736
|
+
const themeData = await pool(themes, 4, (t) => vulnDb("theme", t.stylesheet));
|
|
15737
|
+
themes.forEach((t, i) => {
|
|
15738
|
+
const hits = (themeData[i]?.vulnerability ?? []).filter((v) => affects(v, t.version));
|
|
15739
|
+
if (hits.length)
|
|
15740
|
+
out.push({
|
|
15741
|
+
id: `vuln:theme:${t.stylesheet}`,
|
|
15742
|
+
priority: t.status === "active" ? "p0" : "p2",
|
|
15743
|
+
area: "themes",
|
|
15744
|
+
title: `Theme ${t.name ?? t.stylesheet} ${t.version} has known vulnerabilities`,
|
|
15745
|
+
why: decode2(hits[0]?.name ?? ""),
|
|
15746
|
+
fix: t.status === "active" ? "Update the theme." : "Delete the unused theme in wp-admin \u2192 Appearance.",
|
|
15747
|
+
source: "wpvulnerability.net"
|
|
15748
|
+
});
|
|
15749
|
+
});
|
|
15750
|
+
if (core) {
|
|
15751
|
+
const d = await vulnDb("core", core);
|
|
15752
|
+
if (d === null) degraded.push("WordPress core vulnerabilities");
|
|
15753
|
+
const names = [
|
|
15754
|
+
...new Set((d?.vulnerability ?? []).flatMap((v) => (v.source ?? []).map((x) => decode2(x.name))).filter(Boolean))
|
|
15755
|
+
];
|
|
15756
|
+
const unauth = names.filter((n2) => /unauthenticated/i.test(n2));
|
|
15757
|
+
if (names.length || updates?.core)
|
|
15758
|
+
out.push({
|
|
15759
|
+
id: "core",
|
|
15760
|
+
priority: unauth.length ? "p0" : names.length ? "p1" : "p2",
|
|
15761
|
+
area: "core",
|
|
15762
|
+
title: `WordPress ${core}${updates?.core ? ` \u2192 ${updates.core} available` : ""}${names.length ? ` (${names.length} known vulnerabilities${unauth.length ? `, ${unauth.length} without login` : ""})` : ""}`,
|
|
15763
|
+
why: names.length ? `For example: ${unauth[0] ?? names[0]}.` : "Minor WordPress releases are security releases.",
|
|
15764
|
+
fix: "Update WordPress (wp-admin \u2192 Dashboard \u2192 Updates, or the host's one-click update). Back up first.",
|
|
15765
|
+
source: names.length ? "wpvulnerability.net" : void 0
|
|
15766
|
+
});
|
|
15767
|
+
}
|
|
15768
|
+
return out;
|
|
15769
|
+
}
|
|
15770
|
+
function healthFindings(h) {
|
|
15771
|
+
const out = [];
|
|
15772
|
+
const s = h.settings;
|
|
15773
|
+
const add = (f) => out.push(f);
|
|
15774
|
+
if (s.debug_display)
|
|
15775
|
+
add({
|
|
15776
|
+
id: "debug-display",
|
|
15777
|
+
priority: "p1",
|
|
15778
|
+
area: "settings",
|
|
15779
|
+
title: "PHP errors are shown to visitors (WP_DEBUG_DISPLAY)",
|
|
15780
|
+
why: "Error messages reveal file paths and versions to attackers.",
|
|
15781
|
+
fix: "In wp-config.php set WP_DEBUG to false (or WP_DEBUG_DISPLAY to false). Host or developer task."
|
|
15782
|
+
});
|
|
15783
|
+
if (s.registration && !["subscriber", ""].includes(String(s.default_role)))
|
|
15784
|
+
add({
|
|
15785
|
+
id: "registration-role",
|
|
15786
|
+
priority: "p0",
|
|
15787
|
+
area: "settings",
|
|
15788
|
+
title: `Anyone can register and becomes ${s.default_role}`,
|
|
15789
|
+
why: "Strangers get accounts that can publish or change the site.",
|
|
15790
|
+
fix: "wp-admin \u2192 Settings \u2192 General: untick \u201CAnyone can register\u201D, or set the new user role to Subscriber."
|
|
15791
|
+
});
|
|
15792
|
+
else if (s.registration)
|
|
15793
|
+
add({
|
|
15794
|
+
id: "registration",
|
|
15795
|
+
priority: "p3",
|
|
15796
|
+
area: "settings",
|
|
15797
|
+
title: "Anyone can register an account",
|
|
15798
|
+
why: "Open registration attracts spam accounts; fine only if the site needs it.",
|
|
15799
|
+
fix: "wp-admin \u2192 Settings \u2192 General: untick \u201CAnyone can register\u201D if visitors don't need accounts."
|
|
15800
|
+
});
|
|
15801
|
+
if (!s.https)
|
|
15802
|
+
add({
|
|
15803
|
+
id: "https",
|
|
15804
|
+
priority: "p1",
|
|
15805
|
+
area: "settings",
|
|
15806
|
+
title: "The site address is not https",
|
|
15807
|
+
why: "Logins and forms travel unencrypted; browsers mark the site as not secure.",
|
|
15808
|
+
fix: "Install a certificate at the host and change the WordPress and site address to https."
|
|
15809
|
+
});
|
|
15810
|
+
if (s.file_edit)
|
|
15811
|
+
add({
|
|
15812
|
+
id: "file-edit",
|
|
15813
|
+
priority: "p3",
|
|
15814
|
+
area: "settings",
|
|
15815
|
+
title: "Plugin and theme files can be edited in wp-admin",
|
|
15816
|
+
why: "A stolen admin login can then run any code on the server.",
|
|
15817
|
+
fix: "Add define( 'DISALLOW_FILE_EDIT', true ); to wp-config.php (host or developer). CMO.so's tools keep working."
|
|
15818
|
+
});
|
|
15819
|
+
if (s.xmlrpc)
|
|
15820
|
+
add({
|
|
15821
|
+
id: "xmlrpc",
|
|
15822
|
+
priority: "p3",
|
|
15823
|
+
area: "settings",
|
|
15824
|
+
title: "XML-RPC is on",
|
|
15825
|
+
why: "Old remote API used for password guessing at scale; most sites don't need it (the CMO.so tools don't).",
|
|
15826
|
+
fix: "Block /xmlrpc.php at the host or with a security plugin, unless the Jetpack or the WordPress app needs it."
|
|
15827
|
+
});
|
|
15828
|
+
const perms = String(s.wp_config_perms ?? "");
|
|
15829
|
+
if (/^\d{3}$/.test(perms) && Number(perms[2]) >= 4)
|
|
15830
|
+
add({
|
|
15831
|
+
id: "wp-config-perms",
|
|
15832
|
+
priority: Number(perms[2]) >= 6 ? "p1" : "p3",
|
|
15833
|
+
area: "server",
|
|
15834
|
+
title: `wp-config.php is readable by every user on the server (${perms})`,
|
|
15835
|
+
why: "It holds the database password; on shared hosting other accounts could read it.",
|
|
15836
|
+
fix: "Ask the host to set it to 640 or 600."
|
|
15837
|
+
});
|
|
15838
|
+
const php = h.versions.php.split(".").slice(0, 2).join(".");
|
|
15839
|
+
const eol = PHP_EOL[php];
|
|
15840
|
+
const today2 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
15841
|
+
if (eol && eol < today2)
|
|
15842
|
+
add({
|
|
15843
|
+
id: "php-eol",
|
|
15844
|
+
priority: "p1",
|
|
15845
|
+
area: "server",
|
|
15846
|
+
title: `PHP ${h.versions.php} gets no more security fixes (since ${eol})`,
|
|
15847
|
+
why: "Flaws found in PHP now stay open on this server.",
|
|
15848
|
+
fix: "Ask the host to move the site to PHP 8.3 or newer (test the site after)."
|
|
15849
|
+
});
|
|
15850
|
+
else if (eol && eol < new Date(Date.now() + 120 * 864e5).toISOString().slice(0, 10))
|
|
15851
|
+
add({
|
|
15852
|
+
id: "php-eol-soon",
|
|
15853
|
+
priority: "p3",
|
|
15854
|
+
area: "server",
|
|
15855
|
+
title: `PHP ${h.versions.php} stops getting security fixes on ${eol}`,
|
|
15856
|
+
why: "Plan the move before it ends.",
|
|
15857
|
+
fix: "Ask the host to move the site to PHP 8.3 or newer."
|
|
15858
|
+
});
|
|
15859
|
+
const db = /^(\d+\.\d+)/.exec(h.versions.database)?.[1] ?? "";
|
|
15860
|
+
if (!/mariadb/i.test(h.versions.database) && ["5.7", "8.0"].includes(db))
|
|
15861
|
+
add({
|
|
15862
|
+
id: "mysql-eol",
|
|
15863
|
+
priority: "p3",
|
|
15864
|
+
area: "server",
|
|
15865
|
+
title: `MySQL ${db} has reached end of life`,
|
|
15866
|
+
why: "No more security fixes from Oracle.",
|
|
15867
|
+
fix: "Ask the host to move the database to MySQL 8.4 LTS (or MariaDB 11)."
|
|
15868
|
+
});
|
|
15869
|
+
const admins = h.users.admins;
|
|
15870
|
+
if (admins.some((a) => a.login_is_admin))
|
|
15871
|
+
add({
|
|
15872
|
+
id: "admin-login",
|
|
15873
|
+
priority: "p2",
|
|
15874
|
+
area: "users",
|
|
15875
|
+
title: "An Administrator logs in as \u201Cadmin\u201D",
|
|
15876
|
+
why: "It is the first name password-guessing bots try.",
|
|
15877
|
+
fix: "Create a new Administrator with another name, move the content to it, then delete \u201Cadmin\u201D."
|
|
15878
|
+
});
|
|
15879
|
+
if ((h.users.by_role.administrator ?? 0) > 3)
|
|
15880
|
+
add({
|
|
15881
|
+
id: "many-admins",
|
|
15882
|
+
priority: "p3",
|
|
15883
|
+
area: "users",
|
|
15884
|
+
title: `${h.users.by_role.administrator} Administrator accounts`,
|
|
15885
|
+
why: "Each one can change everything; fewer admins, fewer ways in.",
|
|
15886
|
+
fix: "Give people who only write or edit the Editor or Author role."
|
|
15887
|
+
});
|
|
15888
|
+
const old = new Date(Date.now() - 90 * 864e5).toISOString().slice(0, 10);
|
|
15889
|
+
const stale = admins.filter(
|
|
15890
|
+
(a) => a.app_passwords > 0 && (!a.app_password_last_use || a.app_password_last_use < old)
|
|
15891
|
+
);
|
|
15892
|
+
if (stale.length)
|
|
15893
|
+
add({
|
|
15894
|
+
id: "stale-app-passwords",
|
|
15895
|
+
priority: "p3",
|
|
15896
|
+
area: "users",
|
|
15897
|
+
title: `${stale.length} Administrator${stale.length > 1 ? "s have" : " has"} application passwords unused for 90 days`,
|
|
15898
|
+
why: "Old application passwords are keys nobody remembers handing out.",
|
|
15899
|
+
fix: "wp-admin \u2192 Users \u2192 Profile \u2192 Application Passwords: revoke the ones no tool uses (keep the CMO.so one)."
|
|
15900
|
+
});
|
|
15901
|
+
const orphans = h.cron.filter((j) => !j.handled && !j.core);
|
|
15902
|
+
for (const j of orphans.slice(0, 10))
|
|
15903
|
+
add({
|
|
15904
|
+
id: `cron-orphan:${j.hook}`,
|
|
15905
|
+
priority: "p3",
|
|
15906
|
+
area: "cron",
|
|
15907
|
+
title: `Scheduled job \u201C${j.hook}\u201D has nothing to run it`,
|
|
15908
|
+
why: "Usually left behind by a removed plugin; it keeps waking WordPress for nothing.",
|
|
15909
|
+
fix: "Remove it.",
|
|
15910
|
+
tool: { name: "wp_cron_unschedule", args: { hook: j.hook } }
|
|
15911
|
+
});
|
|
15912
|
+
const late = h.cron.filter((j) => j.schedule !== "once" && j.overdue_min > 120);
|
|
15913
|
+
if (late.length)
|
|
15914
|
+
add({
|
|
15915
|
+
id: "cron-late",
|
|
15916
|
+
priority: s.wp_cron_disabled ? "p2" : "p3",
|
|
15917
|
+
area: "cron",
|
|
15918
|
+
title: `${late.length} scheduled jobs are more than 2 hours late`,
|
|
15919
|
+
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.",
|
|
15920
|
+
fix: "Ask the host for a server cron that calls wp-cron.php every 5 minutes (and set DISABLE_WP_CRON)."
|
|
15921
|
+
});
|
|
15922
|
+
if (h.plugins.must_use.length || h.plugins.dropins.length)
|
|
15923
|
+
add({
|
|
15924
|
+
id: "mu-dropins",
|
|
15925
|
+
priority: "p4",
|
|
15926
|
+
area: "plugins",
|
|
15927
|
+
title: `Hidden plugins: ${[...h.plugins.must_use, ...h.plugins.dropins].join(", ")}`,
|
|
15928
|
+
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.",
|
|
15929
|
+
fix: "Ask the host what they are if you don't recognise them."
|
|
15930
|
+
});
|
|
15931
|
+
return out;
|
|
15932
|
+
}
|
|
15933
|
+
async function outsideFindings(url, h) {
|
|
15934
|
+
const out = [];
|
|
15935
|
+
const home = await outside(url, "/", { redirect: "follow" });
|
|
15936
|
+
if (home) {
|
|
15937
|
+
const want = [
|
|
15938
|
+
["strict-transport-security", "HSTS"],
|
|
15939
|
+
["x-content-type-options", "X-Content-Type-Options"],
|
|
15940
|
+
["referrer-policy", "Referrer-Policy"]
|
|
15941
|
+
];
|
|
15942
|
+
const missing = want.filter(([hname]) => !home.headers.get(hname)).map(([, label2]) => label2);
|
|
15943
|
+
const csp = home.headers.get("content-security-policy") ?? "";
|
|
15944
|
+
if (!home.headers.get("x-frame-options") && !/frame-ancestors/i.test(csp))
|
|
15945
|
+
missing.push("X-Frame-Options or CSP frame-ancestors");
|
|
15946
|
+
if (missing.length)
|
|
15947
|
+
out.push({
|
|
15948
|
+
id: "headers",
|
|
15949
|
+
priority: "p3",
|
|
15950
|
+
area: "outside",
|
|
15951
|
+
title: `Missing security headers: ${missing.join(", ")}`,
|
|
15952
|
+
why: "They stop click-jacking, MIME sniffing and downgrade to http in browsers.",
|
|
15953
|
+
fix: "Add them at the web server or CDN (Cloudflare \u2192 Rules \u2192 Transform rules), or with a security plugin."
|
|
15954
|
+
});
|
|
15955
|
+
const gen = /<meta name="generator" content="WordPress ([\d.]+)/i.exec(home.text)?.[1];
|
|
15956
|
+
if (gen)
|
|
15957
|
+
out.push({
|
|
15958
|
+
id: "version-visible",
|
|
15959
|
+
priority: "p4",
|
|
15960
|
+
area: "outside",
|
|
15961
|
+
title: `The WordPress version (${gen}) is visible in the page`,
|
|
15962
|
+
why: "Bots use it to pick attacks; keeping WordPress updated matters more than hiding it.",
|
|
15963
|
+
fix: "Optional: remove the generator tag with a security plugin."
|
|
15964
|
+
});
|
|
15965
|
+
}
|
|
15966
|
+
const probes = [
|
|
15967
|
+
{ path: "/.env", id: "env", title: "/.env is public", test: (t) => /^[A-Z_]+=/m.test(t), priority: "p0" },
|
|
15968
|
+
{
|
|
15969
|
+
path: "/.git/HEAD",
|
|
15970
|
+
id: "git",
|
|
15971
|
+
title: "The .git folder is public",
|
|
15972
|
+
test: (t) => t.startsWith("ref:"),
|
|
15973
|
+
priority: "p0"
|
|
15974
|
+
},
|
|
15975
|
+
{
|
|
15976
|
+
path: "/wp-config.php.bak",
|
|
15977
|
+
id: "config-bak",
|
|
15978
|
+
title: "A copy of wp-config.php is public",
|
|
15979
|
+
test: (t) => /DB_(NAME|PASSWORD)/.test(t),
|
|
15980
|
+
priority: "p0"
|
|
15981
|
+
},
|
|
15982
|
+
{
|
|
15983
|
+
path: "/wp-config.php~",
|
|
15984
|
+
id: "config-tilde",
|
|
15985
|
+
title: "A copy of wp-config.php is public",
|
|
15986
|
+
test: (t) => /DB_(NAME|PASSWORD)/.test(t),
|
|
15987
|
+
priority: "p0"
|
|
15988
|
+
},
|
|
15989
|
+
{
|
|
15990
|
+
path: "/wp-content/debug.log",
|
|
15991
|
+
id: "debug-log",
|
|
15992
|
+
title: "The PHP error log is public",
|
|
15993
|
+
test: (t) => /PHP (Notice|Warning|Fatal|Deprecated)|\[\d{2}-\w{3}-\d{4}/.test(t),
|
|
15994
|
+
priority: "p1"
|
|
15995
|
+
}
|
|
15996
|
+
];
|
|
15997
|
+
const got = await pool(probes, 5, (p) => outside(url, p.path));
|
|
15998
|
+
probes.forEach((p, i) => {
|
|
15999
|
+
const r = got[i];
|
|
16000
|
+
if (r && r.status === 200 && p.test(r.text))
|
|
16001
|
+
out.push({
|
|
16002
|
+
id: `exposed:${p.id}`,
|
|
16003
|
+
priority: p.priority,
|
|
16004
|
+
area: "outside",
|
|
16005
|
+
title: p.title,
|
|
16006
|
+
why: "Anyone can download it: it can hold passwords, keys or the site's code.",
|
|
16007
|
+
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" : ""}.`
|
|
16008
|
+
});
|
|
16009
|
+
});
|
|
16010
|
+
const author = await outside(url, "/?author=1");
|
|
16011
|
+
if (author && [301, 302].includes(author.status) && /\/author\/[^/]+/.test(author.location))
|
|
16012
|
+
out.push({
|
|
16013
|
+
id: "user-enum",
|
|
16014
|
+
priority: "p3",
|
|
16015
|
+
area: "outside",
|
|
16016
|
+
title: "Login names can be found from /?author=1",
|
|
16017
|
+
why: "It gives password-guessing bots half of a login.",
|
|
16018
|
+
fix: "Block ?author= requests for visitors with a security plugin or a server rule."
|
|
16019
|
+
});
|
|
16020
|
+
const users = await outside(url, "/wp-json/wp/v2/users");
|
|
16021
|
+
if (users && users.status === 200 && /"slug"\s*:/.test(users.text))
|
|
16022
|
+
out.push({
|
|
16023
|
+
id: "users-api",
|
|
16024
|
+
priority: "p3",
|
|
16025
|
+
area: "outside",
|
|
16026
|
+
title: "The list of authors is public at /wp-json/wp/v2/users",
|
|
16027
|
+
why: "It shows login names (slugs) to anyone.",
|
|
16028
|
+
fix: "Limit the users endpoint to signed-in users with a security plugin."
|
|
16029
|
+
});
|
|
16030
|
+
const xmlrpc = h?.settings.xmlrpc ? await outside(url, "/xmlrpc.php") : null;
|
|
16031
|
+
if (xmlrpc && xmlrpc.status === 405) {
|
|
16032
|
+
const f = out.find((x) => x.id === "xmlrpc");
|
|
16033
|
+
if (f) f.why += " It answers from the internet.";
|
|
16034
|
+
}
|
|
16035
|
+
return out;
|
|
16036
|
+
}
|
|
16037
|
+
async function securityScan(site, o = {}) {
|
|
16038
|
+
const degraded = [];
|
|
16039
|
+
const notes = [];
|
|
16040
|
+
const h = await site.request({ path: "/maggie-core/v1/health" }).then((r) => r.status === 200 ? r.data : null).catch(() => null);
|
|
16041
|
+
if (!h)
|
|
16042
|
+
notes.push(
|
|
16043
|
+
"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."
|
|
16044
|
+
);
|
|
16045
|
+
const plugins = await call(site, {
|
|
16046
|
+
path: "/wp/v2/plugins",
|
|
16047
|
+
query: { _fields: "plugin,name,version,status,auto_update" }
|
|
16048
|
+
}).catch((e) => {
|
|
16049
|
+
degraded.push(`plugin list (${e.message})`);
|
|
16050
|
+
return [];
|
|
16051
|
+
});
|
|
16052
|
+
const themes = await call(site, { path: "/wp/v2/themes", query: { _fields: "stylesheet,version,status,name" } }).then(
|
|
16053
|
+
(rows) => rows.map((t) => ({ ...t, name: typeof t.name === "string" ? t.name : t.name?.raw ?? t.stylesheet }))
|
|
16054
|
+
).catch(() => []);
|
|
16055
|
+
const core = h?.versions.wordpress ?? "";
|
|
16056
|
+
const findings = [];
|
|
16057
|
+
if (o.vulnerabilities !== false)
|
|
16058
|
+
findings.push(...await componentFindings(plugins, themes, core, h?.updates ?? null, degraded));
|
|
16059
|
+
if (h) findings.push(...healthFindings(h));
|
|
16060
|
+
if (o.outside !== false && site.url) findings.push(...await outsideFindings(site.url, h));
|
|
16061
|
+
findings.sort((a, b) => order.indexOf(a.priority) - order.indexOf(b.priority));
|
|
16062
|
+
const count = Object.fromEntries(order.map((p) => [p, findings.filter((f) => f.priority === p).length]));
|
|
16063
|
+
return {
|
|
16064
|
+
site: site.url ?? "",
|
|
16065
|
+
checked: (/* @__PURE__ */ new Date()).toISOString(),
|
|
16066
|
+
summary: {
|
|
16067
|
+
...count,
|
|
16068
|
+
plugins: plugins.length,
|
|
16069
|
+
active_plugins: plugins.filter((p) => p.status === "active").length,
|
|
16070
|
+
themes: themes.length,
|
|
16071
|
+
wordpress: core || null,
|
|
16072
|
+
php: h?.versions.php ?? null,
|
|
16073
|
+
scheduled_jobs: h?.cron.length ?? null
|
|
16074
|
+
},
|
|
16075
|
+
words: { p0: "fix today", p1: "this week", p2: "this month", p3: "when convenient", p4: "for information" },
|
|
16076
|
+
findings,
|
|
16077
|
+
...h ? {
|
|
16078
|
+
cron: h.cron.filter((j) => !j.core).map((j) => ({
|
|
16079
|
+
hook: j.hook,
|
|
16080
|
+
schedule: j.schedule,
|
|
16081
|
+
next: j.next,
|
|
16082
|
+
handled: j.handled,
|
|
16083
|
+
late_min: j.overdue_min
|
|
16084
|
+
}))
|
|
16085
|
+
} : {},
|
|
16086
|
+
...degraded.length ? { degraded: [...new Set(degraded)].slice(0, 12) } : {},
|
|
16087
|
+
...notes.length ? { notes } : {},
|
|
16088
|
+
source: "Vulnerability data: WPVulnerability (wpvulnerability.net)."
|
|
16089
|
+
};
|
|
16090
|
+
}
|
|
16091
|
+
|
|
15606
16092
|
// ../../packages/tools/src/wp/site.ts
|
|
15607
16093
|
async function siteStatus(site) {
|
|
15608
16094
|
const me = await call(site, {
|
|
@@ -15897,8 +16383,8 @@ async function relatedCards(site, parent, template, exclude = [], n2 = 3) {
|
|
|
15897
16383
|
},
|
|
15898
16384
|
300
|
|
15899
16385
|
);
|
|
15900
|
-
const
|
|
15901
|
-
const picks =
|
|
16386
|
+
const pool4 = pages.filter((p) => !exclude.includes(p.id) && (!template || p.template === template));
|
|
16387
|
+
const picks = pool4.slice(0, n2);
|
|
15902
16388
|
const media = picks.filter((p) => p.featured_media).map((p) => p.featured_media);
|
|
15903
16389
|
const urls = {};
|
|
15904
16390
|
if (media.length) {
|
|
@@ -16163,7 +16649,7 @@ async function seoImport(site, overwrite = false) {
|
|
|
16163
16649
|
body: { overwrite }
|
|
16164
16650
|
});
|
|
16165
16651
|
}
|
|
16166
|
-
async function
|
|
16652
|
+
async function pool2(items3, n2, fn) {
|
|
16167
16653
|
const out = new Array(items3.length);
|
|
16168
16654
|
let i = 0;
|
|
16169
16655
|
await Promise.all(
|
|
@@ -16185,7 +16671,7 @@ async function seoAudit(site, o = {}) {
|
|
|
16185
16671
|
o.posts
|
|
16186
16672
|
) : [];
|
|
16187
16673
|
const items3 = [...pages.map((p) => ({ ...p, kind: "page" })), ...posts2.map((p) => ({ ...p, kind: "post" }))];
|
|
16188
|
-
const heads = await
|
|
16674
|
+
const heads = await pool2(items3, 6, (p) => renderedHead(site, p.link).catch(() => null));
|
|
16189
16675
|
const issues = [];
|
|
16190
16676
|
const titles = /* @__PURE__ */ new Map();
|
|
16191
16677
|
const descs = /* @__PURE__ */ new Map();
|
|
@@ -16289,7 +16775,7 @@ async function seoAudit(site, o = {}) {
|
|
|
16289
16775
|
});
|
|
16290
16776
|
const unknown2 = [...allLinks].filter((l) => !known.has(l) && !/^\/(category|tag|author|page|blogs?)\//.test(l)).slice(0, 60);
|
|
16291
16777
|
const base = site.url ?? "";
|
|
16292
|
-
const checked = await
|
|
16778
|
+
const checked = await pool2(unknown2, 6, async (l) => ({
|
|
16293
16779
|
l,
|
|
16294
16780
|
s: site.fetchPage ? (await site.fetchPage(`${base}${l}`).catch(() => ({ status: 0 }))).status : 200
|
|
16295
16781
|
}));
|
|
@@ -16319,8 +16805,8 @@ async function seoAudit(site, o = {}) {
|
|
|
16319
16805
|
path: "/wp-sitemap.xml",
|
|
16320
16806
|
detail: `The sitemap answers ${sitemap.status || "nothing"}.`
|
|
16321
16807
|
});
|
|
16322
|
-
const
|
|
16323
|
-
issues.sort((a, b) =>
|
|
16808
|
+
const order2 = { high: 0, medium: 1, low: 2 };
|
|
16809
|
+
issues.sort((a, b) => order2[a.severity] - order2[b.severity] || a.code.localeCompare(b.code));
|
|
16324
16810
|
const byCode = {};
|
|
16325
16811
|
for (const i of issues) byCode[i.code] = (byCode[i.code] ?? 0) + 1;
|
|
16326
16812
|
return {
|
|
@@ -16331,6 +16817,888 @@ async function seoAudit(site, o = {}) {
|
|
|
16331
16817
|
};
|
|
16332
16818
|
}
|
|
16333
16819
|
|
|
16820
|
+
// ../../packages/tools/src/wp/seo-tech.ts
|
|
16821
|
+
var UA = "Mozilla/5.0 (compatible; CMO.so SEO check)";
|
|
16822
|
+
async function get(url, redirect = "manual") {
|
|
16823
|
+
const r = await fetch(url, { redirect, signal: AbortSignal.timeout(15e3), headers: { "User-Agent": UA } }).catch(
|
|
16824
|
+
() => null
|
|
16825
|
+
);
|
|
16826
|
+
if (!r) return null;
|
|
16827
|
+
const text3 = r.status === 200 ? await r.text().catch(() => "") : "";
|
|
16828
|
+
return {
|
|
16829
|
+
status: r.status,
|
|
16830
|
+
text: text3,
|
|
16831
|
+
location: r.headers.get("location") ?? "",
|
|
16832
|
+
type: r.headers.get("content-type") ?? ""
|
|
16833
|
+
};
|
|
16834
|
+
}
|
|
16835
|
+
async function pool3(items3, n2, fn) {
|
|
16836
|
+
const out = new Array(items3.length);
|
|
16837
|
+
let i = 0;
|
|
16838
|
+
await Promise.all(
|
|
16839
|
+
Array.from({ length: Math.min(n2, items3.length) }, async () => {
|
|
16840
|
+
while (i < items3.length) {
|
|
16841
|
+
const k = i++;
|
|
16842
|
+
out[k] = await fn(items3[k]);
|
|
16843
|
+
}
|
|
16844
|
+
})
|
|
16845
|
+
);
|
|
16846
|
+
return out;
|
|
16847
|
+
}
|
|
16848
|
+
function sitePath(href, base) {
|
|
16849
|
+
try {
|
|
16850
|
+
const u = new URL(href, `${base}/`);
|
|
16851
|
+
const b = new URL(base);
|
|
16852
|
+
if (u.hostname.replace(/^www\./, "") !== b.hostname.replace(/^www\./, "")) return null;
|
|
16853
|
+
if (!/^https?:$/.test(u.protocol)) return null;
|
|
16854
|
+
let p = u.pathname.replace(/\/+/g, "/");
|
|
16855
|
+
if (!p.endsWith("/") && !/\.[a-z0-9]{2,5}$/i.test(p)) p += "/";
|
|
16856
|
+
return `${p}${u.searchParams.get("p") || u.searchParams.get("page_id") ? `?${u.searchParams.toString()}` : ""}`;
|
|
16857
|
+
} catch {
|
|
16858
|
+
return null;
|
|
16859
|
+
}
|
|
16860
|
+
}
|
|
16861
|
+
var strip = (h) => h.replace(/<[^>]+>/g, " ").replace(/ /g, " ").replace(/&/g, "&").replace(/’|’/g, "\u2019").replace(/–|–/g, "\u2013").replace(/"/g, '"').replace(/'|'/g, "'").replace(/\s+/g, " ").trim();
|
|
16862
|
+
function scanHtml(html2, url, base) {
|
|
16863
|
+
const head = /<head[\s\S]*?<\/head>/i.exec(html2)?.[0] ?? html2;
|
|
16864
|
+
const attr2 = (re) => re.exec(head)?.[1] ?? "";
|
|
16865
|
+
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, "");
|
|
16866
|
+
const body = main.replace(/<script[\s\S]*?<\/script>|<style[\s\S]*?<\/style>/gi, " ");
|
|
16867
|
+
const links2 = [];
|
|
16868
|
+
for (const m of body.matchAll(/<a\b[^>]*href=["']([^"'#]+)[^"']*["'][^>]*>([\s\S]*?)<\/a>/gi)) {
|
|
16869
|
+
const p = sitePath(m[1], base);
|
|
16870
|
+
if (p && !/\/(wp-admin|wp-login|wp-json|feed)\b|\.(jpg|jpeg|png|webp|gif|svg|pdf|zip)$/i.test(p))
|
|
16871
|
+
links2.push({ path: p, text: strip(m[2]).slice(0, 80) });
|
|
16872
|
+
}
|
|
16873
|
+
const imgs = [...body.matchAll(/<img\b[^>]*>/gi)].map((m) => m[0]);
|
|
16874
|
+
const schema = [];
|
|
16875
|
+
let schemaErrors = 0;
|
|
16876
|
+
for (const m of html2.matchAll(/<script[^>]+application\/ld\+json[^>]*>([\s\S]*?)<\/script>/gi)) {
|
|
16877
|
+
try {
|
|
16878
|
+
const j = JSON.parse(m[1]);
|
|
16879
|
+
const items3 = Array.isArray(j) ? j : j["@graph"] ? j["@graph"] : [j];
|
|
16880
|
+
for (const it of items3) {
|
|
16881
|
+
const t = it?.["@type"];
|
|
16882
|
+
for (const x of Array.isArray(t) ? t : [t]) if (typeof x === "string") schema.push(x);
|
|
16883
|
+
}
|
|
16884
|
+
} catch {
|
|
16885
|
+
schemaErrors++;
|
|
16886
|
+
}
|
|
16887
|
+
}
|
|
16888
|
+
return {
|
|
16889
|
+
url,
|
|
16890
|
+
path: sitePath(url, base) ?? url,
|
|
16891
|
+
title: strip(/<title[^>]*>([\s\S]*?)<\/title>/i.exec(head)?.[1] ?? ""),
|
|
16892
|
+
description: strip(attr2(/<meta[^>]+name=["']description["'][^>]+content=["']([^"']*)["']/i)),
|
|
16893
|
+
canonical: attr2(/<link[^>]+rel=["']canonical["'][^>]+href=["']([^"']+)["']/i),
|
|
16894
|
+
robots: attr2(/<meta[^>]+name=["']robots["'][^>]+content=["']([^"']*)["']/i).toLowerCase(),
|
|
16895
|
+
h1: (body.match(/<h1\b/gi) ?? []).length || (html2.match(/<h1\b/gi) ?? []).length,
|
|
16896
|
+
images: imgs.length,
|
|
16897
|
+
// No alt at all is a problem; alt="" is right for decoration (cover backgrounds), wrong on content pictures.
|
|
16898
|
+
imagesNoAlt: imgs.filter((i) => {
|
|
16899
|
+
if (/aria-hidden|role=["']presentation|wp-block-cover__image-background/i.test(i)) return false;
|
|
16900
|
+
if (!/\balt=/i.test(i)) return true;
|
|
16901
|
+
return /\balt=["']\s*["']/i.test(i) && /\bwp-image-\d+/.test(i);
|
|
16902
|
+
}).length,
|
|
16903
|
+
schema: [...new Set(schema)],
|
|
16904
|
+
schemaErrors,
|
|
16905
|
+
links: links2,
|
|
16906
|
+
words: strip(body).split(" ").filter(Boolean).length
|
|
16907
|
+
};
|
|
16908
|
+
}
|
|
16909
|
+
async function sitemapUrls(base, robotsTxt, max = 500) {
|
|
16910
|
+
const fromRobots = [...robotsTxt.matchAll(/^sitemap:\s*(\S+)/gim)].map((m) => m[1]);
|
|
16911
|
+
const candidates = [...fromRobots, `${base}/wp-sitemap.xml`, `${base}/sitemap_index.xml`, `${base}/sitemap.xml`];
|
|
16912
|
+
for (const sm of candidates) {
|
|
16913
|
+
const r = await get(sm, "follow");
|
|
16914
|
+
if (!r || r.status !== 200 || !/<(urlset|sitemapindex)/i.test(r.text)) continue;
|
|
16915
|
+
const urls = [];
|
|
16916
|
+
const queue = [r.text];
|
|
16917
|
+
let fetched = 0;
|
|
16918
|
+
while (queue.length && urls.length < max && fetched < 30) {
|
|
16919
|
+
const xml = queue.shift();
|
|
16920
|
+
const locs = [...xml.matchAll(/<loc>\s*([^<\s]+)\s*<\/loc>/gi)].map(
|
|
16921
|
+
(m) => m[1].replace(/&/g, "&")
|
|
16922
|
+
);
|
|
16923
|
+
if (/<sitemapindex/i.test(xml)) {
|
|
16924
|
+
for (const l of locs) {
|
|
16925
|
+
const s = await get(l, "follow");
|
|
16926
|
+
fetched++;
|
|
16927
|
+
if (s?.status === 200) queue.push(s.text);
|
|
16928
|
+
}
|
|
16929
|
+
} else urls.push(...locs);
|
|
16930
|
+
}
|
|
16931
|
+
return { urls: [...new Set(urls)].slice(0, max), sitemap: sm };
|
|
16932
|
+
}
|
|
16933
|
+
return { urls: [], sitemap: null };
|
|
16934
|
+
}
|
|
16935
|
+
var AI_BOTS = [
|
|
16936
|
+
"GPTBot",
|
|
16937
|
+
"OAI-SearchBot",
|
|
16938
|
+
"ChatGPT-User",
|
|
16939
|
+
"ClaudeBot",
|
|
16940
|
+
"Claude-SearchBot",
|
|
16941
|
+
"PerplexityBot",
|
|
16942
|
+
"Google-Extended",
|
|
16943
|
+
"CCBot"
|
|
16944
|
+
];
|
|
16945
|
+
function robotsBlocked(robots, agents) {
|
|
16946
|
+
const groups = [];
|
|
16947
|
+
let cur = null;
|
|
16948
|
+
for (const raw of robots.split(/\r?\n/)) {
|
|
16949
|
+
const line = raw.replace(/#.*/, "").trim();
|
|
16950
|
+
const m = /^([a-z-]+)\s*:\s*(.*)$/i.exec(line);
|
|
16951
|
+
if (!m) continue;
|
|
16952
|
+
const [k, v] = [m[1].toLowerCase(), m[2].trim()];
|
|
16953
|
+
if (k === "user-agent") {
|
|
16954
|
+
if (!cur || cur.rules.length) {
|
|
16955
|
+
cur = { agents: [], rules: [] };
|
|
16956
|
+
groups.push(cur);
|
|
16957
|
+
}
|
|
16958
|
+
cur.agents.push(v.toLowerCase());
|
|
16959
|
+
} else if (cur && (k === "disallow" || k === "allow")) cur.rules.push(`${k}:${v}`);
|
|
16960
|
+
}
|
|
16961
|
+
const blocks = (g) => g.rules.includes("disallow:/") && !g.rules.some((r) => r === "allow:/");
|
|
16962
|
+
return agents.filter((a) => {
|
|
16963
|
+
const own3 = groups.find((g2) => g2.agents.includes(a.toLowerCase()));
|
|
16964
|
+
const g = own3 ?? groups.find((x) => x.agents.includes("*"));
|
|
16965
|
+
return g ? blocks(g) : false;
|
|
16966
|
+
});
|
|
16967
|
+
}
|
|
16968
|
+
function groupFindings(list3, min = 4) {
|
|
16969
|
+
const kinds = /* @__PURE__ */ new Map();
|
|
16970
|
+
for (const f of list3) {
|
|
16971
|
+
const k = f.id.includes(":") ? f.id.split(":")[0] : f.id;
|
|
16972
|
+
kinds.set(k, [...kinds.get(k) ?? [], f]);
|
|
16973
|
+
}
|
|
16974
|
+
const out = [];
|
|
16975
|
+
for (const [k, fs2] of kinds) {
|
|
16976
|
+
if (fs2.length < min || !fs2[0]?.id.includes(":")) {
|
|
16977
|
+
out.push(...fs2);
|
|
16978
|
+
continue;
|
|
16979
|
+
}
|
|
16980
|
+
const paths = fs2.map((f) => f.id.slice(k.length + 1));
|
|
16981
|
+
const first = fs2[0];
|
|
16982
|
+
const label2 = {
|
|
16983
|
+
"title-long": "have SEO titles longer than 65 characters",
|
|
16984
|
+
alt: "have pictures without alt text",
|
|
16985
|
+
desc: "have no meta description",
|
|
16986
|
+
h1: "don't have exactly one H1",
|
|
16987
|
+
thin: "have fewer than 120 words",
|
|
16988
|
+
"noindex-in-sitemap": "are noindex but in the sitemap",
|
|
16989
|
+
canonical: "point their canonical elsewhere",
|
|
16990
|
+
"schema-error": "have broken structured data",
|
|
16991
|
+
"sitemap-status": "are in the sitemap but don't answer 200",
|
|
16992
|
+
orphan: "get no links from other pages",
|
|
16993
|
+
broken: "are linked but broken"
|
|
16994
|
+
};
|
|
16995
|
+
const seoTool = first.tool?.name === "wp_seo_set";
|
|
16996
|
+
out.push({
|
|
16997
|
+
...first,
|
|
16998
|
+
id: `${k}:*`,
|
|
16999
|
+
title: `${fs2.length} pages ${label2[k] ?? first.title}`,
|
|
17000
|
+
why: first.why,
|
|
17001
|
+
fix: `${first.fix.replace(/\.$/, "")}. Pages: ${paths.slice(0, 12).join(", ")}${paths.length > 12 ? ` +${paths.length - 12} more` : ""}.`,
|
|
17002
|
+
...seoTool ? { tool: { name: "wp_seo_set", args: { items: paths.slice(0, 50).map((x) => ({ page: x })) } } } : {},
|
|
17003
|
+
pages: paths
|
|
17004
|
+
});
|
|
17005
|
+
}
|
|
17006
|
+
return out;
|
|
17007
|
+
}
|
|
17008
|
+
async function techAudit(site, o = {}) {
|
|
17009
|
+
const base = (site.url ?? "").replace(/\/+$/, "");
|
|
17010
|
+
if (!base) throw new Error("The site's address is unknown.");
|
|
17011
|
+
const limit = Math.min(Math.max(o.limit ?? 60, 5), 200);
|
|
17012
|
+
const findings = [];
|
|
17013
|
+
const add = (f) => findings.push(f);
|
|
17014
|
+
const robotsR = await get(`${base}/robots.txt`, "follow");
|
|
17015
|
+
const robots = robotsR?.status === 200 ? robotsR.text : "";
|
|
17016
|
+
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);
|
|
17017
|
+
const engagedOff = visible === false;
|
|
17018
|
+
let { urls, sitemap } = await sitemapUrls(base, robots);
|
|
17019
|
+
let discovered = "sitemap";
|
|
17020
|
+
if (!urls.length) {
|
|
17021
|
+
const rows = await Promise.all(
|
|
17022
|
+
["/wp/v2/pages", "/wp/v2/posts"].map(
|
|
17023
|
+
(path3) => all(site, path3, { status: "publish", _fields: "link", per_page: 100 }, limit).catch(() => [])
|
|
17024
|
+
)
|
|
17025
|
+
);
|
|
17026
|
+
urls = [...new Set(rows.flat().map((r) => r.link))];
|
|
17027
|
+
discovered = "wordpress";
|
|
17028
|
+
}
|
|
17029
|
+
if (engagedOff)
|
|
17030
|
+
add({
|
|
17031
|
+
id: "search-engines-off",
|
|
17032
|
+
priority: "p1",
|
|
17033
|
+
area: "settings",
|
|
17034
|
+
title: "Search engines are switched off for this site",
|
|
17035
|
+
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.",
|
|
17036
|
+
fix: "When the site is ready: wp_settings_set search_engines true.",
|
|
17037
|
+
tool: { name: "wp_settings_set", args: { search_engines: true } }
|
|
17038
|
+
});
|
|
17039
|
+
if (!robotsR || robotsR.status !== 200)
|
|
17040
|
+
add({
|
|
17041
|
+
id: "robots-missing",
|
|
17042
|
+
priority: "p3",
|
|
17043
|
+
area: "settings",
|
|
17044
|
+
title: "No robots.txt",
|
|
17045
|
+
why: "Crawlers look for it first.",
|
|
17046
|
+
fix: "WordPress makes one by itself unless a file or plugin blocks it: check the host."
|
|
17047
|
+
});
|
|
17048
|
+
if (/^disallow:\s*\/\s*$/im.test(robots) && robotsBlocked(robots, ["Googlebot"]).length)
|
|
17049
|
+
add({
|
|
17050
|
+
id: "robots-all",
|
|
17051
|
+
priority: "p0",
|
|
17052
|
+
area: "settings",
|
|
17053
|
+
title: "robots.txt blocks Google from the whole site",
|
|
17054
|
+
why: "Nothing can be indexed.",
|
|
17055
|
+
fix: "Turn search engines on (wp_settings_set search_engines true) or fix the robots.txt file.",
|
|
17056
|
+
tool: { name: "wp_settings_set", args: { search_engines: true } }
|
|
17057
|
+
});
|
|
17058
|
+
if (robots && !engagedOff && !/^sitemap:/im.test(robots))
|
|
17059
|
+
add({
|
|
17060
|
+
id: "robots-sitemap",
|
|
17061
|
+
priority: "p3",
|
|
17062
|
+
area: "settings",
|
|
17063
|
+
title: "robots.txt doesn't point to the sitemap",
|
|
17064
|
+
why: "It helps every crawler find all pages.",
|
|
17065
|
+
fix: "Maggie Core adds the Sitemap line when search engines are on; otherwise add it to robots.txt."
|
|
17066
|
+
});
|
|
17067
|
+
const aiBlocked = robotsBlocked(robots, AI_BOTS);
|
|
17068
|
+
if (aiBlocked.length)
|
|
17069
|
+
add({
|
|
17070
|
+
id: "ai-crawlers",
|
|
17071
|
+
priority: "p2",
|
|
17072
|
+
area: "settings",
|
|
17073
|
+
title: `AI crawlers are blocked: ${aiBlocked.join(", ")}`,
|
|
17074
|
+
why: "ChatGPT, Claude, Perplexity and Google's AI answers can't read or cite the site.",
|
|
17075
|
+
fix: "Allow them in robots.txt unless the owner chose to block AI."
|
|
17076
|
+
});
|
|
17077
|
+
if (!sitemap && !engagedOff)
|
|
17078
|
+
add({
|
|
17079
|
+
id: "sitemap-missing",
|
|
17080
|
+
priority: "p1",
|
|
17081
|
+
area: "settings",
|
|
17082
|
+
title: "No sitemap found",
|
|
17083
|
+
why: "Search engines find new pages slower without one.",
|
|
17084
|
+
fix: "WordPress publishes /wp-sitemap.xml when search engines are on; check nothing turns it off."
|
|
17085
|
+
});
|
|
17086
|
+
const llms = await get(`${base}/llms.txt`, "follow");
|
|
17087
|
+
const hasLlms = !!llms && llms.status === 200 && /^#\s/m.test(llms.text) && !/<html/i.test(llms.text);
|
|
17088
|
+
if (!hasLlms)
|
|
17089
|
+
add({
|
|
17090
|
+
id: "llms-missing",
|
|
17091
|
+
priority: "p3",
|
|
17092
|
+
area: "settings",
|
|
17093
|
+
title: "No llms.txt",
|
|
17094
|
+
why: "A short Markdown map of the site helps AI assistants describe it correctly.",
|
|
17095
|
+
fix: "Generate it from the site.",
|
|
17096
|
+
tool: { name: "wp_llms_txt_set", args: { generate: true } }
|
|
17097
|
+
});
|
|
17098
|
+
const crawl = urls.length ? urls.slice(0, limit) : [`${base}/`];
|
|
17099
|
+
if (!crawl.some((u) => sitePath(u, base) === "/")) crawl.unshift(`${base}/`);
|
|
17100
|
+
const scans = await pool3(crawl, 6, async (u) => {
|
|
17101
|
+
const r = await get(u);
|
|
17102
|
+
if (!r) return null;
|
|
17103
|
+
if (r.status !== 200) return { ...scanHtml("", u, base), status: r.status, redirect: r.location || void 0 };
|
|
17104
|
+
return { ...scanHtml(r.text, u, base), status: 200 };
|
|
17105
|
+
});
|
|
17106
|
+
const pages = scans.filter(Boolean);
|
|
17107
|
+
const ok2 = pages.filter((p) => p.status === 200);
|
|
17108
|
+
const bad = pages.filter((p) => p.status !== 200);
|
|
17109
|
+
for (const p of bad)
|
|
17110
|
+
add({
|
|
17111
|
+
id: `sitemap-status:${p.path}`,
|
|
17112
|
+
priority: p.status >= 400 ? "p1" : "p2",
|
|
17113
|
+
area: "outside",
|
|
17114
|
+
title: `The sitemap lists ${p.path}, which answers ${p.status}${p.redirect ? ` \u2192 ${p.redirect}` : ""}`,
|
|
17115
|
+
why: "Sitemaps should list only live pages; search engines lose trust in it.",
|
|
17116
|
+
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."
|
|
17117
|
+
});
|
|
17118
|
+
for (const p of ok2) {
|
|
17119
|
+
if (/noindex/.test(p.robots) && !engagedOff && discovered === "sitemap")
|
|
17120
|
+
add({
|
|
17121
|
+
id: `noindex-in-sitemap:${p.path}`,
|
|
17122
|
+
priority: "p1",
|
|
17123
|
+
area: "outside",
|
|
17124
|
+
title: `${p.path} is noindex but in the sitemap`,
|
|
17125
|
+
why: "Mixed signals: either it should be found, or it shouldn't be listed.",
|
|
17126
|
+
fix: 'Remove noindex if the page should rank (wp_seo_set robots "").',
|
|
17127
|
+
tool: { name: "wp_seo_set", args: { page: p.path, robots: "" } }
|
|
17128
|
+
});
|
|
17129
|
+
if (p.canonical && sitePath(p.canonical, base) !== p.path)
|
|
17130
|
+
add({
|
|
17131
|
+
id: `canonical:${p.path}`,
|
|
17132
|
+
priority: "p2",
|
|
17133
|
+
area: "outside",
|
|
17134
|
+
title: `${p.path} points its canonical to ${p.canonical}`,
|
|
17135
|
+
why: "Google will index the other address instead of this page.",
|
|
17136
|
+
fix: 'Clear the custom canonical unless it is on purpose (wp_seo_set canonical "").',
|
|
17137
|
+
tool: { name: "wp_seo_set", args: { page: p.path, canonical: "" } }
|
|
17138
|
+
});
|
|
17139
|
+
if (p.h1 !== 1)
|
|
17140
|
+
add({
|
|
17141
|
+
id: `h1:${p.path}`,
|
|
17142
|
+
priority: "p2",
|
|
17143
|
+
area: "outside",
|
|
17144
|
+
title: `${p.path} has ${p.h1} H1 headings`,
|
|
17145
|
+
why: "One H1 says what the page is about.",
|
|
17146
|
+
fix: p.h1 ? "Make the extra H1s H2 (wp_section_update edits)." : "Give the page a main heading (the hero's title)."
|
|
17147
|
+
});
|
|
17148
|
+
if (p.imagesNoAlt)
|
|
17149
|
+
add({
|
|
17150
|
+
id: `alt:${p.path}`,
|
|
17151
|
+
priority: "p3",
|
|
17152
|
+
area: "outside",
|
|
17153
|
+
title: `${p.path}: ${p.imagesNoAlt} of ${p.images} pictures have no alt text`,
|
|
17154
|
+
why: "Alt text is how search engines, AI and screen readers know what a picture shows.",
|
|
17155
|
+
fix: "Add alt text (wp_section_update images alt, or the media library)."
|
|
17156
|
+
});
|
|
17157
|
+
if (p.schemaErrors)
|
|
17158
|
+
add({
|
|
17159
|
+
id: `schema-error:${p.path}`,
|
|
17160
|
+
priority: "p2",
|
|
17161
|
+
area: "outside",
|
|
17162
|
+
title: `${p.path}: ${p.schemaErrors} structured-data block(s) are not valid JSON`,
|
|
17163
|
+
why: "Google ignores broken structured data.",
|
|
17164
|
+
fix: "Fix or remove the page's custom schema (wp_seo_set schema)."
|
|
17165
|
+
});
|
|
17166
|
+
if (p.words < 120 && !/\?/.test(p.path))
|
|
17167
|
+
add({
|
|
17168
|
+
id: `thin:${p.path}`,
|
|
17169
|
+
priority: "p3",
|
|
17170
|
+
area: "outside",
|
|
17171
|
+
title: `${p.path} has only ${p.words} words`,
|
|
17172
|
+
why: "Very short pages rarely rank or get cited.",
|
|
17173
|
+
fix: "Add useful text: what, for whom, price or next step, questions."
|
|
17174
|
+
});
|
|
17175
|
+
if (!p.description)
|
|
17176
|
+
add({
|
|
17177
|
+
id: `desc:${p.path}`,
|
|
17178
|
+
priority: "p2",
|
|
17179
|
+
area: "outside",
|
|
17180
|
+
title: `${p.path} has no meta description`,
|
|
17181
|
+
why: "Google writes its own snippet, often a poor one.",
|
|
17182
|
+
fix: "Write one (140\u2013160 characters).",
|
|
17183
|
+
tool: { name: "wp_seo_set", args: { page: p.path } }
|
|
17184
|
+
});
|
|
17185
|
+
if (p.title.length > 65)
|
|
17186
|
+
add({
|
|
17187
|
+
id: `title-long:${p.path}`,
|
|
17188
|
+
priority: "p3",
|
|
17189
|
+
area: "outside",
|
|
17190
|
+
title: `${p.path}: title is ${p.title.length} characters`,
|
|
17191
|
+
why: "Search results cut it after about 60.",
|
|
17192
|
+
fix: "Shorten the SEO title.",
|
|
17193
|
+
tool: { name: "wp_seo_set", args: { page: p.path } }
|
|
17194
|
+
});
|
|
17195
|
+
}
|
|
17196
|
+
const dup = (key) => {
|
|
17197
|
+
const by = /* @__PURE__ */ new Map();
|
|
17198
|
+
for (const p of ok2) if (p[key]) by.set(p[key], [...by.get(p[key]) ?? [], p.path]);
|
|
17199
|
+
for (const [v, ps] of by)
|
|
17200
|
+
if (ps.length > 1)
|
|
17201
|
+
add({
|
|
17202
|
+
id: `dup-${key}:${v.slice(0, 40)}`,
|
|
17203
|
+
priority: "p2",
|
|
17204
|
+
area: "outside",
|
|
17205
|
+
title: `${ps.length} pages share the same ${key}: \u201C${v.slice(0, 70)}\u201D`,
|
|
17206
|
+
why: "Search engines can't tell them apart.",
|
|
17207
|
+
fix: `Give each its own ${key} (wp_seo_set items).`,
|
|
17208
|
+
tool: { name: "wp_seo_set", args: { items: ps.slice(0, 10).map((x) => ({ page: x })) } }
|
|
17209
|
+
});
|
|
17210
|
+
};
|
|
17211
|
+
dup("title");
|
|
17212
|
+
dup("description");
|
|
17213
|
+
const home = ok2.find((p) => p.path === "/");
|
|
17214
|
+
if (home && !home.schema.some((t) => /Organization|LocalBusiness|WebSite|Person|Store|Restaurant|Service/i.test(t)))
|
|
17215
|
+
add({
|
|
17216
|
+
id: "schema-home",
|
|
17217
|
+
priority: "p2",
|
|
17218
|
+
area: "outside",
|
|
17219
|
+
title: "The homepage has no Organization / LocalBusiness structured data",
|
|
17220
|
+
why: "It tells Google and AI who the business is, where and how to reach it.",
|
|
17221
|
+
fix: "Fill the business details (wp_seo_site_set business).",
|
|
17222
|
+
tool: { name: "wp_seo_site_set", args: {} }
|
|
17223
|
+
});
|
|
17224
|
+
const inbound = /* @__PURE__ */ new Map();
|
|
17225
|
+
for (const p of ok2)
|
|
17226
|
+
for (const l of new Set(p.links.map((x) => x.path))) if (l !== p.path) inbound.set(l, (inbound.get(l) ?? 0) + 1);
|
|
17227
|
+
const known = new Set(pages.map((p) => p.path));
|
|
17228
|
+
const targets = [...new Set(ok2.flatMap((p) => p.links.map((l) => l.path)))].filter((t) => !known.has(t)).slice(0, 80);
|
|
17229
|
+
const checked = await pool3(targets, 6, async (t) => ({ t, r: await get(`${base}${t}`) }));
|
|
17230
|
+
const broken = checked.filter((c) => c.r && c.r.status >= 400);
|
|
17231
|
+
const redirected = checked.filter((c) => c.r && [301, 302, 307, 308].includes(c.r.status));
|
|
17232
|
+
for (const b of broken) {
|
|
17233
|
+
const from = ok2.filter((p) => p.links.some((l) => l.path === b.t)).map((p) => p.path);
|
|
17234
|
+
add({
|
|
17235
|
+
id: `broken:${b.t}`,
|
|
17236
|
+
priority: "p1",
|
|
17237
|
+
area: "outside",
|
|
17238
|
+
title: `Broken link to ${b.t} (${b.r?.status}) on ${from.slice(0, 3).join(", ")}${from.length > 3 ? ` +${from.length - 3}` : ""}`,
|
|
17239
|
+
why: "Visitors hit a dead end and crawlers waste their visit.",
|
|
17240
|
+
fix: "Point the link to a live page (wp_section_update links) or add a redirect (wp_redirect_set).",
|
|
17241
|
+
tool: { name: "wp_redirect_set", args: { from: b.t } }
|
|
17242
|
+
});
|
|
17243
|
+
}
|
|
17244
|
+
if (redirected.length)
|
|
17245
|
+
add({
|
|
17246
|
+
id: "links-redirected",
|
|
17247
|
+
priority: "p3",
|
|
17248
|
+
area: "outside",
|
|
17249
|
+
title: `${redirected.length} internal links go through a redirect`,
|
|
17250
|
+
why: "Each hop slows visitors and loses a little link value.",
|
|
17251
|
+
fix: `Link straight to the final address: ${redirected.slice(0, 5).map((c) => `${c.t} \u2192 ${c.r?.location}`).join(", ")}.`
|
|
17252
|
+
});
|
|
17253
|
+
const generic = ok2.flatMap(
|
|
17254
|
+
(p) => p.links.filter((l) => /^(click here|here|read more|learn more|more|this|link|點此|更多)$/i.test(l.text)).map(() => p.path)
|
|
17255
|
+
);
|
|
17256
|
+
if (generic.length)
|
|
17257
|
+
add({
|
|
17258
|
+
id: "anchors-generic",
|
|
17259
|
+
priority: "p3",
|
|
17260
|
+
area: "outside",
|
|
17261
|
+
title: `${generic.length} links say only \u201Cread more\u201D, \u201Cclick here\u201D or similar`,
|
|
17262
|
+
why: "Link words tell search engines what the target page is about.",
|
|
17263
|
+
fix: `Use the target's topic as the link text (pages: ${[...new Set(generic)].slice(0, 5).join(", ")}).`
|
|
17264
|
+
});
|
|
17265
|
+
let speed = null;
|
|
17266
|
+
if (o.speed) speed = await pageSpeed(`${base}/`);
|
|
17267
|
+
if (speed?.lcp_ms && Number(speed.lcp_ms) > 2500)
|
|
17268
|
+
add({
|
|
17269
|
+
id: "lcp",
|
|
17270
|
+
priority: Number(speed.lcp_ms) > 4e3 ? "p1" : "p2",
|
|
17271
|
+
area: "outside",
|
|
17272
|
+
title: `The homepage's main content shows after ${(Number(speed.lcp_ms) / 1e3).toFixed(1)} s on phones (LCP)`,
|
|
17273
|
+
why: "Google wants under 2.5 s; slow pages lose visitors and rankings.",
|
|
17274
|
+
fix: "Smaller hero picture (WebP, under 200 KB), fewer fonts and scripts above the fold."
|
|
17275
|
+
});
|
|
17276
|
+
if (speed?.cls != null && Number(speed.cls) > 0.1)
|
|
17277
|
+
add({
|
|
17278
|
+
id: "cls",
|
|
17279
|
+
priority: "p2",
|
|
17280
|
+
area: "outside",
|
|
17281
|
+
title: `The homepage moves while loading (CLS ${speed.cls})`,
|
|
17282
|
+
why: "Google wants under 0.1.",
|
|
17283
|
+
fix: "Give pictures width and height; don't insert banners above content after load."
|
|
17284
|
+
});
|
|
17285
|
+
const order2 = ["p0", "p1", "p2", "p3", "p4"];
|
|
17286
|
+
const grouped = groupFindings(findings);
|
|
17287
|
+
grouped.sort((a, b) => order2.indexOf(a.priority) - order2.indexOf(b.priority));
|
|
17288
|
+
findings.length = 0;
|
|
17289
|
+
findings.push(...grouped);
|
|
17290
|
+
return {
|
|
17291
|
+
site: base,
|
|
17292
|
+
checked: (/* @__PURE__ */ new Date()).toISOString(),
|
|
17293
|
+
summary: {
|
|
17294
|
+
...Object.fromEntries(order2.map((p) => [p, findings.filter((f) => f.priority === p).length])),
|
|
17295
|
+
sitemap,
|
|
17296
|
+
pages_from: discovered,
|
|
17297
|
+
search_engines: visible,
|
|
17298
|
+
sitemap_urls: discovered === "sitemap" ? urls.length : 0,
|
|
17299
|
+
crawled: pages.length,
|
|
17300
|
+
live: ok2.length,
|
|
17301
|
+
llms_txt: hasLlms,
|
|
17302
|
+
ai_crawlers_blocked: aiBlocked,
|
|
17303
|
+
internal_links: ok2.reduce((n2, p) => n2 + p.links.length, 0)
|
|
17304
|
+
},
|
|
17305
|
+
pages: ok2.map((p) => ({
|
|
17306
|
+
path: p.path,
|
|
17307
|
+
title: p.title,
|
|
17308
|
+
words: p.words,
|
|
17309
|
+
h1: p.h1,
|
|
17310
|
+
links_out: new Set(p.links.map((l) => l.path)).size,
|
|
17311
|
+
links_in: inbound.get(p.path) ?? 0,
|
|
17312
|
+
schema: p.schema
|
|
17313
|
+
})),
|
|
17314
|
+
findings,
|
|
17315
|
+
...speed ? { speed } : {},
|
|
17316
|
+
...urls.length > crawl.length ? { note: `Crawled the first ${crawl.length} of ${urls.length} sitemap addresses (limit up to 200).` } : {}
|
|
17317
|
+
};
|
|
17318
|
+
}
|
|
17319
|
+
async function pageSpeed(url) {
|
|
17320
|
+
const key = globalThis.process?.env?.PAGESPEED_API_KEY;
|
|
17321
|
+
const q3 = new URLSearchParams({ url, strategy: "mobile", category: "performance" });
|
|
17322
|
+
if (key) q3.set("key", key);
|
|
17323
|
+
const r = await fetch(`https://www.googleapis.com/pagespeedonline/v5/runPagespeed?${q3}`, {
|
|
17324
|
+
signal: AbortSignal.timeout(9e4)
|
|
17325
|
+
}).catch(() => null);
|
|
17326
|
+
if (!r || !r.ok)
|
|
17327
|
+
return {
|
|
17328
|
+
error: `PageSpeed Insights didn't answer (${r?.status ?? "timeout"})${r?.status === 429 && !key ? ": the server needs a PAGESPEED_API_KEY (Google Cloud, free)" : ""}.`
|
|
17329
|
+
};
|
|
17330
|
+
const j = await r.json();
|
|
17331
|
+
const f = j.loadingExperience?.metrics ?? {};
|
|
17332
|
+
const a = j.lighthouseResult?.audits ?? {};
|
|
17333
|
+
const field = !!f.LARGEST_CONTENTFUL_PAINT_MS;
|
|
17334
|
+
return {
|
|
17335
|
+
source: field ? "real visitors (Chrome UX Report, 28 days)" : "lab test (no real-visitor data yet)",
|
|
17336
|
+
score: Math.round((j.lighthouseResult?.categories?.performance?.score ?? 0) * 100),
|
|
17337
|
+
lcp_ms: field ? f.LARGEST_CONTENTFUL_PAINT_MS?.percentile : Math.round(a["largest-contentful-paint"]?.numericValue ?? 0),
|
|
17338
|
+
cls: field ? (f.CUMULATIVE_LAYOUT_SHIFT_SCORE?.percentile ?? 0) / 100 : Number((a["cumulative-layout-shift"]?.numericValue ?? 0).toFixed(3)),
|
|
17339
|
+
inp_ms: f.INTERACTION_TO_NEXT_PAINT?.percentile ?? null,
|
|
17340
|
+
tbt_ms: Math.round(a["total-blocking-time"]?.numericValue ?? 0)
|
|
17341
|
+
};
|
|
17342
|
+
}
|
|
17343
|
+
var STOP = new Set(
|
|
17344
|
+
"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(
|
|
17345
|
+
" "
|
|
17346
|
+
)
|
|
17347
|
+
);
|
|
17348
|
+
var tokens = (s) => new Set(
|
|
17349
|
+
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)$/, ""))
|
|
17350
|
+
);
|
|
17351
|
+
var overlap = (a, b, idf = () => 1) => {
|
|
17352
|
+
let dot = 0;
|
|
17353
|
+
let na = 0;
|
|
17354
|
+
let nb = 0;
|
|
17355
|
+
for (const w of a) {
|
|
17356
|
+
const x = idf(w) ** 2;
|
|
17357
|
+
na += x;
|
|
17358
|
+
if (b.has(w)) dot += x;
|
|
17359
|
+
}
|
|
17360
|
+
for (const w of b) nb += idf(w) ** 2;
|
|
17361
|
+
return dot / Math.sqrt(Math.max(1e-9, na) * Math.max(1e-9, nb));
|
|
17362
|
+
};
|
|
17363
|
+
function contentLinks(raw, base) {
|
|
17364
|
+
const out = /* @__PURE__ */ new Set();
|
|
17365
|
+
for (const m of raw.matchAll(/href=["']([^"'#]+)["']/gi)) {
|
|
17366
|
+
const p = sitePath(m[1], base);
|
|
17367
|
+
if (p) out.add(p);
|
|
17368
|
+
}
|
|
17369
|
+
for (const m of raw.matchAll(/"url":"([^"]+)"/g)) {
|
|
17370
|
+
const p = sitePath(m[1].replace(/\\\//g, "/"), base);
|
|
17371
|
+
if (p) out.add(p);
|
|
17372
|
+
}
|
|
17373
|
+
return out;
|
|
17374
|
+
}
|
|
17375
|
+
var flatMenu = (items3) => items3.flatMap((i) => [{ url: i.url, label: i.label }, ...flatMenu(i.children ?? [])]);
|
|
17376
|
+
async function linksPlan(site, o = {}) {
|
|
17377
|
+
const base = (site.url ?? "").replace(/\/+$/, "");
|
|
17378
|
+
const pages = await listPages(site, { status: "publish", withContent: true });
|
|
17379
|
+
const posts2 = await all(
|
|
17380
|
+
site,
|
|
17381
|
+
"/wp/v2/posts",
|
|
17382
|
+
{
|
|
17383
|
+
context: "edit",
|
|
17384
|
+
status: "publish",
|
|
17385
|
+
per_page: 100,
|
|
17386
|
+
_fields: "id,link,title,categories,content,meta",
|
|
17387
|
+
orderby: "date",
|
|
17388
|
+
order: "desc"
|
|
17389
|
+
},
|
|
17390
|
+
o.posts ?? 200
|
|
17391
|
+
);
|
|
17392
|
+
const cats = await all(site, "/wp/v2/categories", {
|
|
17393
|
+
per_page: 100,
|
|
17394
|
+
_fields: "id,name,link,count"
|
|
17395
|
+
});
|
|
17396
|
+
const catName = new Map(cats.map((c) => [c.id, c.name]));
|
|
17397
|
+
const settings2 = await site.request({
|
|
17398
|
+
path: "/wp/v2/settings",
|
|
17399
|
+
query: { _fields: "page_on_front,page_for_posts" }
|
|
17400
|
+
}).then((r) => r.status === 200 ? r.data : {});
|
|
17401
|
+
const docs = [
|
|
17402
|
+
...pages.map((p) => ({
|
|
17403
|
+
id: p.id,
|
|
17404
|
+
kind: "page",
|
|
17405
|
+
path: sitePath(p.link, base) ?? p.link,
|
|
17406
|
+
url: p.link,
|
|
17407
|
+
title: titleOf(p.title),
|
|
17408
|
+
parent: p.parent,
|
|
17409
|
+
links: contentLinks(p.content?.raw ?? "", base),
|
|
17410
|
+
words: tokens(
|
|
17411
|
+
`${titleOf(p.title)} ${p.slug} ${p.meta?.maggie_seo_title ?? ""} ${p.meta?.maggie_seo_keywords ?? ""}`
|
|
17412
|
+
),
|
|
17413
|
+
description: String(p.meta?.maggie_seo_description ?? "")
|
|
17414
|
+
})),
|
|
17415
|
+
...posts2.map((p) => ({
|
|
17416
|
+
id: p.id,
|
|
17417
|
+
kind: "post",
|
|
17418
|
+
path: sitePath(p.link, base) ?? p.link,
|
|
17419
|
+
url: p.link,
|
|
17420
|
+
title: p.title.raw ?? "",
|
|
17421
|
+
cats: p.categories.map((c) => catName.get(c) ?? "").filter(Boolean),
|
|
17422
|
+
links: contentLinks(p.content.raw, base),
|
|
17423
|
+
words: tokens(
|
|
17424
|
+
`${p.title.raw ?? ""} ${p.categories.map((c) => catName.get(c) ?? "").join(" ")} ${p.meta?.maggie_seo_keywords ?? ""}`
|
|
17425
|
+
),
|
|
17426
|
+
description: String(p.meta?.maggie_seo_description ?? "")
|
|
17427
|
+
}))
|
|
17428
|
+
];
|
|
17429
|
+
const byPath = new Map(docs.map((d) => [d.path, d]));
|
|
17430
|
+
const menu = await menuGet(site).catch(() => null);
|
|
17431
|
+
const menuPaths = new Set(
|
|
17432
|
+
flatMenu(menu?.items ?? []).map((i) => sitePath(i.url, base)).filter(Boolean)
|
|
17433
|
+
);
|
|
17434
|
+
const footer = await partGet(site, "footer").catch(() => null);
|
|
17435
|
+
const footerPaths = footer ? contentLinks(footer.content, base) : /* @__PURE__ */ new Set();
|
|
17436
|
+
const header = await partGet(site, "header").catch(() => null);
|
|
17437
|
+
const headerPaths = header ? contentLinks(header.content, base) : /* @__PURE__ */ new Set();
|
|
17438
|
+
const chrome = /* @__PURE__ */ new Set([...menuPaths, ...footerPaths, ...headerPaths]);
|
|
17439
|
+
const inbound = /* @__PURE__ */ new Map();
|
|
17440
|
+
for (const d of docs)
|
|
17441
|
+
for (const l of d.links) if (l !== d.path) inbound.set(l, /* @__PURE__ */ new Set([...inbound.get(l) ?? [], d.path]));
|
|
17442
|
+
const home = docs.find((d) => d.id === settings2.page_on_front && d.kind === "page");
|
|
17443
|
+
const blogPage = docs.find((d) => d.id === settings2.page_for_posts && d.kind === "page");
|
|
17444
|
+
const actions = [];
|
|
17445
|
+
const findings = [];
|
|
17446
|
+
const sample = docs.filter(
|
|
17447
|
+
(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!")
|
|
17448
|
+
);
|
|
17449
|
+
for (const d of sample)
|
|
17450
|
+
findings.push({
|
|
17451
|
+
id: `sample:${d.path}`,
|
|
17452
|
+
priority: "p2",
|
|
17453
|
+
area: "outside",
|
|
17454
|
+
title: `WordPress's sample ${d.kind === "page" ? "page" : "article"} \u201C${d.title}\u201D is still published`,
|
|
17455
|
+
why: "It tells visitors and search engines the site isn't finished, and dilutes the real pages.",
|
|
17456
|
+
fix: "Move it to the trash.",
|
|
17457
|
+
tool: {
|
|
17458
|
+
name: d.kind === "page" ? "wp_page_delete" : "wp_post_delete",
|
|
17459
|
+
args: d.kind === "page" ? { page: d.id } : { post: d.id }
|
|
17460
|
+
}
|
|
17461
|
+
});
|
|
17462
|
+
const pageDocs = docs.filter((d) => d.kind === "page" && d !== home && !sample.includes(d));
|
|
17463
|
+
const postDocs = docs.filter((d) => d.kind === "post" && !sample.includes(d));
|
|
17464
|
+
const menuItems = flatMenu(menu?.items ?? []);
|
|
17465
|
+
const top = (menu?.items ?? []).length;
|
|
17466
|
+
for (const i of menuItems) {
|
|
17467
|
+
const p = sitePath(i.url, base);
|
|
17468
|
+
if (p && p !== "/" && !byPath.has(p) && !/\/(category|tag|author)\//.test(p) && !p.startsWith("/?"))
|
|
17469
|
+
findings.push({
|
|
17470
|
+
id: `menu-dead:${p}`,
|
|
17471
|
+
priority: "p1",
|
|
17472
|
+
area: "outside",
|
|
17473
|
+
title: `The menu links to ${p} (\u201C${i.label}\u201D), which isn't a published page or post`,
|
|
17474
|
+
why: "Visitors hit a dead end from every page.",
|
|
17475
|
+
fix: "Point it to a live page or remove it (wp_menu_set).",
|
|
17476
|
+
tool: { name: "wp_menu_set", args: {} }
|
|
17477
|
+
});
|
|
17478
|
+
}
|
|
17479
|
+
if (top > 7)
|
|
17480
|
+
findings.push({
|
|
17481
|
+
id: "menu-long",
|
|
17482
|
+
priority: "p3",
|
|
17483
|
+
area: "outside",
|
|
17484
|
+
title: `The menu has ${top} top-level items`,
|
|
17485
|
+
why: "More than 7 makes choosing hard; group them under submenus.",
|
|
17486
|
+
fix: "Group related pages under a parent item (wp_menu_set)."
|
|
17487
|
+
});
|
|
17488
|
+
const hubs = pageDocs.filter((d) => pageDocs.some((c) => c.parent === d.id));
|
|
17489
|
+
const topLevel = pageDocs.filter((d) => !d.parent);
|
|
17490
|
+
const wantMenu = [.../* @__PURE__ */ new Set([...hubs, ...topLevel.slice(0, 6)])].filter(
|
|
17491
|
+
(d) => !chrome.has(d.path) && !/privacy|terms|cookie|legal|impressum|datenschutz|thank/i.test(d.path)
|
|
17492
|
+
);
|
|
17493
|
+
if (wantMenu.length)
|
|
17494
|
+
actions.push({
|
|
17495
|
+
type: "menu",
|
|
17496
|
+
why: "Main pages every visitor should reach in one click.",
|
|
17497
|
+
add: wantMenu.slice(0, 6).map((d) => ({ label: d.title, url: d.url })),
|
|
17498
|
+
tool: "wp_menu_set"
|
|
17499
|
+
});
|
|
17500
|
+
if (postDocs.length && blogPage && !chrome.has(blogPage.path))
|
|
17501
|
+
actions.push({
|
|
17502
|
+
type: "menu",
|
|
17503
|
+
why: "The blog isn't reachable from the menu.",
|
|
17504
|
+
add: [{ label: blogPage.title || "Blog", url: blogPage.url }],
|
|
17505
|
+
tool: "wp_menu_set"
|
|
17506
|
+
});
|
|
17507
|
+
const legal = pageDocs.filter(
|
|
17508
|
+
(d) => /privacy|terms|cookie|legal|impressum|datenschutz|accessib/i.test(`${d.path} ${d.title}`)
|
|
17509
|
+
);
|
|
17510
|
+
const contact = pageDocs.filter((d) => /contact|about|book|location|faq/i.test(`${d.path} ${d.title}`));
|
|
17511
|
+
const footerMissing = [...legal, ...contact].filter((d) => !footerPaths.has(d.path));
|
|
17512
|
+
if (footerMissing.length)
|
|
17513
|
+
actions.push({
|
|
17514
|
+
type: "footer",
|
|
17515
|
+
why: "Legal, contact and about pages belong in the footer of every page (trust, and Google's quality raters look for them).",
|
|
17516
|
+
add: footerMissing.slice(0, 8).map((d) => ({ label: d.title, url: d.url })),
|
|
17517
|
+
tool: "wp_footer_set"
|
|
17518
|
+
});
|
|
17519
|
+
for (const hub of hubs) {
|
|
17520
|
+
const kids = pageDocs.filter((c) => c.parent === hub.id);
|
|
17521
|
+
const missing = kids.filter((k) => !hub.links.has(k.path));
|
|
17522
|
+
if (missing.length)
|
|
17523
|
+
actions.push({
|
|
17524
|
+
type: "page_related",
|
|
17525
|
+
page: hub.id,
|
|
17526
|
+
path: hub.path,
|
|
17527
|
+
heading: `More in ${hub.title}`,
|
|
17528
|
+
why: `${hub.title} doesn't link to ${missing.length} of its own sub-pages.`,
|
|
17529
|
+
links: missing.map((k) => ({ url: k.url, label: k.title }))
|
|
17530
|
+
});
|
|
17531
|
+
for (const k of kids)
|
|
17532
|
+
if (!k.links.has(hub.path)) {
|
|
17533
|
+
const sib = kids.filter((s) => s !== k).slice(0, 3);
|
|
17534
|
+
actions.push({
|
|
17535
|
+
type: "page_related",
|
|
17536
|
+
page: k.id,
|
|
17537
|
+
path: k.path,
|
|
17538
|
+
heading: "Related",
|
|
17539
|
+
why: `${k.title} doesn't link back to ${hub.title}${sib.length ? " or its sister pages" : ""}.`,
|
|
17540
|
+
links: [{ url: hub.url, label: hub.title }, ...sib.map((s) => ({ url: s.url, label: s.title }))]
|
|
17541
|
+
});
|
|
17542
|
+
}
|
|
17543
|
+
}
|
|
17544
|
+
const df = /* @__PURE__ */ new Map();
|
|
17545
|
+
for (const d of docs) for (const w of d.words) df.set(w, (df.get(w) ?? 0) + 1);
|
|
17546
|
+
const idf = (w) => Math.log(1 + docs.length / (1 + (df.get(w) ?? 0)));
|
|
17547
|
+
const forPage = /* @__PURE__ */ new Map();
|
|
17548
|
+
for (const post of postDocs) {
|
|
17549
|
+
let best = null;
|
|
17550
|
+
let score = 0;
|
|
17551
|
+
for (const pg of home ? [...pageDocs, home] : pageDocs) {
|
|
17552
|
+
if (pg === blogPage) continue;
|
|
17553
|
+
const s = overlap(post.words, pg.words, idf);
|
|
17554
|
+
if (s > score) [best, score] = [pg, s];
|
|
17555
|
+
}
|
|
17556
|
+
if (!best || score < 0.3) continue;
|
|
17557
|
+
forPage.set(best, [...forPage.get(best) ?? [], post]);
|
|
17558
|
+
if (!post.links.has(best.path))
|
|
17559
|
+
actions.push({
|
|
17560
|
+
type: "post_link",
|
|
17561
|
+
post: post.id,
|
|
17562
|
+
path: post.path,
|
|
17563
|
+
why: `\u201C${post.title}\u201D is about ${best.title} but doesn't link to that page.`,
|
|
17564
|
+
url: best.url,
|
|
17565
|
+
label: best.title,
|
|
17566
|
+
match: Math.round(score * 100)
|
|
17567
|
+
});
|
|
17568
|
+
}
|
|
17569
|
+
for (const [pg, ps] of forPage) {
|
|
17570
|
+
const missing = ps.filter((p) => !pg.links.has(p.path));
|
|
17571
|
+
if (missing.length >= 2)
|
|
17572
|
+
actions.push({
|
|
17573
|
+
type: "page_related",
|
|
17574
|
+
page: pg.id,
|
|
17575
|
+
path: pg.path,
|
|
17576
|
+
heading: "From the blog",
|
|
17577
|
+
why: `${missing.length} articles about ${pg.title} aren't linked from the page.`,
|
|
17578
|
+
links: missing.slice(0, 5).map((p) => ({ url: p.url, label: p.title }))
|
|
17579
|
+
});
|
|
17580
|
+
}
|
|
17581
|
+
const lonelyPosts = [];
|
|
17582
|
+
for (const d of docs) {
|
|
17583
|
+
if (d === home || d === blogPage || sample.includes(d)) continue;
|
|
17584
|
+
const ins = inbound.get(d.path);
|
|
17585
|
+
if (ins && ins.size || chrome.has(d.path)) continue;
|
|
17586
|
+
if (d.kind === "post") lonelyPosts.push(d);
|
|
17587
|
+
else
|
|
17588
|
+
findings.push({
|
|
17589
|
+
id: `orphan:${d.path}`,
|
|
17590
|
+
priority: "p2",
|
|
17591
|
+
area: "outside",
|
|
17592
|
+
title: `Nothing links to the page \u201C${d.title}\u201D (${d.path})`,
|
|
17593
|
+
why: "Pages that only the sitemap knows are found late and rank poorly.",
|
|
17594
|
+
fix: "Link to it from its parent or a related page, or put it in the menu or footer"
|
|
17595
|
+
});
|
|
17596
|
+
}
|
|
17597
|
+
if (lonelyPosts.length)
|
|
17598
|
+
findings.push({
|
|
17599
|
+
id: "orphan-posts",
|
|
17600
|
+
priority: "p3",
|
|
17601
|
+
area: "outside",
|
|
17602
|
+
title: `${lonelyPosts.length} of ${postDocs.length} articles get no links from pages or other articles (only from the blog list)`,
|
|
17603
|
+
why: "Links from related pages and articles tell search engines which articles matter and keep readers on the site.",
|
|
17604
|
+
fix: "Apply the post_link and page_related actions: each article links to its page, each page shows its articles."
|
|
17605
|
+
});
|
|
17606
|
+
const grouped = groupFindings(findings);
|
|
17607
|
+
findings.length = 0;
|
|
17608
|
+
findings.push(...grouped);
|
|
17609
|
+
return {
|
|
17610
|
+
site: base,
|
|
17611
|
+
counts: {
|
|
17612
|
+
pages: pageDocs.length + (home ? 1 : 0),
|
|
17613
|
+
posts: postDocs.length,
|
|
17614
|
+
menu_items: menuItems.length,
|
|
17615
|
+
footer_links: footerPaths.size,
|
|
17616
|
+
content_links: docs.reduce((n2, d) => n2 + d.links.size, 0),
|
|
17617
|
+
orphan_pages: findings.reduce(
|
|
17618
|
+
(n2, f) => n2 + (f.id.startsWith("orphan:") ? f.pages?.length ?? 1 : 0),
|
|
17619
|
+
0
|
|
17620
|
+
),
|
|
17621
|
+
orphan_posts: lonelyPosts.length
|
|
17622
|
+
},
|
|
17623
|
+
action_counts: Object.fromEntries(
|
|
17624
|
+
["menu", "footer", "page_related", "post_link"].map((t) => [t, actions.filter((x) => x.type === t).length])
|
|
17625
|
+
),
|
|
17626
|
+
actions: [
|
|
17627
|
+
...actions.filter((x) => x.type === "menu" || x.type === "footer"),
|
|
17628
|
+
...actions.filter((x) => x.type === "post_link").sort((x, y) => Number(y.match) - Number(x.match)).slice(0, 30),
|
|
17629
|
+
...actions.filter((x) => x.type === "page_related").slice(0, 30)
|
|
17630
|
+
],
|
|
17631
|
+
findings,
|
|
17632
|
+
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."
|
|
17633
|
+
};
|
|
17634
|
+
}
|
|
17635
|
+
var esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
17636
|
+
function relatedBlock(heading2, links2) {
|
|
17637
|
+
const items3 = links2.map((l) => `<!-- wp:list-item -->
|
|
17638
|
+
<li><a href="${esc(l.url)}">${esc(l.label)}</a></li>
|
|
17639
|
+
<!-- /wp:list-item -->`).join("\n");
|
|
17640
|
+
return `<!-- wp:group {"metadata":{"name":"Related links","maggie":{"type":"related-links","version":1}},"align":"wide","className":"maggie-related-links","layout":{"type":"constrained"}} -->
|
|
17641
|
+
<div class="wp-block-group alignwide maggie-related-links"><!-- wp:heading {"level":2} -->
|
|
17642
|
+
<h2 class="wp-block-heading">${esc(heading2)}</h2>
|
|
17643
|
+
<!-- /wp:heading -->
|
|
17644
|
+
|
|
17645
|
+
<!-- wp:list -->
|
|
17646
|
+
<ul class="wp-block-list">${items3}</ul>
|
|
17647
|
+
<!-- /wp:list --></div>
|
|
17648
|
+
<!-- /wp:group -->`;
|
|
17649
|
+
}
|
|
17650
|
+
function postLinkBlock(text3, url, label2) {
|
|
17651
|
+
return `<!-- wp:paragraph {"className":"maggie-related-link"} -->
|
|
17652
|
+
<p class="maggie-related-link">${esc(text3)} <a href="${esc(url)}">${esc(label2)}</a></p>
|
|
17653
|
+
<!-- /wp:paragraph -->`;
|
|
17654
|
+
}
|
|
17655
|
+
async function llmsTxt(site, o = {}) {
|
|
17656
|
+
const base = (site.url ?? "").replace(/\/+$/, "");
|
|
17657
|
+
const s = await site.request({
|
|
17658
|
+
path: "/wp/v2/settings",
|
|
17659
|
+
query: { _fields: "title,description,page_on_front,page_for_posts" }
|
|
17660
|
+
}).then((r) => r.status === 200 ? r.data : {});
|
|
17661
|
+
const pages = await listPages(site, { status: "publish" });
|
|
17662
|
+
const posts2 = await all(
|
|
17663
|
+
site,
|
|
17664
|
+
"/wp/v2/posts",
|
|
17665
|
+
{ status: "publish", per_page: 100, _fields: "link,title,excerpt,meta", orderby: "date", order: "desc" },
|
|
17666
|
+
o.posts ?? 25
|
|
17667
|
+
);
|
|
17668
|
+
const desc = (m, fallback = "") => String(m?.maggie_seo_description || fallback).replace(/\s+/g, " ").trim();
|
|
17669
|
+
const home = pages.find((p) => p.id === s.page_on_front);
|
|
17670
|
+
const noise = /privacy|terms|cookie|thank|cart|checkout|my-account|login/i;
|
|
17671
|
+
const visible = pages.filter((p) => p.id !== s.page_on_front && p.id !== s.page_for_posts && !noise.test(p.link));
|
|
17672
|
+
const byParent = /* @__PURE__ */ new Map();
|
|
17673
|
+
for (const p of visible) byParent.set(p.parent, [...byParent.get(p.parent) ?? [], p]);
|
|
17674
|
+
const line = (title, url, d) => `- [${title.replace(/[[\]]/g, "")}](${url})${d ? `: ${d}` : ""}`;
|
|
17675
|
+
const out = [`# ${s.title || base.replace(/^https?:\/\//, "")}`, ""];
|
|
17676
|
+
const summary = desc(home?.meta, s.description ?? "");
|
|
17677
|
+
if (summary) out.push(`> ${summary}`, "");
|
|
17678
|
+
const top = byParent.get(0) ?? [];
|
|
17679
|
+
if (top.length) {
|
|
17680
|
+
out.push("## Pages", "");
|
|
17681
|
+
for (const p of top) {
|
|
17682
|
+
out.push(line(titleOf(p.title), p.link, desc(p.meta)));
|
|
17683
|
+
for (const c of byParent.get(p.id) ?? []) out.push(` ${line(titleOf(c.title), c.link, desc(c.meta))}`);
|
|
17684
|
+
}
|
|
17685
|
+
out.push("");
|
|
17686
|
+
}
|
|
17687
|
+
if (posts2.length) {
|
|
17688
|
+
out.push("## Articles", "");
|
|
17689
|
+
for (const p of posts2)
|
|
17690
|
+
out.push(
|
|
17691
|
+
line(strip(p.title.rendered ?? ""), p.link, desc(p.meta, strip(p.excerpt?.rendered ?? "").slice(0, 160)))
|
|
17692
|
+
);
|
|
17693
|
+
out.push("");
|
|
17694
|
+
}
|
|
17695
|
+
const legal = pages.filter((p) => /privacy|terms/i.test(p.link));
|
|
17696
|
+
out.push("## Optional", "", line("Sitemap", `${base}/wp-sitemap.xml`, "every page and article"));
|
|
17697
|
+
for (const p of legal) out.push(line(titleOf(p.title), p.link, ""));
|
|
17698
|
+
return `${out.join("\n").replace(/\n{3,}/g, "\n\n").trim()}
|
|
17699
|
+
`;
|
|
17700
|
+
}
|
|
17701
|
+
|
|
16334
17702
|
// ../../packages/tools/src/wordpress.ts
|
|
16335
17703
|
var sites = /* @__PURE__ */ new WeakMap();
|
|
16336
17704
|
function siteOf(ctx) {
|
|
@@ -18832,8 +20200,276 @@ var fullTools = [
|
|
|
18832
20200
|
}
|
|
18833
20201
|
})
|
|
18834
20202
|
];
|
|
20203
|
+
var securityTools = [
|
|
20204
|
+
tool({
|
|
20205
|
+
name: "wp_security_scan",
|
|
20206
|
+
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.",
|
|
20207
|
+
parameters: {
|
|
20208
|
+
type: "object",
|
|
20209
|
+
properties: {
|
|
20210
|
+
vulnerabilities: bool("Check known vulnerabilities (default true)."),
|
|
20211
|
+
outside: bool("Check from outside like a visitor (default true).")
|
|
20212
|
+
}
|
|
20213
|
+
},
|
|
20214
|
+
group: "site",
|
|
20215
|
+
need: READ,
|
|
20216
|
+
risk: "R0",
|
|
20217
|
+
gates: ["WP"],
|
|
20218
|
+
run: (ctx, a) => securityScan(siteOf(ctx), { vulnerabilities: a.vulnerabilities !== false, outside: a.outside !== false })
|
|
20219
|
+
}),
|
|
20220
|
+
tool({
|
|
20221
|
+
name: "wp_plugin_update",
|
|
20222
|
+
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.",
|
|
20223
|
+
parameters: { type: "object", properties: { plugin: str2("Plugin id (folder/file).") }, required: ["plugin"] },
|
|
20224
|
+
group: "site",
|
|
20225
|
+
need: WRITE,
|
|
20226
|
+
risk: "W3",
|
|
20227
|
+
gates: [...GATES],
|
|
20228
|
+
confirm: (a, lang) => say(
|
|
20229
|
+
lang,
|
|
20230
|
+
`Update the plugin ${q2(a.plugin, "")} on your website to its latest version (the old version is not kept).`,
|
|
20231
|
+
`\u628A\u7DB2\u7AD9\u4E0A\u7684\u63D2\u4EF6 ${q2(a.plugin, "")} \u66F4\u65B0\u5230\u6700\u65B0\u7248\uFF08\u4E0D\u4FDD\u7559\u820A\u7248\uFF09\u3002`
|
|
20232
|
+
),
|
|
20233
|
+
run: async (ctx, a) => {
|
|
20234
|
+
const site = siteOf(ctx);
|
|
20235
|
+
const r = await call(site, {
|
|
20236
|
+
method: "POST",
|
|
20237
|
+
path: "/maggie-core/v1/plugins/update",
|
|
20238
|
+
body: { plugin: String(a.plugin ?? "").replace(/\.php$/, "") }
|
|
20239
|
+
});
|
|
20240
|
+
const home = site.url ? await check(site, `${site.url}/`, "publish") : null;
|
|
20241
|
+
return {
|
|
20242
|
+
...r,
|
|
20243
|
+
check: home,
|
|
20244
|
+
...home && !home.ok ? {
|
|
20245
|
+
warning: "The homepage has a problem after the update: deactivate the plugin (wp_plugin_set inactive) and tell the owner."
|
|
20246
|
+
} : {}
|
|
20247
|
+
};
|
|
20248
|
+
}
|
|
20249
|
+
}),
|
|
20250
|
+
tool({
|
|
20251
|
+
name: "wp_cron_unschedule",
|
|
20252
|
+
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+.",
|
|
20253
|
+
parameters: { type: "object", properties: { hook: str2("The job's hook name.") }, required: ["hook"] },
|
|
20254
|
+
group: "site",
|
|
20255
|
+
need: WRITE,
|
|
20256
|
+
risk: "W2",
|
|
20257
|
+
gates: [...GATES],
|
|
20258
|
+
confirm: (a, lang) => say(
|
|
20259
|
+
lang,
|
|
20260
|
+
`Remove the scheduled job ${q2(a.hook, "")} from your website (nothing runs it any more).`,
|
|
20261
|
+
`\u79FB\u9664\u7DB2\u7AD9\u4E0A\u5DF2\u7121\u7A0B\u5F0F\u8655\u7406\u7684\u6392\u7A0B\u5DE5\u4F5C ${q2(a.hook, "")}\u3002`
|
|
20262
|
+
),
|
|
20263
|
+
run: (ctx, a) => call(siteOf(ctx), {
|
|
20264
|
+
method: "POST",
|
|
20265
|
+
path: "/maggie-core/v1/cron/unschedule",
|
|
20266
|
+
body: { hook: String(a.hook ?? "") }
|
|
20267
|
+
})
|
|
20268
|
+
})
|
|
20269
|
+
];
|
|
20270
|
+
var LINK_ACTION = obj("One action from wp_internal_links_plan.", {
|
|
20271
|
+
type: { type: "string", enum: ["page_related", "post_link"], description: "page_related or post_link." },
|
|
20272
|
+
page: int2("page_related: the page id."),
|
|
20273
|
+
heading: str2(`page_related: the band's heading, e.g. "Related" or "From the blog".`),
|
|
20274
|
+
links: arr("page_related: links to list.", obj("", { url: str2(""), label: str2("") })),
|
|
20275
|
+
post: int2("post_link: the article id."),
|
|
20276
|
+
url: str2("post_link: the page to link to."),
|
|
20277
|
+
label: str2("post_link: the link text (the page's topic)."),
|
|
20278
|
+
text: str2('post_link: words before the link (default "Related:").')
|
|
20279
|
+
});
|
|
20280
|
+
function withRelated(blocks, heading2, links2) {
|
|
20281
|
+
const band2 = parse(relatedBlock(heading2, links2)).filter((b) => b.name);
|
|
20282
|
+
const isBand = (b) => String(b.attrs.className ?? "").includes("maggie-related-links") && serialize([b]).includes(`>${heading2.replace(/&/g, "&").replace(/</g, "<")}</h2>`);
|
|
20283
|
+
const at = blocks.findIndex(isBand);
|
|
20284
|
+
if (at >= 0) return [...blocks.slice(0, at), ...band2, ...blocks.slice(at + 1)];
|
|
20285
|
+
const real = blocks.map((b, i) => [b, i]).filter(([b]) => b.name);
|
|
20286
|
+
const last = real[real.length - 1];
|
|
20287
|
+
const lastType = last ? classify(last[0], "main") : "";
|
|
20288
|
+
if (last && /cta|form|map-contact|contact/.test(lastType))
|
|
20289
|
+
return [...blocks.slice(0, last[1]), ...band2, ...blocks.slice(last[1])];
|
|
20290
|
+
return [...blocks, ...band2];
|
|
20291
|
+
}
|
|
20292
|
+
var seoTechTools = [
|
|
20293
|
+
tool({
|
|
20294
|
+
name: "wp_seo_tech_audit",
|
|
20295
|
+
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.",
|
|
20296
|
+
parameters: {
|
|
20297
|
+
type: "object",
|
|
20298
|
+
properties: {
|
|
20299
|
+
limit: int2("Pages to crawl from the sitemap (default 60, max 200)."),
|
|
20300
|
+
speed: bool("Also measure the homepage's speed on phones (slower, about 30 s).")
|
|
20301
|
+
}
|
|
20302
|
+
},
|
|
20303
|
+
group: "site",
|
|
20304
|
+
need: READ,
|
|
20305
|
+
risk: "R0",
|
|
20306
|
+
gates: ["WP"],
|
|
20307
|
+
run: (ctx, a) => techAudit(siteOf(ctx), { limit: typeof a.limit === "number" ? a.limit : void 0, speed: !!a.speed })
|
|
20308
|
+
}),
|
|
20309
|
+
tool({
|
|
20310
|
+
name: "wp_internal_links_plan",
|
|
20311
|
+
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.",
|
|
20312
|
+
parameters: { type: "object", properties: { posts: int2("Articles to include (default 200, newest first).") } },
|
|
20313
|
+
group: "site",
|
|
20314
|
+
need: READ,
|
|
20315
|
+
risk: "R0",
|
|
20316
|
+
gates: ["WP"],
|
|
20317
|
+
run: (ctx, a) => linksPlan(siteOf(ctx), { posts: typeof a.posts === "number" ? a.posts : void 0 })
|
|
20318
|
+
}),
|
|
20319
|
+
tool({
|
|
20320
|
+
name: "wp_internal_links_apply",
|
|
20321
|
+
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.',
|
|
20322
|
+
parameters: {
|
|
20323
|
+
type: "object",
|
|
20324
|
+
properties: { actions: arr("Up to 20 actions.", LINK_ACTION), preview: PREVIEW },
|
|
20325
|
+
required: ["actions"]
|
|
20326
|
+
},
|
|
20327
|
+
group: "site",
|
|
20328
|
+
need: WRITE,
|
|
20329
|
+
risk: "W3",
|
|
20330
|
+
gates: [...GATES],
|
|
20331
|
+
confirm: (a, lang) => {
|
|
20332
|
+
const n2 = Array.isArray(a.actions) ? a.actions.length : 0;
|
|
20333
|
+
return say(
|
|
20334
|
+
lang,
|
|
20335
|
+
`Add internal links on your website (${n2} ${n2 === 1 ? "change" : "changes"}: related-links bands on pages, a related line at the end of articles).`,
|
|
20336
|
+
`\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`
|
|
20337
|
+
);
|
|
20338
|
+
},
|
|
20339
|
+
run: async (ctx, a) => {
|
|
20340
|
+
const site = siteOf(ctx);
|
|
20341
|
+
const acts = Array.isArray(a.actions) ? a.actions : [];
|
|
20342
|
+
if (!acts.length) throw new Error("actions: give at least one action from wp_internal_links_plan.");
|
|
20343
|
+
if (acts.length > 20) throw new Error("actions: up to 20 at a time.");
|
|
20344
|
+
const results = [];
|
|
20345
|
+
const byPage = /* @__PURE__ */ new Map();
|
|
20346
|
+
for (const x of acts) {
|
|
20347
|
+
if (x.type === "page_related") {
|
|
20348
|
+
if (!x.page || !x.links?.length) throw new Error("page_related needs page and links.");
|
|
20349
|
+
byPage.set(x.page, [...byPage.get(x.page) ?? [], x]);
|
|
20350
|
+
} else if (x.type === "post_link") {
|
|
20351
|
+
if (!x.post || !x.url || !x.label) throw new Error("post_link needs post, url and label.");
|
|
20352
|
+
} else throw new Error(`Unknown action type ${x.type}.`);
|
|
20353
|
+
}
|
|
20354
|
+
for (const [page, list3] of byPage) {
|
|
20355
|
+
const r = await changePage(ctx, { page, preview: !!a.preview }, (blocks) => {
|
|
20356
|
+
let next = blocks;
|
|
20357
|
+
for (const x of list3)
|
|
20358
|
+
next = withRelated(next, (x.heading || "Related").slice(0, 80), (x.links ?? []).slice(0, 12));
|
|
20359
|
+
return { blocks: next, note: { related: list3.map((x) => x.heading || "Related") } };
|
|
20360
|
+
});
|
|
20361
|
+
results.push({ type: "page_related", page_id: page, ...r });
|
|
20362
|
+
}
|
|
20363
|
+
for (const x of acts.filter((y) => y.type === "post_link")) {
|
|
20364
|
+
const post = await call(site, {
|
|
20365
|
+
path: `/wp/v2/posts/${Number(x.post)}`,
|
|
20366
|
+
query: { context: "edit", _fields: "id,link,content,modified" }
|
|
20367
|
+
});
|
|
20368
|
+
const kept = parse(post.content.raw).filter(
|
|
20369
|
+
(b) => !(b.name === "core/paragraph" && String(b.attrs.className ?? "").includes("maggie-related-link"))
|
|
20370
|
+
);
|
|
20371
|
+
const line = parse(postLinkBlock(x.text || "Related:", String(x.url), String(x.label))).filter((b) => b.name);
|
|
20372
|
+
const content = serialize([...kept, ...line]);
|
|
20373
|
+
if (a.preview) {
|
|
20374
|
+
results.push({
|
|
20375
|
+
type: "post_link",
|
|
20376
|
+
post: post.id,
|
|
20377
|
+
path: post.link,
|
|
20378
|
+
preview: true,
|
|
20379
|
+
adds: `${x.text || "Related:"} ${x.label} \u2192 ${x.url}`
|
|
20380
|
+
});
|
|
20381
|
+
continue;
|
|
20382
|
+
}
|
|
20383
|
+
const saved = await call(site, {
|
|
20384
|
+
method: "POST",
|
|
20385
|
+
path: `/wp/v2/posts/${post.id}`,
|
|
20386
|
+
query: { _fields: "id,link,modified" },
|
|
20387
|
+
body: { content }
|
|
20388
|
+
});
|
|
20389
|
+
results.push({
|
|
20390
|
+
type: "post_link",
|
|
20391
|
+
post: saved.id,
|
|
20392
|
+
path: saved.link,
|
|
20393
|
+
saved: true,
|
|
20394
|
+
modified: saved.modified,
|
|
20395
|
+
link: { url: x.url, label: x.label }
|
|
20396
|
+
});
|
|
20397
|
+
}
|
|
20398
|
+
return {
|
|
20399
|
+
results,
|
|
20400
|
+
...a.preview ? { preview: true } : { undo: "Pages: wp_page_undo; articles: restore the earlier revision in the editor." }
|
|
20401
|
+
};
|
|
20402
|
+
}
|
|
20403
|
+
}),
|
|
20404
|
+
tool({
|
|
20405
|
+
name: "wp_llms_txt_get",
|
|
20406
|
+
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+.",
|
|
20407
|
+
parameters: { type: "object", properties: {} },
|
|
20408
|
+
group: "site",
|
|
20409
|
+
need: READ,
|
|
20410
|
+
risk: "R0",
|
|
20411
|
+
gates: ["WP"],
|
|
20412
|
+
run: async (ctx) => {
|
|
20413
|
+
const site = siteOf(ctx);
|
|
20414
|
+
const saved = await call(site, { path: "/maggie-core/v1/llms" });
|
|
20415
|
+
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;
|
|
20416
|
+
return {
|
|
20417
|
+
...saved,
|
|
20418
|
+
live,
|
|
20419
|
+
...saved.file ? {
|
|
20420
|
+
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."
|
|
20421
|
+
} : {}
|
|
20422
|
+
};
|
|
20423
|
+
}
|
|
20424
|
+
}),
|
|
20425
|
+
tool({
|
|
20426
|
+
name: "wp_llms_txt_set",
|
|
20427
|
+
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+.`,
|
|
20428
|
+
parameters: {
|
|
20429
|
+
type: "object",
|
|
20430
|
+
properties: {
|
|
20431
|
+
generate: bool("Build it from the site."),
|
|
20432
|
+
text: str2("The llms.txt Markdown to save."),
|
|
20433
|
+
posts: int2("Articles to list when generating (default 25)."),
|
|
20434
|
+
preview: PREVIEW
|
|
20435
|
+
}
|
|
20436
|
+
},
|
|
20437
|
+
group: "site",
|
|
20438
|
+
need: WRITE,
|
|
20439
|
+
risk: "W2",
|
|
20440
|
+
gates: [...GATES],
|
|
20441
|
+
confirm: (a, lang) => say(
|
|
20442
|
+
lang,
|
|
20443
|
+
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).",
|
|
20444
|
+
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"
|
|
20445
|
+
),
|
|
20446
|
+
run: async (ctx, a) => {
|
|
20447
|
+
const site = siteOf(ctx);
|
|
20448
|
+
const text3 = typeof a.text === "string" ? a.text : a.generate ? await llmsTxt(site, { posts: typeof a.posts === "number" ? a.posts : void 0 }) : null;
|
|
20449
|
+
if (text3 == null) throw new Error("Give text, or generate: true.");
|
|
20450
|
+
if (/<\?(php|=)?|<script\b/i.test(text3)) throw new Error("llms.txt: plain Markdown only.");
|
|
20451
|
+
if (a.preview) return { preview: true, text: text3, characters: text3.length };
|
|
20452
|
+
const r = await call(site, {
|
|
20453
|
+
method: "POST",
|
|
20454
|
+
path: "/maggie-core/v1/llms",
|
|
20455
|
+
body: { text: text3 }
|
|
20456
|
+
});
|
|
20457
|
+
return {
|
|
20458
|
+
saved: r.saved,
|
|
20459
|
+
url: r.url,
|
|
20460
|
+
characters: text3.length,
|
|
20461
|
+
before_characters: r.before.length,
|
|
20462
|
+
...r.file ? { note: "A real llms.txt file on the server is served instead: delete it at the host." } : {},
|
|
20463
|
+
undo: r.before ? "wp_llms_txt_set text with the earlier text (before is kept in this result)" : 'wp_llms_txt_set text ""',
|
|
20464
|
+
before: r.before
|
|
20465
|
+
};
|
|
20466
|
+
}
|
|
20467
|
+
})
|
|
20468
|
+
];
|
|
18835
20469
|
var wordpressTools = [
|
|
18836
20470
|
...fullTools,
|
|
20471
|
+
...securityTools,
|
|
20472
|
+
...seoTechTools,
|
|
18837
20473
|
...siteTools,
|
|
18838
20474
|
...pageTools,
|
|
18839
20475
|
...sectionTools,
|
|
@@ -22252,7 +23888,7 @@ var program = new Command();
|
|
|
22252
23888
|
// package.json
|
|
22253
23889
|
var package_default = {
|
|
22254
23890
|
name: "@cmo-so/cli",
|
|
22255
|
-
version: "0.12.
|
|
23891
|
+
version: "0.12.13",
|
|
22256
23892
|
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.",
|
|
22257
23893
|
type: "module",
|
|
22258
23894
|
license: "MIT",
|
|
@@ -22336,7 +23972,7 @@ var fileStore = () => {
|
|
|
22336
23972
|
const file = join(configDir(), "credentials.json");
|
|
22337
23973
|
return {
|
|
22338
23974
|
load: () => readJson(file),
|
|
22339
|
-
save: (
|
|
23975
|
+
save: (tokens2) => writePrivate(file, tokens2),
|
|
22340
23976
|
clear: () => rm(file, { force: true })
|
|
22341
23977
|
};
|
|
22342
23978
|
};
|
|
@@ -22492,7 +24128,7 @@ __export(util_exports, {
|
|
|
22492
24128
|
defineLazy: () => defineLazy,
|
|
22493
24129
|
defineLazyInternal: () => defineLazyInternal,
|
|
22494
24130
|
derived: () => derived,
|
|
22495
|
-
esc: () =>
|
|
24131
|
+
esc: () => esc2,
|
|
22496
24132
|
escapeRegex: () => escapeRegex,
|
|
22497
24133
|
explicitlyAborted: () => explicitlyAborted,
|
|
22498
24134
|
extend: () => extend,
|
|
@@ -22723,7 +24359,7 @@ function randomString(length = 10) {
|
|
|
22723
24359
|
}
|
|
22724
24360
|
return str3;
|
|
22725
24361
|
}
|
|
22726
|
-
function
|
|
24362
|
+
function esc2(str3) {
|
|
22727
24363
|
return JSON.stringify(str3);
|
|
22728
24364
|
}
|
|
22729
24365
|
function slugify(input) {
|
|
@@ -24872,14 +26508,14 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
24872
26508
|
const desc = Object.getOwnPropertyDescriptor(def, "shape");
|
|
24873
26509
|
const sh = desc?.get ? desc.get.raw : def.shape ?? {};
|
|
24874
26510
|
if (sh) {
|
|
24875
|
-
const
|
|
26511
|
+
const get2 = () => {
|
|
24876
26512
|
const newSh = { ...sh };
|
|
24877
26513
|
Object.defineProperty(def, "shape", { value: newSh });
|
|
24878
|
-
|
|
26514
|
+
get2.raw = newSh;
|
|
24879
26515
|
return newSh;
|
|
24880
26516
|
};
|
|
24881
|
-
|
|
24882
|
-
Object.defineProperty(def, "shape", { get });
|
|
26517
|
+
get2.raw = sh;
|
|
26518
|
+
Object.defineProperty(def, "shape", { get: get2 });
|
|
24883
26519
|
}
|
|
24884
26520
|
const _normalized = cached(() => normalizeDef(def));
|
|
24885
26521
|
defineLazyInternal(inst, "propValues", (zod) => {
|
|
@@ -24978,7 +26614,7 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
24978
26614
|
if (key === "__proto__")
|
|
24979
26615
|
continue;
|
|
24980
26616
|
const id = ids3[key];
|
|
24981
|
-
const k = typeof key === "symbol" ? `syms[${syms.indexOf(key)}]` :
|
|
26617
|
+
const k = typeof key === "symbol" ? `syms[${syms.indexOf(key)}]` : esc2(key);
|
|
24982
26618
|
const isPresent = `${k} in input`;
|
|
24983
26619
|
const schema = shape[key];
|
|
24984
26620
|
const optin = schema?._zod?.optin;
|
|
@@ -27950,7 +29586,7 @@ var parseAsync2 = /* @__PURE__ */ _parseAsync(ZodRealError);
|
|
|
27950
29586
|
var safeParse3 = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
27951
29587
|
var safeParseAsync2 = /* @__PURE__ */ _safeParseAsync(ZodRealError);
|
|
27952
29588
|
var encode2 = /* @__PURE__ */ _encode(ZodRealError);
|
|
27953
|
-
var
|
|
29589
|
+
var decode4 = /* @__PURE__ */ _decode(ZodRealError);
|
|
27954
29590
|
var encodeAsync2 = /* @__PURE__ */ _encodeAsync(ZodRealError);
|
|
27955
29591
|
var decodeAsync2 = /* @__PURE__ */ _decodeAsync(ZodRealError);
|
|
27956
29592
|
var safeEncode2 = /* @__PURE__ */ _safeEncode(ZodRealError);
|
|
@@ -28110,7 +29746,7 @@ var ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
|
|
|
28110
29746
|
return encode2(this, data, params, { callee: _encode2 });
|
|
28111
29747
|
},
|
|
28112
29748
|
decode: function _decode2(data, params) {
|
|
28113
|
-
return
|
|
29749
|
+
return decode4(this, data, params, { callee: _decode2 });
|
|
28114
29750
|
},
|
|
28115
29751
|
encodeAsync: async function _encodeAsync2(data, params) {
|
|
28116
29752
|
return await encodeAsync2(this, data, params, { callee: _encodeAsync2 });
|
|
@@ -33313,7 +34949,36 @@ function registerWp(program3) {
|
|
|
33313
34949
|
(p, s, o, c) => run(g(c), "wp_section_move", { page: p, section: s, ...posArgs(o) })
|
|
33314
34950
|
);
|
|
33315
34951
|
section.command("remove <page> <section>").description("remove a section").action((p, s, _o, c) => run(g(c), "wp_section_remove", { page: p, section: s }));
|
|
33316
|
-
const seo = wp.command("seo").description("SEO fields, audit, import");
|
|
34952
|
+
const seo = wp.command("seo").description("SEO fields, audit, technical check, import");
|
|
34953
|
+
seo.command("tech").description(
|
|
34954
|
+
"technical SEO check: robots.txt, sitemap pages, canonicals, noindex, H1, alt text, schema, links, llms.txt"
|
|
34955
|
+
).option("--limit <n>", "pages to crawl (default 60, max 200)").option("--speed", "also measure the homepage's Core Web Vitals on phones").action(
|
|
34956
|
+
(o, c) => run(g(c), "wp_seo_tech_audit", { limit: o.limit ? Number(o.limit) : void 0, speed: !!o.speed })
|
|
34957
|
+
);
|
|
34958
|
+
const links2 = wp.command("links").description("internal links: plan and apply (pages, articles, menu, footer)");
|
|
34959
|
+
links2.command("plan", { isDefault: true }).action((_o, c) => run(g(c), "wp_internal_links_plan", {}));
|
|
34960
|
+
links2.command("apply").description("apply page_related / post_link actions from the plan (JSON array or { actions })").requiredOption("--from <file>", "JSON (- for stdin)").option("--preview", "show the changes, save nothing").action(async (o, c) => {
|
|
34961
|
+
const j = await json(o.from);
|
|
34962
|
+
const actions = Array.isArray(j) ? j : j.actions;
|
|
34963
|
+
await run(g(c), "wp_internal_links_apply", { actions, preview: !!o.preview });
|
|
34964
|
+
});
|
|
34965
|
+
const llms = wp.command("llms").description("the site's llms.txt (served at /llms.txt)");
|
|
34966
|
+
llms.command("get", { isDefault: true }).action((_o, c) => run(g(c), "wp_llms_txt_get", {}));
|
|
34967
|
+
llms.command("generate").description("build llms.txt from the site and save it").option("--preview", "show it, save nothing").option("--posts <n>", "articles to list (default 25)").action(
|
|
34968
|
+
(o, c) => run(g(c), "wp_llms_txt_set", {
|
|
34969
|
+
generate: true,
|
|
34970
|
+
preview: !!o.preview,
|
|
34971
|
+
posts: o.posts ? Number(o.posts) : void 0
|
|
34972
|
+
})
|
|
34973
|
+
);
|
|
34974
|
+
llms.command("set <file>").description("save this Markdown file as llms.txt").action(
|
|
34975
|
+
async (file, _o, c) => run(g(c), "wp_llms_txt_set", { text: await readFile2(file, "utf8") })
|
|
34976
|
+
);
|
|
34977
|
+
llms.command("off").action((_o, c) => run(g(c), "wp_llms_txt_set", { text: "" }));
|
|
34978
|
+
wp.command("security").description(
|
|
34979
|
+
"security check: vulnerable or outdated plugins, themes and WordPress, risky settings, admins, WP-Cron, what visitors can see"
|
|
34980
|
+
).option("--no-outside", "skip the checks from outside").action((o, c) => run(g(c), "wp_security_scan", { outside: o.outside !== false }));
|
|
34981
|
+
wp.command("cron-rm <hook>").description("remove a scheduled job nothing runs any more (left by a removed plugin)").action((hook, _o, c) => run(g(c), "wp_cron_unschedule", { hook }));
|
|
33317
34982
|
seo.command("get <page>").description("stored fields and what the page outputs").action((p, _o, c) => run(g(c), "wp_seo_get", { page: p }));
|
|
33318
34983
|
seo.command("set <page>").description("set a page's SEO fields").option("--title <t>").option("--description <d>").option("--keywords <k>").option("--robots <r>", '"index, follow" | "noindex, follow" | "noindex, nofollow"').option("--canonical <url>").option("--og-image <url>").option("--from <file>", "several pages: JSON { items: [{ page, title, description, \u2026 }] }").action(async (p, o, c) => {
|
|
33319
34984
|
const args = o.from ? await json(o.from) : {
|
|
@@ -33486,6 +35151,7 @@ ${table(r.issues, ["severity", "code", "path", "detail"])}`;
|
|
|
33486
35151
|
);
|
|
33487
35152
|
plugins.command("activate <plugin>").action((p, _o, c) => run(g(c), "wp_plugin_set", { plugin: p, status: "active" }));
|
|
33488
35153
|
plugins.command("deactivate <plugin>").action((p, _o, c) => run(g(c), "wp_plugin_set", { plugin: p, status: "inactive" }));
|
|
35154
|
+
plugins.command("update <plugin>").description("update an installed plugin to its latest version (Maggie Core 0.14+)").action((p, _o, c) => run(g(c), "wp_plugin_update", { plugin: p }));
|
|
33489
35155
|
plugins.command("delete <plugin>").description("remove an inactive plugin's files (reinstall from WordPress.org to undo)").action((p, _o, c) => run(g(c), "wp_plugin_set", { plugin: p, status: "deleted" }));
|
|
33490
35156
|
wp.command("api <route>").description("read any allowed WordPress REST route (GET), e.g. /wp/v2/types").option("--query <json>", "query parameters as JSON").action(
|
|
33491
35157
|
(route, o, c) => run(g(c), "wp_api_read", { route, query: o.query ? JSON.parse(o.query) : void 0 })
|