@gotmar/audit 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +14 -2
- package/dist/crawl.d.ts +28 -0
- package/dist/crawl.js +266 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +696 -0
- package/dist/launch.d.ts +22 -0
- package/dist/launch.js +150 -0
- package/dist/robots.d.ts +21 -0
- package/dist/robots.js +80 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.js +1 -0
- package/package.json +38 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,696 @@
|
|
|
1
|
+
import { parse } from "node-html-parser";
|
|
2
|
+
import { crawlSite } from "./crawl.js";
|
|
3
|
+
import { isAllowed, parseRobots } from "./robots.js";
|
|
4
|
+
export * from "./types.js";
|
|
5
|
+
export { isAllowed, parseRobots } from "./robots.js";
|
|
6
|
+
export { newIssues } from "./crawl.js";
|
|
7
|
+
export { LAUNCH_CHANNELS, trackedLink } from "./launch.js";
|
|
8
|
+
const DEFAULT_UA = "Mozilla/5.0 (compatible; GotmarAudit/0.1; +https://getgotmar.com/bot)";
|
|
9
|
+
/** Crawlers that decide whether you show up in classic search. */
|
|
10
|
+
export const SEARCH_BOTS = ["Googlebot", "Bingbot"];
|
|
11
|
+
/** Crawlers that fetch pages to answer questions or cite sources in AI search. */
|
|
12
|
+
export const AI_SEARCH_BOTS = [
|
|
13
|
+
"OAI-SearchBot",
|
|
14
|
+
"ChatGPT-User",
|
|
15
|
+
"Claude-SearchBot",
|
|
16
|
+
"Claude-User",
|
|
17
|
+
"PerplexityBot",
|
|
18
|
+
"Perplexity-User",
|
|
19
|
+
];
|
|
20
|
+
/** Crawlers (or robots tokens) used for model training. Blocking these is a choice, not a mistake. */
|
|
21
|
+
export const AI_TRAINING_BOTS = ["GPTBot", "ClaudeBot", "Google-Extended", "Applebot-Extended", "CCBot"];
|
|
22
|
+
export const LINKS = {
|
|
23
|
+
searchConsole: "https://search.google.com/search-console",
|
|
24
|
+
bingWebmaster: "https://www.bing.com/webmasters",
|
|
25
|
+
richResults: "https://search.google.com/test/rich-results",
|
|
26
|
+
pageSpeed: "https://pagespeed.web.dev/",
|
|
27
|
+
};
|
|
28
|
+
function normalizeUrl(input) {
|
|
29
|
+
const trimmed = input.trim();
|
|
30
|
+
const withScheme = /^https?:\/\//i.test(trimmed) ? trimmed : `https://${trimmed}`;
|
|
31
|
+
return new URL(withScheme).toString();
|
|
32
|
+
}
|
|
33
|
+
function looksLikeHtml(body) {
|
|
34
|
+
return /^\s*(<!doctype html|<html)/i.test(body);
|
|
35
|
+
}
|
|
36
|
+
async function get(url, opts) {
|
|
37
|
+
const doFetch = opts.fetch ?? fetch;
|
|
38
|
+
const started = Date.now();
|
|
39
|
+
try {
|
|
40
|
+
const res = await doFetch(url, {
|
|
41
|
+
redirect: "follow",
|
|
42
|
+
headers: {
|
|
43
|
+
"user-agent": opts.userAgent ?? DEFAULT_UA,
|
|
44
|
+
accept: "text/html,application/xhtml+xml,application/xml;q=0.9,text/plain;q=0.8,*/*;q=0.5",
|
|
45
|
+
...opts.headers,
|
|
46
|
+
},
|
|
47
|
+
signal: AbortSignal.timeout(opts.timeoutMs ?? 15000),
|
|
48
|
+
});
|
|
49
|
+
const text = await res.text();
|
|
50
|
+
return { status: res.status, text, finalUrl: res.url || url, ms: Date.now() - started, headers: res.headers };
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function grade(score) {
|
|
57
|
+
if (score >= 90)
|
|
58
|
+
return "A";
|
|
59
|
+
if (score >= 75)
|
|
60
|
+
return "B";
|
|
61
|
+
if (score >= 60)
|
|
62
|
+
return "C";
|
|
63
|
+
if (score >= 40)
|
|
64
|
+
return "D";
|
|
65
|
+
return "F";
|
|
66
|
+
}
|
|
67
|
+
const PENALTY = { critical: 20, warning: 8, info: 2 };
|
|
68
|
+
function collectJsonLdTypes(node, out) {
|
|
69
|
+
if (Array.isArray(node)) {
|
|
70
|
+
node.forEach((n) => collectJsonLdTypes(n, out));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (node && typeof node === "object") {
|
|
74
|
+
const obj = node;
|
|
75
|
+
const t = obj["@type"];
|
|
76
|
+
if (typeof t === "string")
|
|
77
|
+
out.add(t);
|
|
78
|
+
if (Array.isArray(t))
|
|
79
|
+
t.forEach((x) => typeof x === "string" && out.add(x));
|
|
80
|
+
if (obj["@graph"])
|
|
81
|
+
collectJsonLdTypes(obj["@graph"], out);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Audit a live URL the way search and AI crawlers see it: raw HTML, no JavaScript.
|
|
86
|
+
* Every issue carries a `fix` written as an instruction a coding agent can follow.
|
|
87
|
+
*/
|
|
88
|
+
export async function runAudit(inputUrl, opts = {}) {
|
|
89
|
+
const url = normalizeUrl(inputUrl);
|
|
90
|
+
const issues = [];
|
|
91
|
+
const passed = [];
|
|
92
|
+
const add = (issue) => issues.push(issue);
|
|
93
|
+
const pass = (id, category, title) => passed.push({ id, category, title });
|
|
94
|
+
const finish = (page, facts) => {
|
|
95
|
+
// Reminders the audit cannot confirm from HTML (e.g. DNS-verified Search Console) don't cost points.
|
|
96
|
+
const unscored = new Set(["search-console", "bing-webmaster"]);
|
|
97
|
+
// A page we could not read as HTML scores 0: nothing else can be judged.
|
|
98
|
+
const score = facts
|
|
99
|
+
? Math.max(0, 100 - issues.reduce((sum, i) => sum + (unscored.has(i.id) ? 0 : PENALTY[i.severity]), 0))
|
|
100
|
+
: 0;
|
|
101
|
+
const order = { critical: 0, warning: 1, info: 2 };
|
|
102
|
+
issues.sort((a, b) => order[a.severity] - order[b.severity]);
|
|
103
|
+
return {
|
|
104
|
+
url,
|
|
105
|
+
finalUrl: page?.finalUrl ?? url,
|
|
106
|
+
fetchedAt: new Date().toISOString(),
|
|
107
|
+
status: page?.status ?? 0,
|
|
108
|
+
responseMs: page?.ms ?? 0,
|
|
109
|
+
score,
|
|
110
|
+
grade: grade(score),
|
|
111
|
+
issues,
|
|
112
|
+
passed,
|
|
113
|
+
facts,
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
const page = await get(url, opts);
|
|
117
|
+
if (!page || page.status >= 400) {
|
|
118
|
+
const blocked = page && [401, 403, 429, 503].includes(page.status);
|
|
119
|
+
add({
|
|
120
|
+
id: blocked ? "blocked" : "unreachable",
|
|
121
|
+
severity: "critical",
|
|
122
|
+
category: "indexing",
|
|
123
|
+
title: blocked ? "The site refused an automated request" : "Page could not be loaded",
|
|
124
|
+
detail: !page
|
|
125
|
+
? "The request failed or timed out. Check the URL and that the site is deployed."
|
|
126
|
+
: blocked
|
|
127
|
+
? `The server answered HTTP ${page.status} to Gotmar's crawler. Bot protection (for example Cloudflare's "Block AI bots" or Vercel's Attack Challenge Mode) may be blocking search and AI crawlers too, even if robots.txt allows them.`
|
|
128
|
+
: `The server answered with HTTP ${page.status}. Crawlers will drop pages that error.`,
|
|
129
|
+
fix: blocked
|
|
130
|
+
? "Ask the human to check their host's firewall / bot-protection settings and allow verified search and AI crawlers (Googlebot, Bingbot, OAI-SearchBot, PerplexityBot, Claude-SearchBot). Re-run the audit after."
|
|
131
|
+
: "Make sure the production URL returns HTTP 200 for the homepage, then re-run the audit.",
|
|
132
|
+
});
|
|
133
|
+
return finish(page, null);
|
|
134
|
+
}
|
|
135
|
+
const contentType = (page.headers.get("content-type") ?? "").toLowerCase();
|
|
136
|
+
if ((contentType && !contentType.includes("html")) || (!contentType && !/<html|<head|<body/i.test(page.text))) {
|
|
137
|
+
add({
|
|
138
|
+
id: "not-html",
|
|
139
|
+
severity: "critical",
|
|
140
|
+
category: "indexing",
|
|
141
|
+
title: "This URL is not a web page",
|
|
142
|
+
detail: `It returned ${contentType || "non-HTML content"}. Audit the site's homepage or a public page instead.`,
|
|
143
|
+
fix: "Run the audit on the public homepage URL.",
|
|
144
|
+
});
|
|
145
|
+
return finish(page, null);
|
|
146
|
+
}
|
|
147
|
+
const finalUrl = new URL(page.finalUrl);
|
|
148
|
+
const origin = finalUrl.origin;
|
|
149
|
+
// Fetch the crawl files in parallel with HTML analysis.
|
|
150
|
+
const robotsPromise = get(`${origin}/robots.txt`, opts);
|
|
151
|
+
const llmsPromise = get(`${origin}/llms.txt`, opts);
|
|
152
|
+
const root = parse(page.text, { comment: false });
|
|
153
|
+
const metas = root.querySelectorAll("meta");
|
|
154
|
+
const metaContent = (key) => {
|
|
155
|
+
const k = key.toLowerCase();
|
|
156
|
+
for (const m of metas) {
|
|
157
|
+
const name = (m.getAttribute("name") ?? m.getAttribute("property") ?? "").toLowerCase();
|
|
158
|
+
if (name === k)
|
|
159
|
+
return (m.getAttribute("content") ?? "").trim();
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
};
|
|
163
|
+
const links = root.querySelectorAll("link");
|
|
164
|
+
const canonical = links.find((l) => (l.getAttribute("rel") ?? "").toLowerCase().split(/\s+/).includes("canonical"))?.getAttribute("href") ??
|
|
165
|
+
null;
|
|
166
|
+
const title = root.querySelector("title")?.text.trim() || null;
|
|
167
|
+
const description = metaContent("description");
|
|
168
|
+
const lang = root.querySelector("html")?.getAttribute("lang") ?? null;
|
|
169
|
+
const viewport = metaContent("viewport");
|
|
170
|
+
const robotsMeta = [metaContent("robots"), metaContent("googlebot")].filter(Boolean).join(",").toLowerCase();
|
|
171
|
+
// Hosts add X-Robots-Tag: noindex to preview deployments; that's expected there.
|
|
172
|
+
const xRobots = opts.preview ? "" : (page.headers.get("x-robots-tag") ?? "").toLowerCase();
|
|
173
|
+
const ogTitle = metaContent("og:title");
|
|
174
|
+
const ogDescription = metaContent("og:description");
|
|
175
|
+
const ogImage = metaContent("og:image");
|
|
176
|
+
const twitterCard = metaContent("twitter:card");
|
|
177
|
+
// An empty tag (left as a placeholder) does not count as verified.
|
|
178
|
+
const googleVerification = !!metaContent("google-site-verification");
|
|
179
|
+
const bingVerification = !!metaContent("msvalidate.01");
|
|
180
|
+
const h1 = root.querySelectorAll("h1").map((n) => n.text.trim().replace(/\s+/g, " "));
|
|
181
|
+
const images = root.querySelectorAll("img");
|
|
182
|
+
const imagesMissingAlt = images.filter((img) => img.getAttribute("alt") === undefined).length;
|
|
183
|
+
const jsonLdTypes = new Set();
|
|
184
|
+
let jsonLdInvalid = 0;
|
|
185
|
+
for (const s of root.querySelectorAll("script")) {
|
|
186
|
+
if ((s.getAttribute("type") ?? "").toLowerCase() !== "application/ld+json")
|
|
187
|
+
continue;
|
|
188
|
+
try {
|
|
189
|
+
collectJsonLdTypes(JSON.parse(s.rawText), jsonLdTypes);
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
jsonLdInvalid++;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// A client-rendered app ships an empty mount point plus scripts.
|
|
196
|
+
const mountPoint = root.querySelector("#root, #app, #__nuxt, #svelte, [data-reactroot]");
|
|
197
|
+
const scriptCount = root.querySelectorAll("script[src]").length;
|
|
198
|
+
const looksClientRendered = !!mountPoint && mountPoint.text.trim().length < 40 && scriptCount > 0;
|
|
199
|
+
// Visible text, as a crawler that does not run JavaScript sees it.
|
|
200
|
+
root.querySelectorAll("script,style,noscript,template,svg").forEach((n) => n.remove());
|
|
201
|
+
const body = root.querySelector("body") ?? root;
|
|
202
|
+
const words = body.text.split(/\s+/).filter((w) => /[\p{L}\p{N}]/u.test(w));
|
|
203
|
+
const wordCount = words.length;
|
|
204
|
+
// ---------- Indexing ----------
|
|
205
|
+
if (finalUrl.protocol !== "https:") {
|
|
206
|
+
add({
|
|
207
|
+
id: "no-https",
|
|
208
|
+
severity: "warning",
|
|
209
|
+
category: "indexing",
|
|
210
|
+
title: "Site is not served over HTTPS",
|
|
211
|
+
detail: `The page resolved to ${finalUrl.href}.`,
|
|
212
|
+
fix: "Serve the site over HTTPS and redirect http:// to https://. On Vercel this is automatic for custom domains.",
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
else
|
|
216
|
+
pass("https", "indexing", "Served over HTTPS");
|
|
217
|
+
if (robotsMeta.includes("noindex") || xRobots.includes("noindex")) {
|
|
218
|
+
add({
|
|
219
|
+
id: "noindex",
|
|
220
|
+
severity: "critical",
|
|
221
|
+
category: "indexing",
|
|
222
|
+
title: "Page tells search engines not to index it",
|
|
223
|
+
detail: `Found noindex in ${robotsMeta.includes("noindex") ? "a robots meta tag" : "the X-Robots-Tag header"}.`,
|
|
224
|
+
fix: "Remove `noindex` from the production homepage (check `metadata.robots` in the root layout and any middleware headers). Keep noindex only on preview deployments.",
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
else
|
|
228
|
+
pass("indexable", "indexing", "Page is indexable");
|
|
229
|
+
if (wordCount < 50) {
|
|
230
|
+
add({
|
|
231
|
+
id: "empty-html",
|
|
232
|
+
severity: "critical",
|
|
233
|
+
category: "ai-search",
|
|
234
|
+
title: looksClientRendered ? "Crawlers see an empty page (client-rendered app)" : "Crawlers see an almost empty page",
|
|
235
|
+
detail: looksClientRendered
|
|
236
|
+
? `The HTML is an empty app shell with ${wordCount} words of text; the content only appears after JavaScript runs. Most AI crawlers (GPTBot, ClaudeBot, PerplexityBot) do not run JavaScript, so they see nothing to index or quote. This is typical of React/Vite apps built with Lovable, Bolt or Create React App.`
|
|
237
|
+
: `The page has only ${wordCount} words of text. Search engines and AI tools need a few paragraphs to understand what the product is and who it is for.`,
|
|
238
|
+
fix: looksClientRendered
|
|
239
|
+
? "Render public pages' content into the HTML. In Next.js, keep page content in Server Components (no `'use client'` at the page level). For Vite/React SPAs, prerender the public routes at build time, or move the marketing pages (home, pricing, blog) to a server-rendered framework."
|
|
240
|
+
: "Add a few server-rendered paragraphs: who the product is for, the problem it solves, how it works, pricing, and 3-5 FAQs.",
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
else if (wordCount < 200) {
|
|
244
|
+
add({
|
|
245
|
+
id: "thin-content",
|
|
246
|
+
severity: "info",
|
|
247
|
+
category: "on-page",
|
|
248
|
+
title: "Thin page content",
|
|
249
|
+
detail: `The page has ${wordCount} words in its HTML. Pages that explain who it is for, what it does and how it compares get cited more often.`,
|
|
250
|
+
fix: "Add a short, server-rendered section that explains who the product is for, the problem it solves, and 3-5 FAQs in plain language.",
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
else
|
|
254
|
+
pass("content", "on-page", `Server-rendered content (${wordCount} words)`);
|
|
255
|
+
if (!canonical) {
|
|
256
|
+
add({
|
|
257
|
+
id: "no-canonical",
|
|
258
|
+
severity: "warning",
|
|
259
|
+
category: "indexing",
|
|
260
|
+
title: "No canonical URL",
|
|
261
|
+
detail: "Without a canonical tag, search engines may split ranking between www/non-www, trailing slashes and query-string variants.",
|
|
262
|
+
fix: "Set `metadataBase` in the root layout and `alternates: { canonical: '/' }` (per page: its own path) in Next.js metadata.",
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
try {
|
|
267
|
+
const c = new URL(canonical, finalUrl);
|
|
268
|
+
if (c.host !== finalUrl.host && !opts.preview) {
|
|
269
|
+
add({
|
|
270
|
+
id: "canonical-host",
|
|
271
|
+
severity: "warning",
|
|
272
|
+
category: "indexing",
|
|
273
|
+
title: "Canonical points at a different host",
|
|
274
|
+
detail: `Canonical is ${c.href} but the page is served from ${finalUrl.host}.`,
|
|
275
|
+
fix: "Make `metadataBase` match the production domain exactly (including www or not), and redirect the other variant to it.",
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
else
|
|
279
|
+
pass("canonical", "indexing", "Canonical URL set");
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
pass("canonical", "indexing", "Canonical URL set");
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
// ---------- On-page ----------
|
|
286
|
+
if (!title) {
|
|
287
|
+
add({
|
|
288
|
+
id: "no-title",
|
|
289
|
+
severity: "critical",
|
|
290
|
+
category: "on-page",
|
|
291
|
+
title: "Missing page title",
|
|
292
|
+
detail: "The <title> tag is the headline in search results and AI citations.",
|
|
293
|
+
fix: "Set `metadata.title` (use a template like `{ default: 'Product: one-line value prop', template: '%s | Product' }`) in the root layout and a specific title on every page.",
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
else if (title.length < 10 || title.length > 70) {
|
|
297
|
+
add({
|
|
298
|
+
id: "title-length",
|
|
299
|
+
// Too short hurts (no keywords); too long only gets truncated in results.
|
|
300
|
+
severity: title.length < 10 ? "warning" : "info",
|
|
301
|
+
category: "on-page",
|
|
302
|
+
title: title.length < 10 ? "Page title is too short" : "Page title is too long",
|
|
303
|
+
detail: `"${title}" is ${title.length} characters. Aim for 30-60 so it is descriptive and not cut off.`,
|
|
304
|
+
fix: "Rewrite the title as 'Product: what it does for whom', 30-60 characters.",
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
else
|
|
308
|
+
pass("title", "on-page", "Good page title");
|
|
309
|
+
if (!description) {
|
|
310
|
+
add({
|
|
311
|
+
id: "no-description",
|
|
312
|
+
severity: "warning",
|
|
313
|
+
category: "on-page",
|
|
314
|
+
title: "Missing meta description",
|
|
315
|
+
detail: "Search engines show this under your title; AI tools often use it to summarize the page.",
|
|
316
|
+
fix: "Add `metadata.description`: one or two sentences (120-160 characters) saying what the product does and for whom.",
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
else if (description.length < 50 || description.length > 170) {
|
|
320
|
+
add({
|
|
321
|
+
id: "description-length",
|
|
322
|
+
severity: "info",
|
|
323
|
+
category: "on-page",
|
|
324
|
+
title: "Meta description length is off",
|
|
325
|
+
detail: `It is ${description.length} characters. Aim for 120-160.`,
|
|
326
|
+
fix: "Rewrite the description to 120-160 characters, leading with the main benefit.",
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
else
|
|
330
|
+
pass("description", "on-page", "Good meta description");
|
|
331
|
+
if (h1.length === 0) {
|
|
332
|
+
add({
|
|
333
|
+
id: "no-h1",
|
|
334
|
+
severity: "warning",
|
|
335
|
+
category: "on-page",
|
|
336
|
+
title: "No H1 heading in the HTML",
|
|
337
|
+
detail: "Crawlers use the H1 to understand the main topic of the page.",
|
|
338
|
+
fix: "Give each page exactly one server-rendered <h1> that states what the page is about.",
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
else if (h1.length > 1) {
|
|
342
|
+
add({
|
|
343
|
+
id: "multiple-h1",
|
|
344
|
+
severity: "info",
|
|
345
|
+
category: "on-page",
|
|
346
|
+
title: "More than one H1",
|
|
347
|
+
detail: `Found ${h1.length} H1s: ${h1.slice(0, 3).map((h) => `"${h}"`).join(", ")}.`,
|
|
348
|
+
fix: "Keep one <h1> per page and turn the others into <h2>.",
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
else
|
|
352
|
+
pass("h1", "on-page", "One clear H1");
|
|
353
|
+
if (!lang) {
|
|
354
|
+
add({
|
|
355
|
+
id: "no-lang",
|
|
356
|
+
severity: "info",
|
|
357
|
+
category: "on-page",
|
|
358
|
+
title: "No language set on <html>",
|
|
359
|
+
detail: "The lang attribute helps search engines serve the page to the right audience.",
|
|
360
|
+
fix: 'Add `lang="en"` (or the right language) to the <html> element in the root layout.',
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
if (!viewport) {
|
|
364
|
+
add({
|
|
365
|
+
id: "no-viewport",
|
|
366
|
+
severity: "warning",
|
|
367
|
+
category: "on-page",
|
|
368
|
+
title: "No mobile viewport tag",
|
|
369
|
+
detail: "Google indexes the mobile version of pages first.",
|
|
370
|
+
fix: "Add a viewport meta tag (Next.js adds one by default; check it was not removed).",
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
if (imagesMissingAlt > 0) {
|
|
374
|
+
add({
|
|
375
|
+
id: "img-alt",
|
|
376
|
+
severity: "info",
|
|
377
|
+
category: "on-page",
|
|
378
|
+
title: "Images without alt text",
|
|
379
|
+
detail: `${imagesMissingAlt} of ${images.length} images have no alt attribute.`,
|
|
380
|
+
fix: 'Add descriptive `alt` text to meaningful images and `alt=""` to decorative ones.',
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
// ---------- Social ----------
|
|
384
|
+
const missingOg = [!ogTitle && "og:title", !ogDescription && "og:description", !ogImage && "og:image"].filter(Boolean);
|
|
385
|
+
if (missingOg.length) {
|
|
386
|
+
add({
|
|
387
|
+
id: "open-graph",
|
|
388
|
+
severity: "warning",
|
|
389
|
+
category: "social",
|
|
390
|
+
title: "Link previews are incomplete",
|
|
391
|
+
detail: `Missing ${missingOg.join(", ")}. Links shared on X, LinkedIn, Slack and iMessage will look bare.`,
|
|
392
|
+
fix: "Add `openGraph: { title, description, images }` to the root metadata, and an `app/opengraph-image.tsx` (1200x630) so every page gets a preview image.",
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
else
|
|
396
|
+
pass("open-graph", "social", "Open Graph tags present");
|
|
397
|
+
if (!twitterCard) {
|
|
398
|
+
add({
|
|
399
|
+
id: "twitter-card",
|
|
400
|
+
severity: "info",
|
|
401
|
+
category: "social",
|
|
402
|
+
title: "No Twitter/X card type",
|
|
403
|
+
detail: "Without twitter:card, X shows a small preview.",
|
|
404
|
+
fix: "Add `twitter: { card: 'summary_large_image' }` to the root metadata.",
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
// ---------- Structured data ----------
|
|
408
|
+
if (jsonLdInvalid > 0) {
|
|
409
|
+
add({
|
|
410
|
+
id: "jsonld-invalid",
|
|
411
|
+
severity: "warning",
|
|
412
|
+
category: "ai-search",
|
|
413
|
+
title: "Structured data has JSON errors",
|
|
414
|
+
detail: `${jsonLdInvalid} JSON-LD block(s) could not be parsed, so search engines ignore them.`,
|
|
415
|
+
fix: "Generate JSON-LD with JSON.stringify (or gotmarJsonLd from @gotmar/next) instead of hand-written strings.",
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
if (jsonLdTypes.size === 0) {
|
|
419
|
+
add({
|
|
420
|
+
id: "no-jsonld",
|
|
421
|
+
severity: "warning",
|
|
422
|
+
category: "ai-search",
|
|
423
|
+
title: "No structured data",
|
|
424
|
+
detail: "JSON-LD tells search engines and AI tools exactly what the product is, who makes it and what it costs.",
|
|
425
|
+
fix: "Add JSON-LD to the homepage: `Organization` + `WebSite`, and `SoftwareApplication` (name, description, applicationCategory, offers) for the product. Add `FAQPage` where there is an FAQ and `Article` on blog posts.",
|
|
426
|
+
humanStep: { label: "Check it with Google's Rich Results Test", url: LINKS.richResults },
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
else
|
|
430
|
+
pass("jsonld", "ai-search", `Structured data: ${[...jsonLdTypes].join(", ")}`);
|
|
431
|
+
// ---------- robots.txt ----------
|
|
432
|
+
const robotsRes = await robotsPromise;
|
|
433
|
+
let robots = null;
|
|
434
|
+
const blocked = {};
|
|
435
|
+
if (robotsRes && robotsRes.status === 200 && !looksLikeHtml(robotsRes.text)) {
|
|
436
|
+
robots = parseRobots(robotsRes.text);
|
|
437
|
+
for (const bot of [...SEARCH_BOTS, ...AI_SEARCH_BOTS, ...AI_TRAINING_BOTS]) {
|
|
438
|
+
blocked[bot] = !isAllowed(robots, bot, "/");
|
|
439
|
+
}
|
|
440
|
+
const blockedSearch = SEARCH_BOTS.filter((b) => blocked[b]);
|
|
441
|
+
const blockedAiSearch = AI_SEARCH_BOTS.filter((b) => blocked[b]);
|
|
442
|
+
const blockedTraining = AI_TRAINING_BOTS.filter((b) => blocked[b]);
|
|
443
|
+
if (blockedSearch.length) {
|
|
444
|
+
add({
|
|
445
|
+
id: "robots-blocks-search",
|
|
446
|
+
severity: "critical",
|
|
447
|
+
category: "indexing",
|
|
448
|
+
title: "robots.txt blocks search engines",
|
|
449
|
+
detail: `${blockedSearch.join(" and ")} cannot crawl the homepage.`,
|
|
450
|
+
fix: "Change robots.txt so `User-agent: *` allows `/`. Only disallow private paths like /api, /dashboard, /admin.",
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
else
|
|
454
|
+
pass("robots-search", "indexing", "Search engines are allowed");
|
|
455
|
+
if (blockedAiSearch.length) {
|
|
456
|
+
add({
|
|
457
|
+
id: "robots-blocks-ai-search",
|
|
458
|
+
severity: "warning",
|
|
459
|
+
category: "ai-search",
|
|
460
|
+
title: "robots.txt blocks AI search",
|
|
461
|
+
detail: `${blockedAiSearch.join(", ")} are blocked, so ChatGPT, Claude or Perplexity cannot read or cite the site when answering questions.`,
|
|
462
|
+
fix: `Allow these user agents in robots.txt: ${blockedAiSearch.join(", ")}. With @gotmar/next use gotmarRobots(), which allows AI search crawlers by default.`,
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
else
|
|
466
|
+
pass("robots-ai-search", "ai-search", "AI search crawlers are allowed");
|
|
467
|
+
if (blockedTraining.length) {
|
|
468
|
+
add({
|
|
469
|
+
id: "robots-blocks-ai-training",
|
|
470
|
+
severity: "info",
|
|
471
|
+
category: "ai-search",
|
|
472
|
+
title: "AI training crawlers are blocked",
|
|
473
|
+
detail: `${blockedTraining.join(", ")} are blocked. That is a valid choice, but models will know less about the product.`,
|
|
474
|
+
fix: "Only change this if the owner wants the product to be part of AI training data. Ask the human before changing.",
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
add({
|
|
480
|
+
id: "no-robots",
|
|
481
|
+
severity: "warning",
|
|
482
|
+
category: "indexing",
|
|
483
|
+
title: "No robots.txt",
|
|
484
|
+
detail: `${origin}/robots.txt is missing${robotsRes?.status === 200 ? " (the server returned an HTML page instead)" : ""}.`,
|
|
485
|
+
fix: "Add `app/robots.ts` (Next.js) that allows all crawlers, disallows private paths, and points to the sitemap. @gotmar/next: `export default function robots() { return gotmarRobots({ baseUrl }) }`.",
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
// ---------- Sitemap ----------
|
|
489
|
+
// On a preview deployment, the sitemap and robots.txt point at production: read the preview's copies.
|
|
490
|
+
const local = (u) => {
|
|
491
|
+
if (!opts.preview)
|
|
492
|
+
return u;
|
|
493
|
+
try {
|
|
494
|
+
const parsed = new URL(u);
|
|
495
|
+
return origin + parsed.pathname + parsed.search;
|
|
496
|
+
}
|
|
497
|
+
catch {
|
|
498
|
+
return u;
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
const sitemapCandidates = (robots?.sitemaps.length ? robots.sitemaps : [`${origin}/sitemap.xml`]).map(local);
|
|
502
|
+
let sitemapFacts = { found: false, url: null, urlCount: 0 };
|
|
503
|
+
const sitemapUrls = [];
|
|
504
|
+
for (const candidate of sitemapCandidates.slice(0, 2)) {
|
|
505
|
+
const res = await get(candidate, opts);
|
|
506
|
+
if (!res || res.status !== 200 || !/<(urlset|sitemapindex)[\s>]/i.test(res.text))
|
|
507
|
+
continue;
|
|
508
|
+
let count = 0;
|
|
509
|
+
const hosts = new Set();
|
|
510
|
+
const locs = [...res.text.matchAll(/<loc>\s*([^<\s]+)\s*<\/loc>/gi)].map((m) => m[1]);
|
|
511
|
+
const collect = (loc) => {
|
|
512
|
+
count++;
|
|
513
|
+
if (sitemapUrls.length < 2000)
|
|
514
|
+
sitemapUrls.push(loc);
|
|
515
|
+
try {
|
|
516
|
+
hosts.add(new URL(loc).host);
|
|
517
|
+
}
|
|
518
|
+
catch { }
|
|
519
|
+
};
|
|
520
|
+
if (/<sitemapindex[\s>]/i.test(res.text)) {
|
|
521
|
+
for (const child of locs.slice(0, 3)) {
|
|
522
|
+
const c = await get(local(child), opts);
|
|
523
|
+
if (!c || c.status !== 200)
|
|
524
|
+
continue;
|
|
525
|
+
for (const m of c.text.matchAll(/<loc>\s*([^<\s]+)\s*<\/loc>/gi))
|
|
526
|
+
collect(m[1]);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
locs.forEach(collect);
|
|
531
|
+
}
|
|
532
|
+
if (opts.preview)
|
|
533
|
+
hosts.clear();
|
|
534
|
+
sitemapFacts = { found: true, url: candidate, urlCount: count };
|
|
535
|
+
if (count === 0) {
|
|
536
|
+
add({
|
|
537
|
+
id: "sitemap-empty",
|
|
538
|
+
severity: "warning",
|
|
539
|
+
category: "indexing",
|
|
540
|
+
title: "Sitemap has no URLs",
|
|
541
|
+
detail: `${candidate} exists but lists no pages.`,
|
|
542
|
+
fix: "List every public page (home, pricing, features, blog posts) in `app/sitemap.ts`.",
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
else if ([...hosts].some((h) => h !== finalUrl.host)) {
|
|
546
|
+
add({
|
|
547
|
+
id: "sitemap-host",
|
|
548
|
+
severity: "warning",
|
|
549
|
+
category: "indexing",
|
|
550
|
+
title: "Sitemap URLs use a different host",
|
|
551
|
+
detail: `Sitemap lists ${[...hosts].join(", ")} but the site is served from ${finalUrl.host}.`,
|
|
552
|
+
fix: "Build sitemap URLs from the production domain (the same value as `metadataBase`).",
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
else
|
|
556
|
+
pass("sitemap", "indexing", `Sitemap with ${count} URL${count === 1 ? "" : "s"}`);
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
if (!sitemapFacts.found) {
|
|
560
|
+
add({
|
|
561
|
+
id: "no-sitemap",
|
|
562
|
+
severity: "warning",
|
|
563
|
+
category: "indexing",
|
|
564
|
+
title: "No sitemap",
|
|
565
|
+
detail: "A sitemap is how search engines discover every page, including new blog posts.",
|
|
566
|
+
fix: "Add `app/sitemap.ts` listing all public pages (with @gotmar/next: `gotmarSitemap({ baseUrl, routes })`) and reference it from robots.txt.",
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
else if (robots && robots.sitemaps.length === 0) {
|
|
570
|
+
add({
|
|
571
|
+
id: "robots-no-sitemap",
|
|
572
|
+
severity: "info",
|
|
573
|
+
category: "indexing",
|
|
574
|
+
title: "robots.txt does not point to the sitemap",
|
|
575
|
+
detail: "Crawlers look for a `Sitemap:` line in robots.txt.",
|
|
576
|
+
fix: "Add a `sitemap` field (the absolute URL of /sitemap.xml) to the object returned by app/robots.ts.",
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
// ---------- llms.txt ----------
|
|
580
|
+
const llmsRes = await llmsPromise;
|
|
581
|
+
const llmsFound = !!llmsRes && llmsRes.status === 200 && llmsRes.text.trim().length > 0 && !looksLikeHtml(llmsRes.text);
|
|
582
|
+
if (!llmsFound) {
|
|
583
|
+
add({
|
|
584
|
+
id: "no-llms-txt",
|
|
585
|
+
severity: "warning",
|
|
586
|
+
category: "ai-search",
|
|
587
|
+
title: "No llms.txt",
|
|
588
|
+
detail: "llms.txt is a short Markdown summary of the site for AI tools and agents: what it is, who it is for, and the key pages.",
|
|
589
|
+
fix: "Add `app/llms.txt/route.ts` returning Markdown: `# Product`, a `> one-line summary`, then sections of links to key pages. With @gotmar/next: `export const GET = gotmarLlmsTxt({...})`.",
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
else
|
|
593
|
+
pass("llms-txt", "ai-search", "llms.txt present");
|
|
594
|
+
// ---------- Verification (only the human can finish this) ----------
|
|
595
|
+
if (!googleVerification) {
|
|
596
|
+
add({
|
|
597
|
+
id: "search-console",
|
|
598
|
+
severity: "info",
|
|
599
|
+
category: "indexing",
|
|
600
|
+
title: "No Google Search Console verification tag found",
|
|
601
|
+
detail: "Search Console is where Google reports indexing problems and the searches people use to find the site. (Ignore this if it is already verified by DNS.)",
|
|
602
|
+
fix: "Ask the human to add the site in Search Console using the 'HTML tag' method and paste the code. Put it in the root layout as `metadata.verification.google`. After deploying, the human clicks Verify and submits `/sitemap.xml`.",
|
|
603
|
+
humanStep: { label: "Open Google Search Console", url: LINKS.searchConsole },
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
else
|
|
607
|
+
pass("search-console", "indexing", "Google Search Console verification tag present");
|
|
608
|
+
if (!bingVerification) {
|
|
609
|
+
add({
|
|
610
|
+
id: "bing-webmaster",
|
|
611
|
+
severity: "info",
|
|
612
|
+
category: "ai-search",
|
|
613
|
+
title: "Not connected to Bing Webmaster Tools",
|
|
614
|
+
detail: "Bing's index feeds Copilot and is used by ChatGPT search. Bing can import a verified site straight from Search Console. (Ignore this if already verified another way.)",
|
|
615
|
+
fix: "Ask the human to sign in to Bing Webmaster Tools and choose 'Import from Google Search Console'. No code change needed.",
|
|
616
|
+
humanStep: { label: "Open Bing Webmaster Tools", url: LINKS.bingWebmaster },
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
// ---------- Performance ----------
|
|
620
|
+
if (page.ms > 2500) {
|
|
621
|
+
add({
|
|
622
|
+
id: "slow",
|
|
623
|
+
severity: "warning",
|
|
624
|
+
category: "performance",
|
|
625
|
+
title: "Slow server response",
|
|
626
|
+
detail: `The HTML took ${page.ms} ms to arrive.`,
|
|
627
|
+
fix: "Make public pages static or cached (avoid per-request data fetching on marketing pages; use `export const revalidate`).",
|
|
628
|
+
humanStep: { label: "Check Core Web Vitals in PageSpeed Insights", url: LINKS.pageSpeed },
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
else
|
|
632
|
+
pass("speed", "performance", `HTML in ${page.ms} ms`);
|
|
633
|
+
// ---------- Whole-site crawl ----------
|
|
634
|
+
let pagesCrawled = 0;
|
|
635
|
+
if ((opts.maxPages ?? 0) > 0 && sitemapUrls.length) {
|
|
636
|
+
const crawl = await crawlSite({
|
|
637
|
+
origin,
|
|
638
|
+
homePath: finalUrl.pathname,
|
|
639
|
+
sitemapUrls,
|
|
640
|
+
maxPages: opts.maxPages,
|
|
641
|
+
preview: !!opts.preview,
|
|
642
|
+
fetchPage: (u) => get(u, opts),
|
|
643
|
+
});
|
|
644
|
+
crawl.issues.forEach(add);
|
|
645
|
+
crawl.passed.forEach((p) => passed.push(p));
|
|
646
|
+
pagesCrawled = crawl.pagesCrawled;
|
|
647
|
+
}
|
|
648
|
+
const facts = {
|
|
649
|
+
title,
|
|
650
|
+
description,
|
|
651
|
+
canonical,
|
|
652
|
+
lang,
|
|
653
|
+
h1,
|
|
654
|
+
wordCount,
|
|
655
|
+
jsonLdTypes: [...jsonLdTypes],
|
|
656
|
+
ogImage,
|
|
657
|
+
imagesTotal: images.length,
|
|
658
|
+
imagesMissingAlt,
|
|
659
|
+
googleVerification,
|
|
660
|
+
bingVerification,
|
|
661
|
+
robotsTxt: { found: !!robots, sitemaps: robots?.sitemaps ?? [], blocked },
|
|
662
|
+
sitemap: sitemapFacts,
|
|
663
|
+
llmsTxt: { found: llmsFound, bytes: llmsFound ? llmsRes.text.length : 0 },
|
|
664
|
+
pagesCrawled,
|
|
665
|
+
};
|
|
666
|
+
return finish(page, facts);
|
|
667
|
+
}
|
|
668
|
+
/** Turns a report into a prompt the user can paste into their coding agent. */
|
|
669
|
+
export function toAgentPrompt(report) {
|
|
670
|
+
const lines = [];
|
|
671
|
+
lines.push(`# Gotmar audit: ${report.finalUrl}`);
|
|
672
|
+
lines.push("");
|
|
673
|
+
lines.push(`Score ${report.score}/100 (grade ${report.grade}). Gotmar fetched the raw HTML without running JavaScript, which is what search and AI crawlers see.`);
|
|
674
|
+
lines.push("");
|
|
675
|
+
if (report.issues.length === 0) {
|
|
676
|
+
lines.push("No issues found. Nothing to fix.");
|
|
677
|
+
return lines.join("\n");
|
|
678
|
+
}
|
|
679
|
+
lines.push("Fix these in order. If GOTMAR.md exists in this repo, follow its conventions. Skip anything marked as a human step and tell the human about it instead.");
|
|
680
|
+
lines.push("");
|
|
681
|
+
report.issues.forEach((issue, i) => {
|
|
682
|
+
lines.push(`${i + 1}. **[${issue.severity}] ${issue.title}** (${issue.category})`);
|
|
683
|
+
lines.push(` Found: ${issue.detail}`);
|
|
684
|
+
lines.push(` Fix: ${issue.fix}`);
|
|
685
|
+
});
|
|
686
|
+
const human = report.issues.filter((i) => i.humanStep);
|
|
687
|
+
if (human.length) {
|
|
688
|
+
lines.push("");
|
|
689
|
+
lines.push("## Steps only the human can do (give them these links)");
|
|
690
|
+
for (const i of human)
|
|
691
|
+
lines.push(`- ${i.humanStep.label}: ${i.humanStep.url}`);
|
|
692
|
+
}
|
|
693
|
+
lines.push("");
|
|
694
|
+
lines.push(`After deploying the fixes, re-run: npx gotmar audit ${report.finalUrl}`);
|
|
695
|
+
return lines.join("\n");
|
|
696
|
+
}
|