lintpage 0.1.1 → 0.1.2
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/cli.js +2624 -14
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2618 -12
- package/dist/cli.mjs.map +1 -1
- package/package.json +6 -4
package/dist/cli.mjs
CHANGED
|
@@ -1,12 +1,2618 @@
|
|
|
1
1
|
// src/cli.ts
|
|
2
2
|
import cac from "cac";
|
|
3
3
|
import chalk2 from "chalk";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "
|
|
9
|
-
|
|
4
|
+
|
|
5
|
+
// ../core/dist/index.mjs
|
|
6
|
+
import { JSDOM } from "jsdom";
|
|
7
|
+
import { readFileSync, existsSync } from "fs";
|
|
8
|
+
import { join } from "path";
|
|
9
|
+
var titleRule = {
|
|
10
|
+
meta: {
|
|
11
|
+
id: "title",
|
|
12
|
+
name: "Page Title",
|
|
13
|
+
category: "SEO",
|
|
14
|
+
tier: "free",
|
|
15
|
+
description: "Checks for the presence and length of the <title> tag"
|
|
16
|
+
},
|
|
17
|
+
run(context) {
|
|
18
|
+
const { document } = context;
|
|
19
|
+
const results = [];
|
|
20
|
+
const titleElement = document.querySelector("title");
|
|
21
|
+
const value = titleElement?.textContent?.trim() || "";
|
|
22
|
+
const length = value.length;
|
|
23
|
+
if (!value) {
|
|
24
|
+
results.push({
|
|
25
|
+
ruleId: "title",
|
|
26
|
+
ruleName: "Page Title",
|
|
27
|
+
message: "Missing title tag",
|
|
28
|
+
severity: "WARNING",
|
|
29
|
+
category: "SEO",
|
|
30
|
+
tier: "free",
|
|
31
|
+
fix: "Add a <title>Your Page Title</title> tag inside your <head> element. Keep it 50-60 characters.",
|
|
32
|
+
data: { value, length }
|
|
33
|
+
});
|
|
34
|
+
} else if (length < 30) {
|
|
35
|
+
results.push({
|
|
36
|
+
ruleId: "title",
|
|
37
|
+
ruleName: "Page Title",
|
|
38
|
+
message: "Title is too short (recommended: 50-60 characters)",
|
|
39
|
+
severity: "WARNING",
|
|
40
|
+
category: "SEO",
|
|
41
|
+
tier: "free",
|
|
42
|
+
fix: "Expand your title to 50-60 characters. Include your primary keyword and make it compelling for click-through.",
|
|
43
|
+
data: { value, length }
|
|
44
|
+
});
|
|
45
|
+
} else if (length > 60) {
|
|
46
|
+
results.push({
|
|
47
|
+
ruleId: "title",
|
|
48
|
+
ruleName: "Page Title",
|
|
49
|
+
message: "Title is too long (recommended: 50-60 characters)",
|
|
50
|
+
severity: "WARNING",
|
|
51
|
+
category: "SEO",
|
|
52
|
+
tier: "free",
|
|
53
|
+
fix: "Shorten your title to under 60 characters to prevent truncation in search results.",
|
|
54
|
+
data: { value, length }
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return results;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var metaDescriptionRule = {
|
|
61
|
+
meta: {
|
|
62
|
+
id: "meta-description",
|
|
63
|
+
name: "Meta Description",
|
|
64
|
+
category: "SEO",
|
|
65
|
+
tier: "free",
|
|
66
|
+
description: "Checks for the presence and length of the meta description tag"
|
|
67
|
+
},
|
|
68
|
+
run(context) {
|
|
69
|
+
const { document } = context;
|
|
70
|
+
const results = [];
|
|
71
|
+
const metaDesc = document.querySelector('meta[name="description"]');
|
|
72
|
+
const value = metaDesc?.getAttribute("content")?.trim() || "";
|
|
73
|
+
const length = value.length;
|
|
74
|
+
if (!value) {
|
|
75
|
+
results.push({
|
|
76
|
+
ruleId: "meta-description",
|
|
77
|
+
ruleName: "Meta Description",
|
|
78
|
+
message: "Missing meta description",
|
|
79
|
+
severity: "WARNING",
|
|
80
|
+
category: "SEO",
|
|
81
|
+
tier: "free",
|
|
82
|
+
fix: 'Add <meta name="description" content="Your description here" /> to your <head> tag. Aim for 150-160 characters.',
|
|
83
|
+
data: { value, length }
|
|
84
|
+
});
|
|
85
|
+
} else if (length < 120) {
|
|
86
|
+
results.push({
|
|
87
|
+
ruleId: "meta-description",
|
|
88
|
+
ruleName: "Meta Description",
|
|
89
|
+
message: "Meta description is too short (recommended: 150-160 characters)",
|
|
90
|
+
severity: "WARNING",
|
|
91
|
+
category: "SEO",
|
|
92
|
+
tier: "free",
|
|
93
|
+
fix: "Expand your meta description to 150-160 characters. Include a compelling summary with your target keyword.",
|
|
94
|
+
data: { value, length }
|
|
95
|
+
});
|
|
96
|
+
} else if (length > 160) {
|
|
97
|
+
results.push({
|
|
98
|
+
ruleId: "meta-description",
|
|
99
|
+
ruleName: "Meta Description",
|
|
100
|
+
message: "Meta description is too long (recommended: 150-160 characters)",
|
|
101
|
+
severity: "WARNING",
|
|
102
|
+
category: "SEO",
|
|
103
|
+
tier: "free",
|
|
104
|
+
fix: "Shorten your meta description to under 160 characters to prevent truncation in search results.",
|
|
105
|
+
data: { value, length }
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return results;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
var ogTitleRule = {
|
|
112
|
+
meta: {
|
|
113
|
+
id: "og-title",
|
|
114
|
+
name: "Open Graph Title",
|
|
115
|
+
category: "SEO",
|
|
116
|
+
tier: "free",
|
|
117
|
+
description: "Checks for the og:title meta tag"
|
|
118
|
+
},
|
|
119
|
+
run(context) {
|
|
120
|
+
const { document } = context;
|
|
121
|
+
const results = [];
|
|
122
|
+
const ogTitle = document.querySelector('meta[property="og:title"]');
|
|
123
|
+
if (!ogTitle?.getAttribute("content")) {
|
|
124
|
+
results.push({
|
|
125
|
+
ruleId: "og-title",
|
|
126
|
+
ruleName: "Open Graph Title",
|
|
127
|
+
message: "Missing og:title tag - social media shares will have no title preview",
|
|
128
|
+
severity: "WARNING",
|
|
129
|
+
category: "SEO",
|
|
130
|
+
tier: "free",
|
|
131
|
+
fix: 'Add <meta property="og:title" content="Your Page Title" /> to your <head> tag.'
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
return results;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
var ogDescriptionRule = {
|
|
138
|
+
meta: {
|
|
139
|
+
id: "og-description",
|
|
140
|
+
name: "Open Graph Description",
|
|
141
|
+
category: "SEO",
|
|
142
|
+
tier: "free",
|
|
143
|
+
description: "Checks for the og:description meta tag"
|
|
144
|
+
},
|
|
145
|
+
run(context) {
|
|
146
|
+
const { document } = context;
|
|
147
|
+
const results = [];
|
|
148
|
+
const ogDesc = document.querySelector('meta[property="og:description"]');
|
|
149
|
+
if (!ogDesc?.getAttribute("content")) {
|
|
150
|
+
results.push({
|
|
151
|
+
ruleId: "og-description",
|
|
152
|
+
ruleName: "Open Graph Description",
|
|
153
|
+
message: "Missing og:description tag - social media shares will have no description preview",
|
|
154
|
+
severity: "WARNING",
|
|
155
|
+
category: "SEO",
|
|
156
|
+
tier: "free",
|
|
157
|
+
fix: 'Add <meta property="og:description" content="Your description" /> to your <head> tag.'
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return results;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
var ogImageRule = {
|
|
164
|
+
meta: {
|
|
165
|
+
id: "og-image",
|
|
166
|
+
name: "Open Graph Image",
|
|
167
|
+
category: "SEO",
|
|
168
|
+
tier: "free",
|
|
169
|
+
description: "Checks for the og:image meta tag"
|
|
170
|
+
},
|
|
171
|
+
run(context) {
|
|
172
|
+
const { document } = context;
|
|
173
|
+
const results = [];
|
|
174
|
+
const ogImage = document.querySelector('meta[property="og:image"]');
|
|
175
|
+
if (!ogImage?.getAttribute("content")) {
|
|
176
|
+
results.push({
|
|
177
|
+
ruleId: "og-image",
|
|
178
|
+
ruleName: "Open Graph Image",
|
|
179
|
+
message: "Missing og:image tag - social media shares will have no image preview",
|
|
180
|
+
severity: "WARNING",
|
|
181
|
+
category: "SEO",
|
|
182
|
+
tier: "free",
|
|
183
|
+
fix: 'Add <meta property="og:image" content="https://yoursite.com/image.jpg" /> to your <head> tag.'
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return results;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
var ogUrlRule = {
|
|
190
|
+
meta: {
|
|
191
|
+
id: "og-url",
|
|
192
|
+
name: "Open Graph URL",
|
|
193
|
+
category: "SEO",
|
|
194
|
+
tier: "free",
|
|
195
|
+
description: "Checks for the og:url meta tag"
|
|
196
|
+
},
|
|
197
|
+
run(context) {
|
|
198
|
+
const { document } = context;
|
|
199
|
+
const results = [];
|
|
200
|
+
const ogUrl = document.querySelector('meta[property="og:url"]');
|
|
201
|
+
if (!ogUrl?.getAttribute("content")) {
|
|
202
|
+
results.push({
|
|
203
|
+
ruleId: "og-url",
|
|
204
|
+
ruleName: "Open Graph URL",
|
|
205
|
+
message: "Missing og:url tag - social media may not show the correct URL",
|
|
206
|
+
severity: "WARNING",
|
|
207
|
+
category: "SEO",
|
|
208
|
+
tier: "free",
|
|
209
|
+
fix: 'Add <meta property="og:url" content="https://yoursite.com/page" /> to your <head> tag.'
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
return results;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
var twitterCardRule = {
|
|
216
|
+
meta: {
|
|
217
|
+
id: "twitter-card",
|
|
218
|
+
name: "Twitter Card",
|
|
219
|
+
category: "SEO",
|
|
220
|
+
tier: "free",
|
|
221
|
+
description: "Checks for Twitter Card meta tags"
|
|
222
|
+
},
|
|
223
|
+
run(context) {
|
|
224
|
+
const { document } = context;
|
|
225
|
+
const results = [];
|
|
226
|
+
const twitterCard = document.querySelector('meta[name="twitter:card"]');
|
|
227
|
+
if (!twitterCard?.getAttribute("content")) {
|
|
228
|
+
results.push({
|
|
229
|
+
ruleId: "twitter-card",
|
|
230
|
+
ruleName: "Twitter Card",
|
|
231
|
+
message: "Missing Twitter Card tags - tweets with your URL will have no preview card",
|
|
232
|
+
severity: "WARNING",
|
|
233
|
+
category: "SEO",
|
|
234
|
+
tier: "free",
|
|
235
|
+
fix: 'Add <meta name="twitter:card" content="summary_large_image" />, <meta name="twitter:title" content="..." />, and <meta name="twitter:image" content="..." /> to your <head>.'
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
return results;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
var canonicalUrlRule = {
|
|
242
|
+
meta: {
|
|
243
|
+
id: "canonical-url",
|
|
244
|
+
name: "Canonical URL",
|
|
245
|
+
category: "SEO",
|
|
246
|
+
tier: "free",
|
|
247
|
+
description: "Checks for a canonical link tag and validates the URL"
|
|
248
|
+
},
|
|
249
|
+
run(context) {
|
|
250
|
+
const { document } = context;
|
|
251
|
+
const results = [];
|
|
252
|
+
const canonical = document.querySelector('link[rel="canonical"]');
|
|
253
|
+
const value = canonical?.getAttribute("href") || void 0;
|
|
254
|
+
if (!canonical) {
|
|
255
|
+
results.push({
|
|
256
|
+
ruleId: "canonical-url",
|
|
257
|
+
ruleName: "Canonical URL",
|
|
258
|
+
message: "No canonical link found (recommended for SEO)",
|
|
259
|
+
severity: "INFO",
|
|
260
|
+
category: "SEO",
|
|
261
|
+
tier: "free",
|
|
262
|
+
fix: 'Add <link rel="canonical" href="https://yoursite.com/this-page" /> to your <head> tag to prevent duplicate content issues.',
|
|
263
|
+
data: { present: false }
|
|
264
|
+
});
|
|
265
|
+
} else if (value && !value.startsWith("http")) {
|
|
266
|
+
results.push({
|
|
267
|
+
ruleId: "canonical-url",
|
|
268
|
+
ruleName: "Canonical URL",
|
|
269
|
+
message: "Canonical URL should be absolute (include protocol and domain)",
|
|
270
|
+
severity: "WARNING",
|
|
271
|
+
category: "SEO",
|
|
272
|
+
tier: "free",
|
|
273
|
+
fix: 'Change your canonical href to an absolute URL starting with https:// (e.g., href="https://yoursite.com/page").',
|
|
274
|
+
data: { present: true, value }
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
return results;
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
var robotsNoindexRule = {
|
|
281
|
+
meta: {
|
|
282
|
+
id: "robots-noindex",
|
|
283
|
+
name: "Robots Noindex",
|
|
284
|
+
category: "Pre-Launch",
|
|
285
|
+
tier: "free",
|
|
286
|
+
description: "Checks for noindex/nofollow in the robots meta tag"
|
|
287
|
+
},
|
|
288
|
+
run(context) {
|
|
289
|
+
const { document } = context;
|
|
290
|
+
const results = [];
|
|
291
|
+
const metaRobots = document.querySelector('meta[name="robots"]');
|
|
292
|
+
const content = metaRobots?.getAttribute("content") || "";
|
|
293
|
+
if (content.includes("noindex")) {
|
|
294
|
+
results.push({
|
|
295
|
+
ruleId: "robots-noindex",
|
|
296
|
+
ruleName: "Robots Noindex",
|
|
297
|
+
message: "Page has noindex meta tag - WILL NOT BE INDEXED by search engines! Remove this before launch or you'll get ZERO organic traffic.",
|
|
298
|
+
severity: "CRITICAL",
|
|
299
|
+
category: "Pre-Launch",
|
|
300
|
+
tier: "free",
|
|
301
|
+
fix: 'Remove the <meta name="robots" content="noindex" /> tag from your <head>, or change it to content="index, follow".',
|
|
302
|
+
data: { metaRobots: content }
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
if (content.includes("nofollow")) {
|
|
306
|
+
results.push({
|
|
307
|
+
ruleId: "robots-noindex",
|
|
308
|
+
ruleName: "Robots Noindex",
|
|
309
|
+
message: "Page has nofollow meta tag - links will not be followed",
|
|
310
|
+
severity: "WARNING",
|
|
311
|
+
category: "SEO",
|
|
312
|
+
tier: "free",
|
|
313
|
+
fix: 'Remove "nofollow" from your <meta name="robots"> content if you want search engines to follow your links.',
|
|
314
|
+
data: { metaRobots: content }
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
return results;
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
var headingStructureRule = {
|
|
321
|
+
meta: {
|
|
322
|
+
id: "heading-structure",
|
|
323
|
+
name: "Heading Structure",
|
|
324
|
+
category: "SEO",
|
|
325
|
+
tier: "free",
|
|
326
|
+
description: "Validates H1 tag presence, count, and heading hierarchy"
|
|
327
|
+
},
|
|
328
|
+
run(context) {
|
|
329
|
+
const { document } = context;
|
|
330
|
+
const results = [];
|
|
331
|
+
const h1Elements = document.querySelectorAll("h1");
|
|
332
|
+
const count = h1Elements.length;
|
|
333
|
+
const values = Array.from(h1Elements).map(
|
|
334
|
+
(h1) => h1.textContent?.trim() || ""
|
|
335
|
+
);
|
|
336
|
+
if (count === 0) {
|
|
337
|
+
results.push({
|
|
338
|
+
ruleId: "heading-structure",
|
|
339
|
+
ruleName: "Heading Structure",
|
|
340
|
+
message: "No H1 tag found",
|
|
341
|
+
severity: "WARNING",
|
|
342
|
+
category: "SEO",
|
|
343
|
+
tier: "free",
|
|
344
|
+
fix: "Add a single <h1> tag to your page with a clear, descriptive heading that includes your primary keyword.",
|
|
345
|
+
data: { h1Count: count }
|
|
346
|
+
});
|
|
347
|
+
} else if (count > 1) {
|
|
348
|
+
results.push({
|
|
349
|
+
ruleId: "heading-structure",
|
|
350
|
+
ruleName: "Heading Structure",
|
|
351
|
+
message: `Multiple H1 tags found (${count}). Recommended: 1 per page`,
|
|
352
|
+
severity: "WARNING",
|
|
353
|
+
category: "SEO",
|
|
354
|
+
tier: "free",
|
|
355
|
+
fix: "Keep only one <h1> tag per page. Use <h2>-<h6> for subheadings.",
|
|
356
|
+
data: { h1Count: count, h1Values: values }
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
values.forEach((value, index) => {
|
|
360
|
+
if (!value) {
|
|
361
|
+
results.push({
|
|
362
|
+
ruleId: "heading-structure",
|
|
363
|
+
ruleName: "Heading Structure",
|
|
364
|
+
message: `H1 #${index + 1} is empty`,
|
|
365
|
+
severity: "WARNING",
|
|
366
|
+
category: "SEO",
|
|
367
|
+
tier: "free",
|
|
368
|
+
fix: "Add descriptive text content to your <h1> tag."
|
|
369
|
+
});
|
|
370
|
+
} else if (value.length > 70) {
|
|
371
|
+
results.push({
|
|
372
|
+
ruleId: "heading-structure",
|
|
373
|
+
ruleName: "Heading Structure",
|
|
374
|
+
message: `H1 #${index + 1} is too long (${value.length} characters)`,
|
|
375
|
+
severity: "INFO",
|
|
376
|
+
category: "SEO",
|
|
377
|
+
tier: "free",
|
|
378
|
+
fix: "Shorten your H1 to under 70 characters for better readability and SEO."
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
const headings = document.querySelectorAll("h1, h2, h3, h4, h5, h6");
|
|
383
|
+
let lastLevel = 0;
|
|
384
|
+
Array.from(headings).forEach((heading) => {
|
|
385
|
+
const level = Number.parseInt(heading.tagName[1] ?? "1", 10);
|
|
386
|
+
if (level - lastLevel > 1) {
|
|
387
|
+
const text = heading.textContent?.trim().substring(0, 40) || "...";
|
|
388
|
+
results.push({
|
|
389
|
+
ruleId: "heading-structure",
|
|
390
|
+
ruleName: "Heading Structure",
|
|
391
|
+
message: `${heading.tagName} skips heading level from h${lastLevel} (content: "${text}")`,
|
|
392
|
+
severity: "INFO",
|
|
393
|
+
category: "SEO",
|
|
394
|
+
tier: "free",
|
|
395
|
+
fix: `Don't skip heading levels. Use h${lastLevel + 1} instead of ${heading.tagName} to maintain proper hierarchy.`
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
lastLevel = level;
|
|
399
|
+
});
|
|
400
|
+
return results;
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
var htmlLangRule = {
|
|
404
|
+
meta: {
|
|
405
|
+
id: "html-lang",
|
|
406
|
+
name: "HTML Lang Attribute",
|
|
407
|
+
category: "Accessibility",
|
|
408
|
+
tier: "free",
|
|
409
|
+
description: "Checks for the lang attribute on the <html> tag"
|
|
410
|
+
},
|
|
411
|
+
run(context) {
|
|
412
|
+
const { document } = context;
|
|
413
|
+
const results = [];
|
|
414
|
+
const html = document.documentElement;
|
|
415
|
+
const lang = html.getAttribute("lang");
|
|
416
|
+
if (!lang) {
|
|
417
|
+
results.push({
|
|
418
|
+
ruleId: "html-lang",
|
|
419
|
+
ruleName: "HTML Lang Attribute",
|
|
420
|
+
message: "Missing lang attribute on <html> tag",
|
|
421
|
+
severity: "WARNING",
|
|
422
|
+
category: "Accessibility",
|
|
423
|
+
tier: "free",
|
|
424
|
+
fix: 'Add lang="en" (or your language code) to your <html> tag: <html lang="en">.',
|
|
425
|
+
data: { present: false }
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
return results;
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
var viewportRule = {
|
|
432
|
+
meta: {
|
|
433
|
+
id: "viewport",
|
|
434
|
+
name: "Viewport Meta Tag",
|
|
435
|
+
category: "SEO",
|
|
436
|
+
tier: "free",
|
|
437
|
+
description: "Checks for the viewport meta tag for mobile responsiveness"
|
|
438
|
+
},
|
|
439
|
+
run(context) {
|
|
440
|
+
const { document } = context;
|
|
441
|
+
const results = [];
|
|
442
|
+
const viewport = document.querySelector('meta[name="viewport"]');
|
|
443
|
+
if (!viewport) {
|
|
444
|
+
results.push({
|
|
445
|
+
ruleId: "viewport",
|
|
446
|
+
ruleName: "Viewport Meta Tag",
|
|
447
|
+
message: "Missing viewport meta tag - page will not render properly on mobile devices",
|
|
448
|
+
severity: "WARNING",
|
|
449
|
+
category: "SEO",
|
|
450
|
+
tier: "free",
|
|
451
|
+
fix: 'Add <meta name="viewport" content="width=device-width, initial-scale=1" /> to your <head> tag.',
|
|
452
|
+
data: { present: false }
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
return results;
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
var faviconRule = {
|
|
459
|
+
meta: {
|
|
460
|
+
id: "favicon",
|
|
461
|
+
name: "Favicon",
|
|
462
|
+
category: "SEO",
|
|
463
|
+
tier: "free",
|
|
464
|
+
description: "Checks for the presence of a favicon link tag"
|
|
465
|
+
},
|
|
466
|
+
run(context) {
|
|
467
|
+
const { document } = context;
|
|
468
|
+
const results = [];
|
|
469
|
+
const favicon = document.querySelector('link[rel*="icon"]');
|
|
470
|
+
if (!favicon) {
|
|
471
|
+
results.push({
|
|
472
|
+
ruleId: "favicon",
|
|
473
|
+
ruleName: "Favicon",
|
|
474
|
+
message: "No favicon found - browsers will show a default icon in tabs and bookmarks",
|
|
475
|
+
severity: "WARNING",
|
|
476
|
+
category: "SEO",
|
|
477
|
+
tier: "free",
|
|
478
|
+
fix: 'Add <link rel="icon" href="/favicon.ico" /> to your <head> tag. Include multiple sizes for best results.',
|
|
479
|
+
data: { present: false }
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
return results;
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
var coreRules = [
|
|
486
|
+
titleRule,
|
|
487
|
+
metaDescriptionRule,
|
|
488
|
+
ogTitleRule,
|
|
489
|
+
ogDescriptionRule,
|
|
490
|
+
ogImageRule,
|
|
491
|
+
ogUrlRule,
|
|
492
|
+
twitterCardRule,
|
|
493
|
+
canonicalUrlRule,
|
|
494
|
+
robotsNoindexRule,
|
|
495
|
+
headingStructureRule,
|
|
496
|
+
htmlLangRule,
|
|
497
|
+
viewportRule,
|
|
498
|
+
faviconRule
|
|
499
|
+
];
|
|
500
|
+
var ruleRegistry = new Map(
|
|
501
|
+
coreRules.map((rule) => [rule.meta.id, rule])
|
|
502
|
+
);
|
|
503
|
+
async function fetchPage(url) {
|
|
504
|
+
const fetchStart = Date.now();
|
|
505
|
+
const response = await fetch(url, {
|
|
506
|
+
headers: {
|
|
507
|
+
"User-Agent": "LintPage-Bot/1.0"
|
|
508
|
+
},
|
|
509
|
+
signal: AbortSignal.timeout(3e4)
|
|
510
|
+
});
|
|
511
|
+
const ttfbMs = Date.now() - fetchStart;
|
|
512
|
+
if (!response.ok) {
|
|
513
|
+
throw new Error(
|
|
514
|
+
`Failed to fetch URL: ${response.status} ${response.statusText}`
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
const html = await response.text();
|
|
518
|
+
const dom = new JSDOM(html);
|
|
519
|
+
return {
|
|
520
|
+
document: dom.window.document,
|
|
521
|
+
response,
|
|
522
|
+
html,
|
|
523
|
+
ttfbMs
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
var CATEGORY_WEIGHTS = {
|
|
527
|
+
"Pre-Launch": 30,
|
|
528
|
+
SEO: 35,
|
|
529
|
+
Accessibility: 20,
|
|
530
|
+
Performance: 15
|
|
531
|
+
};
|
|
532
|
+
function calculateCategoryScores(results) {
|
|
533
|
+
const categoryIssues = {};
|
|
534
|
+
for (const category of Object.keys(CATEGORY_WEIGHTS)) {
|
|
535
|
+
categoryIssues[category] = { critical: 0, warning: 0, info: 0 };
|
|
536
|
+
}
|
|
537
|
+
for (const result of results) {
|
|
538
|
+
const cat = result.category;
|
|
539
|
+
if (!categoryIssues[cat]) {
|
|
540
|
+
categoryIssues[cat] = { critical: 0, warning: 0, info: 0 };
|
|
541
|
+
}
|
|
542
|
+
if (result.severity === "CRITICAL") categoryIssues[cat].critical++;
|
|
543
|
+
else if (result.severity === "WARNING") categoryIssues[cat].warning++;
|
|
544
|
+
else categoryIssues[cat].info++;
|
|
545
|
+
}
|
|
546
|
+
const scores = {};
|
|
547
|
+
for (const [category, weight] of Object.entries(CATEGORY_WEIGHTS)) {
|
|
548
|
+
const counts = categoryIssues[category] || {
|
|
549
|
+
critical: 0,
|
|
550
|
+
warning: 0,
|
|
551
|
+
info: 0
|
|
552
|
+
};
|
|
553
|
+
const deductionPercent = Math.min(
|
|
554
|
+
100,
|
|
555
|
+
counts.critical * 30 + counts.warning * 5 + counts.info * 1
|
|
556
|
+
);
|
|
557
|
+
scores[category] = {
|
|
558
|
+
score: Math.round(weight * (1 - deductionPercent / 100) * 10) / 10,
|
|
559
|
+
max: weight,
|
|
560
|
+
deductionPercent
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
return scores;
|
|
564
|
+
}
|
|
565
|
+
function runRules(rules, context, config) {
|
|
566
|
+
const results = [];
|
|
567
|
+
for (const rule of rules) {
|
|
568
|
+
if (config?.rules) {
|
|
569
|
+
const ruleConfig = config.rules[rule.meta.id];
|
|
570
|
+
if (ruleConfig === false) continue;
|
|
571
|
+
if (typeof ruleConfig === "object" && ruleConfig.enabled === false)
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
try {
|
|
575
|
+
const ruleResults = rule.run(context);
|
|
576
|
+
results.push(...ruleResults);
|
|
577
|
+
} catch (err) {
|
|
578
|
+
console.warn(
|
|
579
|
+
`[lintpage] Rule "${rule.meta.id}" threw an error: ${err instanceof Error ? err.message : String(err)}`
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
return results;
|
|
584
|
+
}
|
|
585
|
+
async function runStandaloneRules(rules, url, config) {
|
|
586
|
+
const results = [];
|
|
587
|
+
for (const rule of rules) {
|
|
588
|
+
if (config?.rules) {
|
|
589
|
+
const ruleConfig = config.rules[rule.meta.id];
|
|
590
|
+
if (ruleConfig === false) continue;
|
|
591
|
+
if (typeof ruleConfig === "object" && ruleConfig.enabled === false)
|
|
592
|
+
continue;
|
|
593
|
+
}
|
|
594
|
+
try {
|
|
595
|
+
const ruleResults = await rule.run(url);
|
|
596
|
+
results.push(...ruleResults);
|
|
597
|
+
} catch (err) {
|
|
598
|
+
console.warn(
|
|
599
|
+
`[lintpage] Standalone rule "${rule.meta.id}" threw an error: ${err instanceof Error ? err.message : String(err)}`
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
return results;
|
|
604
|
+
}
|
|
605
|
+
async function auditPage(url, options) {
|
|
606
|
+
const { document, response, ttfbMs } = await fetchPage(url);
|
|
607
|
+
const isHttps = url.startsWith("https://");
|
|
608
|
+
const context = {
|
|
609
|
+
document,
|
|
610
|
+
url,
|
|
611
|
+
response,
|
|
612
|
+
isHttps
|
|
613
|
+
};
|
|
614
|
+
const allRules = [...coreRules];
|
|
615
|
+
const allStandaloneRules = [];
|
|
616
|
+
if (options?.plugins) {
|
|
617
|
+
for (const plugin of options.plugins) {
|
|
618
|
+
allRules.push(...plugin.rules);
|
|
619
|
+
if (plugin.standaloneRules) {
|
|
620
|
+
allStandaloneRules.push(...plugin.standaloneRules);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
const results = runRules(allRules, context, options?.config);
|
|
625
|
+
if (allStandaloneRules.length > 0) {
|
|
626
|
+
const standaloneResults = await runStandaloneRules(
|
|
627
|
+
allStandaloneRules,
|
|
628
|
+
url,
|
|
629
|
+
options?.config
|
|
630
|
+
);
|
|
631
|
+
results.push(...standaloneResults);
|
|
632
|
+
}
|
|
633
|
+
if (ttfbMs > 2e3) {
|
|
634
|
+
results.push({
|
|
635
|
+
ruleId: "ttfb",
|
|
636
|
+
ruleName: "Time to First Byte",
|
|
637
|
+
message: `Slow server response time (TTFB: ${ttfbMs}ms) - aim for under 800ms`,
|
|
638
|
+
severity: "WARNING",
|
|
639
|
+
category: "Performance",
|
|
640
|
+
tier: "free",
|
|
641
|
+
fix: "Optimize server response time: enable caching, use a CDN, optimize database queries, or upgrade hosting.",
|
|
642
|
+
data: { ms: ttfbMs }
|
|
643
|
+
});
|
|
644
|
+
} else if (ttfbMs > 800) {
|
|
645
|
+
results.push({
|
|
646
|
+
ruleId: "ttfb",
|
|
647
|
+
ruleName: "Time to First Byte",
|
|
648
|
+
message: `Server response time could be improved (TTFB: ${ttfbMs}ms) - aim for under 800ms`,
|
|
649
|
+
severity: "INFO",
|
|
650
|
+
category: "Performance",
|
|
651
|
+
tier: "free",
|
|
652
|
+
fix: "Consider enabling server-side caching or using a CDN to reduce response time.",
|
|
653
|
+
data: { ms: ttfbMs }
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
const categoryScores = calculateCategoryScores(results);
|
|
657
|
+
const score = Object.values(categoryScores).reduce(
|
|
658
|
+
(sum, cat) => sum + cat.score,
|
|
659
|
+
0
|
|
660
|
+
);
|
|
661
|
+
const hasCritical = results.some((r) => r.severity === "CRITICAL");
|
|
662
|
+
return {
|
|
663
|
+
url,
|
|
664
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
665
|
+
results,
|
|
666
|
+
score: Math.round(score),
|
|
667
|
+
overallStatus: hasCritical ? "FAIL" : "PASS",
|
|
668
|
+
categoryScores
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
var CONFIG_FILES = [
|
|
672
|
+
".lintpagerc.json",
|
|
673
|
+
".lintpagerc",
|
|
674
|
+
"lintpage.config.json"
|
|
675
|
+
];
|
|
676
|
+
function loadConfig(cwd) {
|
|
677
|
+
const dir = cwd || process.cwd();
|
|
678
|
+
for (const file of CONFIG_FILES) {
|
|
679
|
+
const path = join(dir, file);
|
|
680
|
+
if (existsSync(path)) {
|
|
681
|
+
try {
|
|
682
|
+
const content = readFileSync(path, "utf-8");
|
|
683
|
+
return JSON.parse(content);
|
|
684
|
+
} catch {
|
|
685
|
+
return null;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
return null;
|
|
690
|
+
}
|
|
691
|
+
function createDefaultConfig() {
|
|
692
|
+
return {
|
|
693
|
+
rules: {}
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
// ../pro/dist/index.mjs
|
|
698
|
+
import * as jose from "jose";
|
|
699
|
+
var sslRule = {
|
|
700
|
+
meta: {
|
|
701
|
+
id: "ssl",
|
|
702
|
+
name: "SSL / HTTPS",
|
|
703
|
+
category: "Pre-Launch",
|
|
704
|
+
tier: "pro",
|
|
705
|
+
description: "Checks that the site is served over HTTPS"
|
|
706
|
+
},
|
|
707
|
+
run(context) {
|
|
708
|
+
const results = [];
|
|
709
|
+
if (!context.isHttps) {
|
|
710
|
+
results.push({
|
|
711
|
+
ruleId: "ssl",
|
|
712
|
+
ruleName: "SSL / HTTPS",
|
|
713
|
+
message: "Site is not using HTTPS \u2014 required for SEO and user trust. Search engines penalize HTTP sites.",
|
|
714
|
+
severity: "CRITICAL",
|
|
715
|
+
category: "Pre-Launch",
|
|
716
|
+
tier: "pro",
|
|
717
|
+
fix: "Install an SSL certificate and redirect all HTTP traffic to HTTPS. Most hosting providers offer free SSL via Let's Encrypt."
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
return results;
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
var robotsTxtCheckRule = {
|
|
724
|
+
meta: {
|
|
725
|
+
id: "robots-txt-check",
|
|
726
|
+
name: "robots.txt Check",
|
|
727
|
+
category: "Pre-Launch",
|
|
728
|
+
tier: "pro",
|
|
729
|
+
description: "Fetches and validates robots.txt for proper directives"
|
|
730
|
+
},
|
|
731
|
+
async run(url) {
|
|
732
|
+
const results = [];
|
|
733
|
+
try {
|
|
734
|
+
const robotsUrl = new URL("/robots.txt", url).href;
|
|
735
|
+
const response = await fetch(robotsUrl, {
|
|
736
|
+
headers: { "User-Agent": "LintPage-Bot/1.0" }
|
|
737
|
+
});
|
|
738
|
+
if (!response.ok) {
|
|
739
|
+
results.push({
|
|
740
|
+
ruleId: "robots-txt-check",
|
|
741
|
+
ruleName: "robots.txt Check",
|
|
742
|
+
message: "No robots.txt file found \u2014 recommended to have one",
|
|
743
|
+
severity: "WARNING",
|
|
744
|
+
category: "Pre-Launch",
|
|
745
|
+
tier: "pro",
|
|
746
|
+
fix: 'Create a robots.txt file at your site root with at least "User-Agent: *" and "Allow: /" directives.'
|
|
747
|
+
});
|
|
748
|
+
return results;
|
|
749
|
+
}
|
|
750
|
+
const content = await response.text();
|
|
751
|
+
const lines = content.split("\n").map((line) => line.trim());
|
|
752
|
+
const rules = /* @__PURE__ */ new Map();
|
|
753
|
+
let currentUserAgent = "*";
|
|
754
|
+
for (const line of lines) {
|
|
755
|
+
if (!line || line.startsWith("#")) continue;
|
|
756
|
+
const [directive, ...valueParts] = line.split(":").map((part) => part.trim());
|
|
757
|
+
const value = valueParts.join(":").trim();
|
|
758
|
+
if (!directive || !value) continue;
|
|
759
|
+
const upper = directive.toUpperCase();
|
|
760
|
+
if (upper === "USER-AGENT") {
|
|
761
|
+
currentUserAgent = value;
|
|
762
|
+
if (!rules.has(currentUserAgent)) {
|
|
763
|
+
rules.set(currentUserAgent, { disallow: [], allow: [] });
|
|
764
|
+
}
|
|
765
|
+
} else if (upper === "DISALLOW") {
|
|
766
|
+
const r = rules.get(currentUserAgent) || {
|
|
767
|
+
disallow: [],
|
|
768
|
+
allow: []
|
|
769
|
+
};
|
|
770
|
+
r.disallow.push(value);
|
|
771
|
+
rules.set(currentUserAgent, r);
|
|
772
|
+
} else if (upper === "ALLOW") {
|
|
773
|
+
const r = rules.get(currentUserAgent) || {
|
|
774
|
+
disallow: [],
|
|
775
|
+
allow: []
|
|
776
|
+
};
|
|
777
|
+
r.allow.push(value);
|
|
778
|
+
rules.set(currentUserAgent, r);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
const wildcard = rules.get("*");
|
|
782
|
+
if (wildcard && wildcard.disallow.includes("/")) {
|
|
783
|
+
results.push({
|
|
784
|
+
ruleId: "robots-txt-check",
|
|
785
|
+
ruleName: "robots.txt Check",
|
|
786
|
+
message: 'robots.txt contains "Disallow: /" for User-Agent: * \u2014 this blocks ALL search engines from crawling your entire site!',
|
|
787
|
+
severity: "CRITICAL",
|
|
788
|
+
category: "Pre-Launch",
|
|
789
|
+
tier: "pro",
|
|
790
|
+
fix: 'Change "Disallow: /" to "Allow: /" in your robots.txt, or remove the Disallow directive entirely.'
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
if (!content.toLowerCase().includes("sitemap")) {
|
|
794
|
+
results.push({
|
|
795
|
+
ruleId: "robots-txt-check",
|
|
796
|
+
ruleName: "robots.txt Check",
|
|
797
|
+
message: "robots.txt does not reference sitemap.xml \u2014 consider adding a Sitemap directive",
|
|
798
|
+
severity: "INFO",
|
|
799
|
+
category: "Pre-Launch",
|
|
800
|
+
tier: "pro",
|
|
801
|
+
fix: 'Add "Sitemap: https://yoursite.com/sitemap.xml" to the end of your robots.txt file.'
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
const hasMalformedLines = lines.some((line) => {
|
|
805
|
+
if (!line || line.startsWith("#")) return false;
|
|
806
|
+
return !line.includes(":") && line.length > 0;
|
|
807
|
+
});
|
|
808
|
+
if (hasMalformedLines) {
|
|
809
|
+
results.push({
|
|
810
|
+
ruleId: "robots-txt-check",
|
|
811
|
+
ruleName: "robots.txt Check",
|
|
812
|
+
message: 'robots.txt may have syntax errors \u2014 ensure each directive follows "Directive: value" format',
|
|
813
|
+
severity: "WARNING",
|
|
814
|
+
category: "Pre-Launch",
|
|
815
|
+
tier: "pro",
|
|
816
|
+
fix: 'Review each line in robots.txt. Every directive must follow the "Directive: value" format (e.g., "User-Agent: *").'
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
if (rules.size === 0 || rules.size === 1 && !rules.has("*")) {
|
|
820
|
+
results.push({
|
|
821
|
+
ruleId: "robots-txt-check",
|
|
822
|
+
ruleName: "robots.txt Check",
|
|
823
|
+
message: "robots.txt exists but has no rules defined \u2014 add User-Agent and Disallow/Allow directives",
|
|
824
|
+
severity: "INFO",
|
|
825
|
+
category: "Pre-Launch",
|
|
826
|
+
tier: "pro",
|
|
827
|
+
fix: 'Add at minimum "User-Agent: *" followed by "Allow: /" to your robots.txt.'
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
} catch {
|
|
831
|
+
results.push({
|
|
832
|
+
ruleId: "robots-txt-check",
|
|
833
|
+
ruleName: "robots.txt Check",
|
|
834
|
+
message: "Could not fetch robots.txt \u2014 ensure it exists at root domain",
|
|
835
|
+
severity: "WARNING",
|
|
836
|
+
category: "Pre-Launch",
|
|
837
|
+
tier: "pro",
|
|
838
|
+
fix: "Create a robots.txt file at your domain root (e.g., https://yoursite.com/robots.txt)."
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
return results;
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
var sitemapPresenceRule = {
|
|
845
|
+
meta: {
|
|
846
|
+
id: "sitemap-presence",
|
|
847
|
+
name: "Sitemap Presence",
|
|
848
|
+
category: "Pre-Launch",
|
|
849
|
+
tier: "pro",
|
|
850
|
+
description: "Checks for the existence and validity of sitemap.xml"
|
|
851
|
+
},
|
|
852
|
+
async run(url) {
|
|
853
|
+
const results = [];
|
|
854
|
+
try {
|
|
855
|
+
const sitemapUrl = new URL("/sitemap.xml", url).href;
|
|
856
|
+
const response = await fetch(sitemapUrl, {
|
|
857
|
+
headers: { "User-Agent": "LintPage-Bot/1.0" }
|
|
858
|
+
});
|
|
859
|
+
if (!response.ok) {
|
|
860
|
+
results.push({
|
|
861
|
+
ruleId: "sitemap-presence",
|
|
862
|
+
ruleName: "Sitemap Presence",
|
|
863
|
+
message: "No sitemap.xml found \u2014 recommended for search engines to discover your pages",
|
|
864
|
+
severity: "WARNING",
|
|
865
|
+
category: "Pre-Launch",
|
|
866
|
+
tier: "pro",
|
|
867
|
+
fix: "Generate a sitemap.xml and place it at your domain root. Most frameworks (Next.js, WordPress) have built-in sitemap generation."
|
|
868
|
+
});
|
|
869
|
+
return results;
|
|
870
|
+
}
|
|
871
|
+
const content = await response.text();
|
|
872
|
+
if (!content.includes("<?xml") || !content.includes("<urlset")) {
|
|
873
|
+
results.push({
|
|
874
|
+
ruleId: "sitemap-presence",
|
|
875
|
+
ruleName: "Sitemap Presence",
|
|
876
|
+
message: "sitemap.xml exists but may not be valid XML format",
|
|
877
|
+
severity: "WARNING",
|
|
878
|
+
category: "Pre-Launch",
|
|
879
|
+
tier: "pro",
|
|
880
|
+
fix: 'Ensure your sitemap.xml starts with <?xml version="1.0"?> and uses the <urlset> element with proper namespace.'
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
const urlMatches = content.match(/<loc>/g);
|
|
884
|
+
const urlCount = urlMatches ? urlMatches.length : 0;
|
|
885
|
+
if (urlCount === 0) {
|
|
886
|
+
results.push({
|
|
887
|
+
ruleId: "sitemap-presence",
|
|
888
|
+
ruleName: "Sitemap Presence",
|
|
889
|
+
message: "sitemap.xml is empty \u2014 add URLs to help search engines discover content",
|
|
890
|
+
severity: "WARNING",
|
|
891
|
+
category: "Pre-Launch",
|
|
892
|
+
tier: "pro",
|
|
893
|
+
fix: "Add <url><loc>https://yoursite.com/page</loc></url> entries to your sitemap for each page you want indexed."
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
} catch {
|
|
897
|
+
results.push({
|
|
898
|
+
ruleId: "sitemap-presence",
|
|
899
|
+
ruleName: "Sitemap Presence",
|
|
900
|
+
message: "Could not fetch sitemap.xml \u2014 create one at /sitemap.xml",
|
|
901
|
+
severity: "WARNING",
|
|
902
|
+
category: "Pre-Launch",
|
|
903
|
+
tier: "pro",
|
|
904
|
+
fix: "Create a sitemap.xml at your domain root. Use a sitemap generator or your framework's built-in sitemap feature."
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
return results;
|
|
908
|
+
}
|
|
909
|
+
};
|
|
910
|
+
var trackingRule = {
|
|
911
|
+
meta: {
|
|
912
|
+
id: "tracking",
|
|
913
|
+
name: "Analytics Tracking",
|
|
914
|
+
category: "Pre-Launch",
|
|
915
|
+
tier: "pro",
|
|
916
|
+
description: "Checks for Google Analytics, Google Tag Manager, or Facebook Pixel"
|
|
917
|
+
},
|
|
918
|
+
run(context) {
|
|
919
|
+
const { document } = context;
|
|
920
|
+
const results = [];
|
|
921
|
+
let foundGA = false;
|
|
922
|
+
let foundGTM = false;
|
|
923
|
+
const scripts = document.querySelectorAll("script");
|
|
924
|
+
scripts.forEach((script) => {
|
|
925
|
+
const src = script.getAttribute("src") || "";
|
|
926
|
+
const content = script.textContent || "";
|
|
927
|
+
if (src.includes("googletagmanager.com/gtag/js") || content.includes("gtag(")) {
|
|
928
|
+
foundGA = true;
|
|
929
|
+
}
|
|
930
|
+
if (src.includes("googletagmanager.com/gtm.js") || content.includes("GTM-")) {
|
|
931
|
+
foundGTM = true;
|
|
932
|
+
}
|
|
933
|
+
});
|
|
934
|
+
if (!foundGA && !foundGTM) {
|
|
935
|
+
results.push({
|
|
936
|
+
ruleId: "tracking",
|
|
937
|
+
ruleName: "Analytics Tracking",
|
|
938
|
+
message: "No Google Analytics or Tag Manager found \u2014 you won't be able to track traffic after launch",
|
|
939
|
+
severity: "WARNING",
|
|
940
|
+
category: "Pre-Launch",
|
|
941
|
+
tier: "pro",
|
|
942
|
+
fix: "Add Google Analytics (gtag.js) or Google Tag Manager script to your <head> tag. Get your tracking ID from analytics.google.com.",
|
|
943
|
+
data: { googleAnalytics: foundGA, googleTagManager: foundGTM }
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
return results;
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
var xRobotsTagRule = {
|
|
950
|
+
meta: {
|
|
951
|
+
id: "x-robots-tag",
|
|
952
|
+
name: "X-Robots-Tag Header",
|
|
953
|
+
category: "Pre-Launch",
|
|
954
|
+
tier: "pro",
|
|
955
|
+
description: "Checks the X-Robots-Tag HTTP header for noindex/nofollow"
|
|
956
|
+
},
|
|
957
|
+
run(context) {
|
|
958
|
+
const { response } = context;
|
|
959
|
+
const results = [];
|
|
960
|
+
const value = response.headers.get("x-robots-tag");
|
|
961
|
+
if (!value) return results;
|
|
962
|
+
const lower = value.toLowerCase();
|
|
963
|
+
if (lower.includes("noindex")) {
|
|
964
|
+
results.push({
|
|
965
|
+
ruleId: "x-robots-tag",
|
|
966
|
+
ruleName: "X-Robots-Tag Header",
|
|
967
|
+
message: 'X-Robots-Tag HTTP header contains "noindex" \u2014 page will NOT be indexed by search engines!',
|
|
968
|
+
severity: "CRITICAL",
|
|
969
|
+
category: "Pre-Launch",
|
|
970
|
+
tier: "pro",
|
|
971
|
+
fix: 'Remove the X-Robots-Tag header from your server configuration, or change its value to "index, follow".',
|
|
972
|
+
data: { value }
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
if (lower.includes("nofollow")) {
|
|
976
|
+
results.push({
|
|
977
|
+
ruleId: "x-robots-tag",
|
|
978
|
+
ruleName: "X-Robots-Tag Header",
|
|
979
|
+
message: 'X-Robots-Tag HTTP header contains "nofollow" \u2014 links will not be followed by search engines',
|
|
980
|
+
severity: "WARNING",
|
|
981
|
+
category: "SEO",
|
|
982
|
+
tier: "pro",
|
|
983
|
+
fix: 'Remove "nofollow" from the X-Robots-Tag header if you want search engines to follow your links.',
|
|
984
|
+
data: { value }
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
return results;
|
|
988
|
+
}
|
|
989
|
+
};
|
|
990
|
+
var thinContentRule = {
|
|
991
|
+
meta: {
|
|
992
|
+
id: "thin-content",
|
|
993
|
+
name: "Thin Content",
|
|
994
|
+
category: "SEO",
|
|
995
|
+
tier: "pro",
|
|
996
|
+
description: "Checks that the page has sufficient text content for search engines"
|
|
997
|
+
},
|
|
998
|
+
run(context) {
|
|
999
|
+
const { document } = context;
|
|
1000
|
+
const results = [];
|
|
1001
|
+
const bodyText = document.body?.textContent || "";
|
|
1002
|
+
const wordCount = bodyText.trim().split(/\s+/).filter(Boolean).length;
|
|
1003
|
+
if (wordCount < 300) {
|
|
1004
|
+
results.push({
|
|
1005
|
+
ruleId: "thin-content",
|
|
1006
|
+
ruleName: "Thin Content",
|
|
1007
|
+
message: `Page has thin content (${wordCount} words) \u2014 search engines prefer pages with substantial content (300+ words)`,
|
|
1008
|
+
severity: "INFO",
|
|
1009
|
+
category: "SEO",
|
|
1010
|
+
tier: "pro",
|
|
1011
|
+
fix: "Add more meaningful text content to the page. Search engines rank pages with substantial, relevant content higher.",
|
|
1012
|
+
data: { wordCount }
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
return results;
|
|
1016
|
+
}
|
|
1017
|
+
};
|
|
1018
|
+
var duplicateMetaRule = {
|
|
1019
|
+
meta: {
|
|
1020
|
+
id: "duplicate-meta",
|
|
1021
|
+
name: "Duplicate Meta Tags",
|
|
1022
|
+
category: "SEO",
|
|
1023
|
+
tier: "pro",
|
|
1024
|
+
description: "Checks for duplicate title, meta description, and canonical tags"
|
|
1025
|
+
},
|
|
1026
|
+
run(context) {
|
|
1027
|
+
const { document } = context;
|
|
1028
|
+
const results = [];
|
|
1029
|
+
const titleTags = document.querySelectorAll("title");
|
|
1030
|
+
if (titleTags.length > 1) {
|
|
1031
|
+
results.push({
|
|
1032
|
+
ruleId: "duplicate-meta",
|
|
1033
|
+
ruleName: "Duplicate Meta Tags",
|
|
1034
|
+
message: `Found ${titleTags.length} <title> tags \u2014 should have exactly one`,
|
|
1035
|
+
severity: "WARNING",
|
|
1036
|
+
category: "SEO",
|
|
1037
|
+
tier: "pro",
|
|
1038
|
+
fix: "Remove duplicate <title> tags. Keep only one in your <head> element.",
|
|
1039
|
+
data: { count: titleTags.length, tag: "title" }
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
const descriptionTags = document.querySelectorAll(
|
|
1043
|
+
'meta[name="description"]'
|
|
1044
|
+
);
|
|
1045
|
+
if (descriptionTags.length > 1) {
|
|
1046
|
+
results.push({
|
|
1047
|
+
ruleId: "duplicate-meta",
|
|
1048
|
+
ruleName: "Duplicate Meta Tags",
|
|
1049
|
+
message: `Found ${descriptionTags.length} meta description tags \u2014 should have exactly one`,
|
|
1050
|
+
severity: "WARNING",
|
|
1051
|
+
category: "SEO",
|
|
1052
|
+
tier: "pro",
|
|
1053
|
+
fix: 'Remove duplicate <meta name="description"> tags. Keep only one in your <head> element.',
|
|
1054
|
+
data: { count: descriptionTags.length, tag: "meta-description" }
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
const canonicalTags = document.querySelectorAll('link[rel="canonical"]');
|
|
1058
|
+
if (canonicalTags.length > 1) {
|
|
1059
|
+
results.push({
|
|
1060
|
+
ruleId: "duplicate-meta",
|
|
1061
|
+
ruleName: "Duplicate Meta Tags",
|
|
1062
|
+
message: `Found ${canonicalTags.length} canonical link tags \u2014 should have exactly one`,
|
|
1063
|
+
severity: "WARNING",
|
|
1064
|
+
category: "SEO",
|
|
1065
|
+
tier: "pro",
|
|
1066
|
+
fix: 'Remove duplicate <link rel="canonical"> tags. Keep only one in your <head> element.',
|
|
1067
|
+
data: { count: canonicalTags.length, tag: "canonical" }
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
return results;
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
var structuredDataRule = {
|
|
1074
|
+
meta: {
|
|
1075
|
+
id: "structured-data",
|
|
1076
|
+
name: "Structured Data",
|
|
1077
|
+
category: "SEO",
|
|
1078
|
+
tier: "pro",
|
|
1079
|
+
description: "Checks for the presence and validity of JSON-LD structured data"
|
|
1080
|
+
},
|
|
1081
|
+
run(context) {
|
|
1082
|
+
const { document } = context;
|
|
1083
|
+
const results = [];
|
|
1084
|
+
const jsonLdScripts = document.querySelectorAll(
|
|
1085
|
+
'script[type="application/ld+json"]'
|
|
1086
|
+
);
|
|
1087
|
+
const types = [];
|
|
1088
|
+
jsonLdScripts.forEach((script) => {
|
|
1089
|
+
try {
|
|
1090
|
+
const data = JSON.parse(script.textContent || "");
|
|
1091
|
+
if (data["@type"]) {
|
|
1092
|
+
types.push(data["@type"]);
|
|
1093
|
+
}
|
|
1094
|
+
} catch {
|
|
1095
|
+
results.push({
|
|
1096
|
+
ruleId: "structured-data",
|
|
1097
|
+
ruleName: "Structured Data",
|
|
1098
|
+
message: "Invalid JSON-LD structured data found",
|
|
1099
|
+
severity: "WARNING",
|
|
1100
|
+
category: "SEO",
|
|
1101
|
+
tier: "pro",
|
|
1102
|
+
fix: "Validate your JSON-LD using Google's Rich Results Test tool and fix any JSON syntax errors."
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
});
|
|
1106
|
+
if (types.length === 0) {
|
|
1107
|
+
results.push({
|
|
1108
|
+
ruleId: "structured-data",
|
|
1109
|
+
ruleName: "Structured Data",
|
|
1110
|
+
message: "No structured data (JSON-LD) found",
|
|
1111
|
+
severity: "INFO",
|
|
1112
|
+
category: "SEO",
|
|
1113
|
+
tier: "pro",
|
|
1114
|
+
fix: 'Add a <script type="application/ld+json"> block with Organization, WebPage, or other relevant schema.org types.',
|
|
1115
|
+
data: { types }
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
return results;
|
|
1119
|
+
}
|
|
1120
|
+
};
|
|
1121
|
+
var charsetRule = {
|
|
1122
|
+
meta: {
|
|
1123
|
+
id: "charset",
|
|
1124
|
+
name: "Character Encoding",
|
|
1125
|
+
category: "SEO",
|
|
1126
|
+
tier: "pro",
|
|
1127
|
+
description: "Checks for a proper charset/encoding declaration"
|
|
1128
|
+
},
|
|
1129
|
+
run(context) {
|
|
1130
|
+
const { document } = context;
|
|
1131
|
+
const results = [];
|
|
1132
|
+
const charsetMeta = document.querySelector("meta[charset]");
|
|
1133
|
+
const httpEquivMeta = document.querySelector(
|
|
1134
|
+
'meta[http-equiv="Content-Type"]'
|
|
1135
|
+
);
|
|
1136
|
+
if (!charsetMeta && !httpEquivMeta) {
|
|
1137
|
+
results.push({
|
|
1138
|
+
ruleId: "charset",
|
|
1139
|
+
ruleName: "Character Encoding",
|
|
1140
|
+
message: "Missing character encoding declaration \u2014 may cause rendering issues with special characters",
|
|
1141
|
+
severity: "WARNING",
|
|
1142
|
+
category: "SEO",
|
|
1143
|
+
tier: "pro",
|
|
1144
|
+
fix: 'Add <meta charset="utf-8" /> as the first element in your <head> tag.'
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
return results;
|
|
1148
|
+
}
|
|
1149
|
+
};
|
|
1150
|
+
var imageAltTextRule = {
|
|
1151
|
+
meta: {
|
|
1152
|
+
id: "image-alt-text",
|
|
1153
|
+
name: "Image Alt Text",
|
|
1154
|
+
category: "Accessibility",
|
|
1155
|
+
tier: "pro",
|
|
1156
|
+
description: "Checks that all images have alt attributes"
|
|
1157
|
+
},
|
|
1158
|
+
run(context) {
|
|
1159
|
+
const { document } = context;
|
|
1160
|
+
const results = [];
|
|
1161
|
+
const images = document.querySelectorAll("img");
|
|
1162
|
+
let missingAlt = 0;
|
|
1163
|
+
images.forEach((img) => {
|
|
1164
|
+
const alt = img.getAttribute("alt");
|
|
1165
|
+
if (alt === null || alt === void 0) {
|
|
1166
|
+
missingAlt++;
|
|
1167
|
+
}
|
|
1168
|
+
});
|
|
1169
|
+
if (missingAlt > 0) {
|
|
1170
|
+
results.push({
|
|
1171
|
+
ruleId: "image-alt-text",
|
|
1172
|
+
ruleName: "Image Alt Text",
|
|
1173
|
+
message: `${missingAlt} of ${images.length} images missing alt attributes`,
|
|
1174
|
+
severity: "WARNING",
|
|
1175
|
+
category: "Accessibility",
|
|
1176
|
+
tier: "pro",
|
|
1177
|
+
fix: 'Add descriptive alt attributes to all images. Screen readers use alt text to describe images to visually impaired users. Use alt="" for decorative images.',
|
|
1178
|
+
data: { total: images.length, missingAlt }
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
return results;
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1184
|
+
var accessibilityRule = {
|
|
1185
|
+
meta: {
|
|
1186
|
+
id: "accessibility",
|
|
1187
|
+
name: "Accessibility & ARIA",
|
|
1188
|
+
category: "Accessibility",
|
|
1189
|
+
tier: "pro",
|
|
1190
|
+
description: "Checks buttons, links, inputs, and ARIA attributes for accessibility"
|
|
1191
|
+
},
|
|
1192
|
+
run(context) {
|
|
1193
|
+
const { document } = context;
|
|
1194
|
+
const results = [];
|
|
1195
|
+
const buttons = document.querySelectorAll("button");
|
|
1196
|
+
let inaccessibleButtons = 0;
|
|
1197
|
+
buttons.forEach((button) => {
|
|
1198
|
+
const hasText = button.textContent?.trim();
|
|
1199
|
+
const hasAriaLabel = button.getAttribute("aria-label");
|
|
1200
|
+
const hasAriaLabelledBy = button.getAttribute("aria-labelledby");
|
|
1201
|
+
if (!hasText && !hasAriaLabel && !hasAriaLabelledBy) {
|
|
1202
|
+
inaccessibleButtons++;
|
|
1203
|
+
}
|
|
1204
|
+
});
|
|
1205
|
+
if (inaccessibleButtons > 0) {
|
|
1206
|
+
results.push({
|
|
1207
|
+
ruleId: "accessibility",
|
|
1208
|
+
ruleName: "Accessibility & ARIA",
|
|
1209
|
+
message: `${inaccessibleButtons} button(s) missing accessible name (no text, aria-label, or aria-labelledby)`,
|
|
1210
|
+
severity: "WARNING",
|
|
1211
|
+
category: "Accessibility",
|
|
1212
|
+
tier: "pro",
|
|
1213
|
+
fix: "Add visible text content, an aria-label, or aria-labelledby attribute to each button.",
|
|
1214
|
+
data: { inaccessibleButtons }
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
const links = document.querySelectorAll("a");
|
|
1218
|
+
let inaccessibleLinks = 0;
|
|
1219
|
+
links.forEach((link) => {
|
|
1220
|
+
const hasText = link.textContent?.trim();
|
|
1221
|
+
const hasAriaLabel = link.getAttribute("aria-label");
|
|
1222
|
+
if (!hasText && !hasAriaLabel) {
|
|
1223
|
+
inaccessibleLinks++;
|
|
1224
|
+
}
|
|
1225
|
+
});
|
|
1226
|
+
if (inaccessibleLinks > 0) {
|
|
1227
|
+
results.push({
|
|
1228
|
+
ruleId: "accessibility",
|
|
1229
|
+
ruleName: "Accessibility & ARIA",
|
|
1230
|
+
message: `${inaccessibleLinks} link(s) missing accessible name (no text or aria-label)`,
|
|
1231
|
+
severity: "WARNING",
|
|
1232
|
+
category: "Accessibility",
|
|
1233
|
+
tier: "pro",
|
|
1234
|
+
fix: "Add descriptive text content or an aria-label attribute to each link so screen readers can identify it.",
|
|
1235
|
+
data: { inaccessibleLinks }
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
const inputs = document.querySelectorAll("input:not([type='hidden'])");
|
|
1239
|
+
let unlabeledInputs = 0;
|
|
1240
|
+
inputs.forEach((input) => {
|
|
1241
|
+
const id = input.getAttribute("id");
|
|
1242
|
+
const ariaLabel = input.getAttribute("aria-label");
|
|
1243
|
+
const ariaLabelledBy = input.getAttribute("aria-labelledby");
|
|
1244
|
+
const hasLabel = id && document.querySelector(`label[for="${id}"]`);
|
|
1245
|
+
if (!hasLabel && !ariaLabel && !ariaLabelledBy) {
|
|
1246
|
+
unlabeledInputs++;
|
|
1247
|
+
}
|
|
1248
|
+
});
|
|
1249
|
+
if (unlabeledInputs > 0) {
|
|
1250
|
+
results.push({
|
|
1251
|
+
ruleId: "accessibility",
|
|
1252
|
+
ruleName: "Accessibility & ARIA",
|
|
1253
|
+
message: `${unlabeledInputs} input(s) missing associated label`,
|
|
1254
|
+
severity: "WARNING",
|
|
1255
|
+
category: "Accessibility",
|
|
1256
|
+
tier: "pro",
|
|
1257
|
+
fix: 'Add a <label for="inputId"> element, or add an aria-label attribute to each input.',
|
|
1258
|
+
data: { unlabeledInputs }
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
const divButtons = document.querySelectorAll(
|
|
1262
|
+
"div[onclick], span[onclick]"
|
|
1263
|
+
);
|
|
1264
|
+
let missingRoles = 0;
|
|
1265
|
+
divButtons.forEach((el) => {
|
|
1266
|
+
if (!el.getAttribute("role")) missingRoles++;
|
|
1267
|
+
});
|
|
1268
|
+
if (missingRoles > 0) {
|
|
1269
|
+
results.push({
|
|
1270
|
+
ruleId: "accessibility",
|
|
1271
|
+
ruleName: "Accessibility & ARIA",
|
|
1272
|
+
message: `${missingRoles} interactive div/span element(s) missing role attribute`,
|
|
1273
|
+
severity: "WARNING",
|
|
1274
|
+
category: "Accessibility",
|
|
1275
|
+
tier: "pro",
|
|
1276
|
+
fix: 'Use a <button> element instead, or add role="button" and an aria-label to interactive elements.',
|
|
1277
|
+
data: { missingRoles }
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
const navElements = document.querySelectorAll(
|
|
1281
|
+
'nav, [role="navigation"]'
|
|
1282
|
+
);
|
|
1283
|
+
let unlabeledNav = 0;
|
|
1284
|
+
navElements.forEach((nav) => {
|
|
1285
|
+
const ariaLabel = nav.getAttribute("aria-label");
|
|
1286
|
+
const ariaLabelledBy = nav.getAttribute("aria-labelledby");
|
|
1287
|
+
if (!ariaLabel && !ariaLabelledBy) unlabeledNav++;
|
|
1288
|
+
});
|
|
1289
|
+
if (unlabeledNav > 0) {
|
|
1290
|
+
results.push({
|
|
1291
|
+
ruleId: "accessibility",
|
|
1292
|
+
ruleName: "Accessibility & ARIA",
|
|
1293
|
+
message: `${unlabeledNav} navigation element(s) missing aria-label or aria-labelledby`,
|
|
1294
|
+
severity: "INFO",
|
|
1295
|
+
category: "Accessibility",
|
|
1296
|
+
tier: "pro",
|
|
1297
|
+
fix: 'Add aria-label="Main navigation" (or similar descriptive label) to your <nav> elements.',
|
|
1298
|
+
data: { unlabeledNav }
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1301
|
+
return results;
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
var semanticStructureRule = {
|
|
1305
|
+
meta: {
|
|
1306
|
+
id: "semantic-structure",
|
|
1307
|
+
name: "Semantic Structure",
|
|
1308
|
+
category: "Accessibility",
|
|
1309
|
+
tier: "pro",
|
|
1310
|
+
description: "Checks for proper semantic HTML: landmarks, lists, tables, articles"
|
|
1311
|
+
},
|
|
1312
|
+
run(context) {
|
|
1313
|
+
const { document } = context;
|
|
1314
|
+
const results = [];
|
|
1315
|
+
const main = document.querySelector("main");
|
|
1316
|
+
if (!main) {
|
|
1317
|
+
results.push({
|
|
1318
|
+
ruleId: "semantic-structure",
|
|
1319
|
+
ruleName: "Semantic Structure",
|
|
1320
|
+
message: "Missing <main> element \u2014 should wrap primary page content for better structure",
|
|
1321
|
+
severity: "WARNING",
|
|
1322
|
+
category: "Pre-Launch",
|
|
1323
|
+
tier: "pro",
|
|
1324
|
+
fix: "Wrap your primary page content in a <main> element. There should be exactly one per page."
|
|
1325
|
+
});
|
|
1326
|
+
}
|
|
1327
|
+
const semanticElements = document.querySelectorAll(
|
|
1328
|
+
"main, section, article, aside, nav"
|
|
1329
|
+
);
|
|
1330
|
+
if (semanticElements.length === 0) {
|
|
1331
|
+
results.push({
|
|
1332
|
+
ruleId: "semantic-structure",
|
|
1333
|
+
ruleName: "Semantic Structure",
|
|
1334
|
+
message: "Missing semantic page regions \u2014 use <main>, <section>, <article>, <nav>, <aside> instead of generic divs",
|
|
1335
|
+
severity: "WARNING",
|
|
1336
|
+
category: "Pre-Launch",
|
|
1337
|
+
tier: "pro",
|
|
1338
|
+
fix: "Replace generic <div> containers with semantic elements: <main>, <nav>, <section>, <article>, <aside>."
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
const listItems = document.querySelectorAll("li");
|
|
1342
|
+
let orphanedLi = 0;
|
|
1343
|
+
listItems.forEach((li) => {
|
|
1344
|
+
const parent = li.parentElement;
|
|
1345
|
+
if (parent?.tagName !== "UL" && parent?.tagName !== "OL") {
|
|
1346
|
+
orphanedLi++;
|
|
1347
|
+
}
|
|
1348
|
+
});
|
|
1349
|
+
if (orphanedLi > 0) {
|
|
1350
|
+
results.push({
|
|
1351
|
+
ruleId: "semantic-structure",
|
|
1352
|
+
ruleName: "Semantic Structure",
|
|
1353
|
+
message: `${orphanedLi} <li> element(s) found outside of <ul> or <ol> \u2014 breaks semantic structure`,
|
|
1354
|
+
severity: "WARNING",
|
|
1355
|
+
category: "Accessibility",
|
|
1356
|
+
tier: "pro",
|
|
1357
|
+
fix: "Wrap <li> elements inside a <ul> (unordered) or <ol> (ordered) list element.",
|
|
1358
|
+
data: { orphanedLi }
|
|
1359
|
+
});
|
|
1360
|
+
}
|
|
1361
|
+
const tables = document.querySelectorAll("table");
|
|
1362
|
+
let tablesWithoutThead = 0;
|
|
1363
|
+
tables.forEach((table) => {
|
|
1364
|
+
if (!table.querySelector("thead")) tablesWithoutThead++;
|
|
1365
|
+
});
|
|
1366
|
+
if (tablesWithoutThead > 0) {
|
|
1367
|
+
results.push({
|
|
1368
|
+
ruleId: "semantic-structure",
|
|
1369
|
+
ruleName: "Semantic Structure",
|
|
1370
|
+
message: `${tablesWithoutThead} table(s) missing <thead> element`,
|
|
1371
|
+
severity: "INFO",
|
|
1372
|
+
category: "Accessibility",
|
|
1373
|
+
tier: "pro",
|
|
1374
|
+
fix: "Add a <thead> element with <th> cells to define table column headers.",
|
|
1375
|
+
data: { tablesWithoutThead }
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
const articles = document.querySelectorAll("article");
|
|
1379
|
+
let articlesWithoutHeading = 0;
|
|
1380
|
+
articles.forEach((article) => {
|
|
1381
|
+
if (!article.querySelector("h1, h2, h3, h4, h5, h6")) {
|
|
1382
|
+
articlesWithoutHeading++;
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
if (articlesWithoutHeading > 0) {
|
|
1386
|
+
results.push({
|
|
1387
|
+
ruleId: "semantic-structure",
|
|
1388
|
+
ruleName: "Semantic Structure",
|
|
1389
|
+
message: `${articlesWithoutHeading} <article> element(s) without a heading`,
|
|
1390
|
+
severity: "INFO",
|
|
1391
|
+
category: "Accessibility",
|
|
1392
|
+
tier: "pro",
|
|
1393
|
+
fix: "Add a heading (h2-h6) inside each <article> element to provide context.",
|
|
1394
|
+
data: { articlesWithoutHeading }
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
return results;
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
var performanceRule = {
|
|
1401
|
+
meta: {
|
|
1402
|
+
id: "performance",
|
|
1403
|
+
name: "Performance Hints",
|
|
1404
|
+
category: "Performance",
|
|
1405
|
+
tier: "pro",
|
|
1406
|
+
description: "Checks for inline styles, lazy loading, and script count"
|
|
1407
|
+
},
|
|
1408
|
+
run(context) {
|
|
1409
|
+
const { document } = context;
|
|
1410
|
+
const results = [];
|
|
1411
|
+
const inlineStyles = document.querySelectorAll("[style]");
|
|
1412
|
+
if (inlineStyles.length > 10) {
|
|
1413
|
+
results.push({
|
|
1414
|
+
ruleId: "performance",
|
|
1415
|
+
ruleName: "Performance Hints",
|
|
1416
|
+
message: `Reduce inline styles (${inlineStyles.length} elements) \u2014 use CSS classes instead`,
|
|
1417
|
+
severity: "INFO",
|
|
1418
|
+
category: "Performance",
|
|
1419
|
+
tier: "pro",
|
|
1420
|
+
fix: "Move inline styles to CSS classes for better cacheability and maintainability.",
|
|
1421
|
+
data: { inlineStyleCount: inlineStyles.length }
|
|
1422
|
+
});
|
|
1423
|
+
}
|
|
1424
|
+
const images = document.querySelectorAll("img");
|
|
1425
|
+
let noLazyLoad = 0;
|
|
1426
|
+
images.forEach((img) => {
|
|
1427
|
+
if (!img.getAttribute("loading")) noLazyLoad++;
|
|
1428
|
+
});
|
|
1429
|
+
if (noLazyLoad > 3) {
|
|
1430
|
+
results.push({
|
|
1431
|
+
ruleId: "performance",
|
|
1432
|
+
ruleName: "Performance Hints",
|
|
1433
|
+
message: `${noLazyLoad} images without loading attribute \u2014 add lazy loading`,
|
|
1434
|
+
severity: "INFO",
|
|
1435
|
+
category: "Performance",
|
|
1436
|
+
tier: "pro",
|
|
1437
|
+
fix: 'Add loading="lazy" to images below the fold to defer loading until they are near the viewport.',
|
|
1438
|
+
data: { noLazyLoad, totalImages: images.length }
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
const scripts = document.querySelectorAll("script[src]");
|
|
1442
|
+
if (scripts.length > 10) {
|
|
1443
|
+
results.push({
|
|
1444
|
+
ruleId: "performance",
|
|
1445
|
+
ruleName: "Performance Hints",
|
|
1446
|
+
message: `Consider reducing external scripts (${scripts.length} found) for better performance`,
|
|
1447
|
+
severity: "INFO",
|
|
1448
|
+
category: "Performance",
|
|
1449
|
+
tier: "pro",
|
|
1450
|
+
fix: "Audit your scripts and remove unused ones. Consider bundling or deferring non-critical scripts.",
|
|
1451
|
+
data: { scriptCount: scripts.length }
|
|
1452
|
+
});
|
|
1453
|
+
}
|
|
1454
|
+
return results;
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
var imageDimensionsRule = {
|
|
1458
|
+
meta: {
|
|
1459
|
+
id: "image-dimensions",
|
|
1460
|
+
name: "Image Dimensions",
|
|
1461
|
+
category: "Performance",
|
|
1462
|
+
tier: "pro",
|
|
1463
|
+
description: "Checks that images have explicit width and height to prevent layout shift (CLS)"
|
|
1464
|
+
},
|
|
1465
|
+
run(context) {
|
|
1466
|
+
const { document } = context;
|
|
1467
|
+
const results = [];
|
|
1468
|
+
const images = document.querySelectorAll("img");
|
|
1469
|
+
let missingCount = 0;
|
|
1470
|
+
images.forEach((img) => {
|
|
1471
|
+
const hasWidth = img.getAttribute("width");
|
|
1472
|
+
const hasHeight = img.getAttribute("height");
|
|
1473
|
+
if (!hasWidth || !hasHeight) missingCount++;
|
|
1474
|
+
});
|
|
1475
|
+
if (missingCount > 0) {
|
|
1476
|
+
results.push({
|
|
1477
|
+
ruleId: "image-dimensions",
|
|
1478
|
+
ruleName: "Image Dimensions",
|
|
1479
|
+
message: `${missingCount} image${missingCount !== 1 ? "s" : ""} missing explicit width/height attributes \u2014 causes layout shift (CLS)`,
|
|
1480
|
+
severity: "INFO",
|
|
1481
|
+
category: "Performance",
|
|
1482
|
+
tier: "pro",
|
|
1483
|
+
fix: "Add width and height attributes to <img> tags to reserve space and prevent layout shift.",
|
|
1484
|
+
data: { missingCount, totalImages: images.length }
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
return results;
|
|
1488
|
+
}
|
|
1489
|
+
};
|
|
1490
|
+
var ttfbRule = {
|
|
1491
|
+
meta: {
|
|
1492
|
+
id: "ttfb-pro",
|
|
1493
|
+
name: "Time to First Byte (Pro)",
|
|
1494
|
+
category: "Performance",
|
|
1495
|
+
tier: "pro",
|
|
1496
|
+
description: "Measures server response time (TTFB) with detailed thresholds"
|
|
1497
|
+
},
|
|
1498
|
+
async run(url) {
|
|
1499
|
+
const results = [];
|
|
1500
|
+
try {
|
|
1501
|
+
const start = Date.now();
|
|
1502
|
+
await fetch(url, {
|
|
1503
|
+
headers: { "User-Agent": "LintPage-Bot/1.0" }
|
|
1504
|
+
});
|
|
1505
|
+
const ttfbMs = Date.now() - start;
|
|
1506
|
+
if (ttfbMs > 2e3) {
|
|
1507
|
+
results.push({
|
|
1508
|
+
ruleId: "ttfb-pro",
|
|
1509
|
+
ruleName: "Time to First Byte (Pro)",
|
|
1510
|
+
message: `Slow server response time (TTFB: ${ttfbMs}ms) \u2014 aim for under 800ms`,
|
|
1511
|
+
severity: "WARNING",
|
|
1512
|
+
category: "Performance",
|
|
1513
|
+
tier: "pro",
|
|
1514
|
+
fix: "Optimize server response time: enable caching, use a CDN, optimize database queries, or upgrade hosting.",
|
|
1515
|
+
data: { ms: ttfbMs }
|
|
1516
|
+
});
|
|
1517
|
+
} else if (ttfbMs > 800) {
|
|
1518
|
+
results.push({
|
|
1519
|
+
ruleId: "ttfb-pro",
|
|
1520
|
+
ruleName: "Time to First Byte (Pro)",
|
|
1521
|
+
message: `Server response time could be improved (TTFB: ${ttfbMs}ms) \u2014 aim for under 800ms`,
|
|
1522
|
+
severity: "INFO",
|
|
1523
|
+
category: "Performance",
|
|
1524
|
+
tier: "pro",
|
|
1525
|
+
fix: "Consider enabling server-side caching or using a CDN to reduce response time.",
|
|
1526
|
+
data: { ms: ttfbMs }
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1529
|
+
} catch {
|
|
1530
|
+
results.push({
|
|
1531
|
+
ruleId: "ttfb-pro",
|
|
1532
|
+
ruleName: "Time to First Byte (Pro)",
|
|
1533
|
+
message: "Could not measure TTFB \u2014 server may be unreachable",
|
|
1534
|
+
severity: "WARNING",
|
|
1535
|
+
category: "Performance",
|
|
1536
|
+
tier: "pro",
|
|
1537
|
+
fix: "Ensure your server is accessible and responding to requests."
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
return results;
|
|
1541
|
+
}
|
|
1542
|
+
};
|
|
1543
|
+
var mixedContentRule = {
|
|
1544
|
+
meta: {
|
|
1545
|
+
id: "mixed-content",
|
|
1546
|
+
name: "Mixed Content",
|
|
1547
|
+
category: "Pre-Launch",
|
|
1548
|
+
tier: "pro",
|
|
1549
|
+
description: "Checks for HTTP resources loaded on an HTTPS page (mixed content)"
|
|
1550
|
+
},
|
|
1551
|
+
run(context) {
|
|
1552
|
+
const { document, isHttps } = context;
|
|
1553
|
+
const results = [];
|
|
1554
|
+
if (!isHttps) return results;
|
|
1555
|
+
const selectors = [
|
|
1556
|
+
'img[src^="http:"]',
|
|
1557
|
+
'script[src^="http:"]',
|
|
1558
|
+
'link[href^="http:"]',
|
|
1559
|
+
'iframe[src^="http:"]',
|
|
1560
|
+
'video[src^="http:"]',
|
|
1561
|
+
'audio[src^="http:"]'
|
|
1562
|
+
];
|
|
1563
|
+
let count = 0;
|
|
1564
|
+
selectors.forEach((selector) => {
|
|
1565
|
+
count += document.querySelectorAll(selector).length;
|
|
1566
|
+
});
|
|
1567
|
+
if (count > 0) {
|
|
1568
|
+
results.push({
|
|
1569
|
+
ruleId: "mixed-content",
|
|
1570
|
+
ruleName: "Mixed Content",
|
|
1571
|
+
message: `Found ${count} mixed content resource${count !== 1 ? "s" : ""} (HTTP on HTTPS page) \u2014 browsers may block these`,
|
|
1572
|
+
severity: "WARNING",
|
|
1573
|
+
category: "Pre-Launch",
|
|
1574
|
+
tier: "pro",
|
|
1575
|
+
fix: "Change all resource URLs from http:// to https:// or use protocol-relative URLs (//).",
|
|
1576
|
+
data: { count }
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
return results;
|
|
1580
|
+
}
|
|
1581
|
+
};
|
|
1582
|
+
var securityHeadersRule = {
|
|
1583
|
+
meta: {
|
|
1584
|
+
id: "security-headers",
|
|
1585
|
+
name: "Security Headers",
|
|
1586
|
+
category: "Performance",
|
|
1587
|
+
tier: "pro",
|
|
1588
|
+
description: "Checks for important security headers (CSP, HSTS, X-Content-Type-Options, X-Frame-Options)"
|
|
1589
|
+
},
|
|
1590
|
+
run(context) {
|
|
1591
|
+
const { response } = context;
|
|
1592
|
+
const results = [];
|
|
1593
|
+
const headers = [
|
|
1594
|
+
{ name: "content-security-policy", label: "Content-Security-Policy" },
|
|
1595
|
+
{
|
|
1596
|
+
name: "strict-transport-security",
|
|
1597
|
+
label: "Strict-Transport-Security (HSTS)"
|
|
1598
|
+
},
|
|
1599
|
+
{ name: "x-content-type-options", label: "X-Content-Type-Options" },
|
|
1600
|
+
{ name: "x-frame-options", label: "X-Frame-Options" }
|
|
1601
|
+
];
|
|
1602
|
+
const missing = [];
|
|
1603
|
+
headers.forEach(({ name, label }) => {
|
|
1604
|
+
if (!response.headers.get(name)) missing.push(label);
|
|
1605
|
+
});
|
|
1606
|
+
if (missing.length > 0) {
|
|
1607
|
+
results.push({
|
|
1608
|
+
ruleId: "security-headers",
|
|
1609
|
+
ruleName: "Security Headers",
|
|
1610
|
+
message: `Missing security headers: ${missing.join(", ")}`,
|
|
1611
|
+
severity: "INFO",
|
|
1612
|
+
category: "Performance",
|
|
1613
|
+
tier: "pro",
|
|
1614
|
+
fix: "Configure your server or hosting provider to send these security headers. Most can be set in next.config.js headers() or your CDN settings.",
|
|
1615
|
+
data: { missing }
|
|
1616
|
+
});
|
|
1617
|
+
}
|
|
1618
|
+
return results;
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1621
|
+
var ogImageSizeRule = {
|
|
1622
|
+
meta: {
|
|
1623
|
+
id: "og-image-size",
|
|
1624
|
+
name: "OG Image Size",
|
|
1625
|
+
category: "SEO",
|
|
1626
|
+
tier: "pro",
|
|
1627
|
+
description: "Checks that the og:image URL exists and advises on recommended dimensions (1200x630)"
|
|
1628
|
+
},
|
|
1629
|
+
run(context) {
|
|
1630
|
+
const { document } = context;
|
|
1631
|
+
const results = [];
|
|
1632
|
+
const ogImage = document.querySelector('meta[property="og:image"]');
|
|
1633
|
+
const imageUrl = ogImage?.getAttribute("content")?.trim();
|
|
1634
|
+
if (!imageUrl) return results;
|
|
1635
|
+
const ogWidth = document.querySelector('meta[property="og:image:width"]');
|
|
1636
|
+
const ogHeight = document.querySelector(
|
|
1637
|
+
'meta[property="og:image:height"]'
|
|
1638
|
+
);
|
|
1639
|
+
const width = Number.parseInt(
|
|
1640
|
+
ogWidth?.getAttribute("content") || "",
|
|
1641
|
+
10
|
|
1642
|
+
);
|
|
1643
|
+
const height = Number.parseInt(
|
|
1644
|
+
ogHeight?.getAttribute("content") || "",
|
|
1645
|
+
10
|
|
1646
|
+
);
|
|
1647
|
+
if (!ogWidth || !ogHeight || Number.isNaN(width) || Number.isNaN(height)) {
|
|
1648
|
+
results.push({
|
|
1649
|
+
ruleId: "og-image-size",
|
|
1650
|
+
ruleName: "OG Image Size",
|
|
1651
|
+
message: "Missing og:image:width and og:image:height meta tags \u2014 social platforms may crop your image incorrectly",
|
|
1652
|
+
severity: "WARNING",
|
|
1653
|
+
category: "SEO",
|
|
1654
|
+
tier: "pro",
|
|
1655
|
+
fix: 'Add <meta property="og:image:width" content="1200" /> and <meta property="og:image:height" content="630" /> to your <head>.'
|
|
1656
|
+
});
|
|
1657
|
+
return results;
|
|
1658
|
+
}
|
|
1659
|
+
if (width < 1200 || height < 630) {
|
|
1660
|
+
results.push({
|
|
1661
|
+
ruleId: "og-image-size",
|
|
1662
|
+
ruleName: "OG Image Size",
|
|
1663
|
+
message: `OG image dimensions (${width}x${height}) are below recommended 1200x630 \u2014 may appear blurry on social platforms`,
|
|
1664
|
+
severity: "WARNING",
|
|
1665
|
+
category: "SEO",
|
|
1666
|
+
tier: "pro",
|
|
1667
|
+
fix: "Use an image at least 1200x630 pixels for best display on Facebook, LinkedIn, and other social platforms.",
|
|
1668
|
+
data: { width, height }
|
|
1669
|
+
});
|
|
1670
|
+
}
|
|
1671
|
+
return results;
|
|
1672
|
+
}
|
|
1673
|
+
};
|
|
1674
|
+
var SUPPORTED_TYPES = /* @__PURE__ */ new Set([
|
|
1675
|
+
"image/jpeg",
|
|
1676
|
+
"image/png",
|
|
1677
|
+
"image/gif",
|
|
1678
|
+
"image/webp"
|
|
1679
|
+
]);
|
|
1680
|
+
var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1681
|
+
".jpg",
|
|
1682
|
+
".jpeg",
|
|
1683
|
+
".png",
|
|
1684
|
+
".gif",
|
|
1685
|
+
".webp"
|
|
1686
|
+
]);
|
|
1687
|
+
var ogImageTypeRule = {
|
|
1688
|
+
meta: {
|
|
1689
|
+
id: "og-image-type",
|
|
1690
|
+
name: "OG Image Type",
|
|
1691
|
+
category: "SEO",
|
|
1692
|
+
tier: "pro",
|
|
1693
|
+
description: "Checks that the og:image type is a widely-supported format (JPEG, PNG, GIF, WebP)"
|
|
1694
|
+
},
|
|
1695
|
+
run(context) {
|
|
1696
|
+
const { document } = context;
|
|
1697
|
+
const results = [];
|
|
1698
|
+
const ogImage = document.querySelector('meta[property="og:image"]');
|
|
1699
|
+
const imageUrl = ogImage?.getAttribute("content")?.trim();
|
|
1700
|
+
if (!imageUrl) return results;
|
|
1701
|
+
const ogType = document.querySelector('meta[property="og:image:type"]')?.getAttribute("content")?.trim();
|
|
1702
|
+
if (ogType && !SUPPORTED_TYPES.has(ogType.toLowerCase())) {
|
|
1703
|
+
results.push({
|
|
1704
|
+
ruleId: "og-image-type",
|
|
1705
|
+
ruleName: "OG Image Type",
|
|
1706
|
+
message: `OG image type "${ogType}" may not be supported by all social platforms`,
|
|
1707
|
+
severity: "WARNING",
|
|
1708
|
+
category: "SEO",
|
|
1709
|
+
tier: "pro",
|
|
1710
|
+
fix: "Use JPEG or PNG for og:image. These formats are supported by all social platforms.",
|
|
1711
|
+
data: { type: ogType }
|
|
1712
|
+
});
|
|
1713
|
+
return results;
|
|
1714
|
+
}
|
|
1715
|
+
if (!ogType) {
|
|
1716
|
+
try {
|
|
1717
|
+
const url = new URL(imageUrl, "https://example.com");
|
|
1718
|
+
const ext = url.pathname.substring(url.pathname.lastIndexOf(".")).toLowerCase();
|
|
1719
|
+
if (ext && !SUPPORTED_EXTENSIONS.has(ext)) {
|
|
1720
|
+
results.push({
|
|
1721
|
+
ruleId: "og-image-type",
|
|
1722
|
+
ruleName: "OG Image Type",
|
|
1723
|
+
message: `OG image URL has extension "${ext}" which may not be supported by all social platforms`,
|
|
1724
|
+
severity: "INFO",
|
|
1725
|
+
category: "SEO",
|
|
1726
|
+
tier: "pro",
|
|
1727
|
+
fix: 'Use JPEG or PNG for og:image, and add <meta property="og:image:type" content="image/jpeg" /> to your <head>.',
|
|
1728
|
+
data: { extension: ext }
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
} catch {
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
return results;
|
|
1735
|
+
}
|
|
1736
|
+
};
|
|
1737
|
+
var twitterImageRule = {
|
|
1738
|
+
meta: {
|
|
1739
|
+
id: "twitter-image",
|
|
1740
|
+
name: "Twitter/X Image",
|
|
1741
|
+
category: "SEO",
|
|
1742
|
+
tier: "pro",
|
|
1743
|
+
description: "Checks for twitter:image meta tag for rich card previews on X/Twitter"
|
|
1744
|
+
},
|
|
1745
|
+
run(context) {
|
|
1746
|
+
const { document } = context;
|
|
1747
|
+
const results = [];
|
|
1748
|
+
const twitterCard = document.querySelector('meta[name="twitter:card"]');
|
|
1749
|
+
if (!twitterCard) return results;
|
|
1750
|
+
const twitterImage = document.querySelector(
|
|
1751
|
+
'meta[name="twitter:image"]'
|
|
1752
|
+
);
|
|
1753
|
+
const ogImage = document.querySelector('meta[property="og:image"]');
|
|
1754
|
+
if (!twitterImage && !ogImage) {
|
|
1755
|
+
results.push({
|
|
1756
|
+
ruleId: "twitter-image",
|
|
1757
|
+
ruleName: "Twitter/X Image",
|
|
1758
|
+
message: "Twitter card present but no twitter:image or og:image found \u2014 tweets will have no image preview",
|
|
1759
|
+
severity: "WARNING",
|
|
1760
|
+
category: "SEO",
|
|
1761
|
+
tier: "pro",
|
|
1762
|
+
fix: 'Add <meta name="twitter:image" content="https://yoursite.com/image.png" /> to your <head>.'
|
|
1763
|
+
});
|
|
1764
|
+
} else if (!twitterImage && ogImage) {
|
|
1765
|
+
results.push({
|
|
1766
|
+
ruleId: "twitter-image",
|
|
1767
|
+
ruleName: "Twitter/X Image",
|
|
1768
|
+
message: "No explicit twitter:image \u2014 falling back to og:image. Consider adding twitter:image for optimal display.",
|
|
1769
|
+
severity: "INFO",
|
|
1770
|
+
category: "SEO",
|
|
1771
|
+
tier: "pro",
|
|
1772
|
+
fix: 'Add <meta name="twitter:image" content="..." /> for more control over how your image appears on X/Twitter.'
|
|
1773
|
+
});
|
|
1774
|
+
}
|
|
1775
|
+
return results;
|
|
1776
|
+
}
|
|
1777
|
+
};
|
|
1778
|
+
var socialPreviewRenderRule = {
|
|
1779
|
+
meta: {
|
|
1780
|
+
id: "social-preview-render",
|
|
1781
|
+
name: "Social Preview Completeness",
|
|
1782
|
+
category: "SEO",
|
|
1783
|
+
tier: "pro",
|
|
1784
|
+
description: "Checks that all essential meta tags for social sharing previews are present and consistent"
|
|
1785
|
+
},
|
|
1786
|
+
run(context) {
|
|
1787
|
+
const { document } = context;
|
|
1788
|
+
const results = [];
|
|
1789
|
+
const ogTitle = document.querySelector('meta[property="og:title"]')?.getAttribute("content");
|
|
1790
|
+
const ogDesc = document.querySelector('meta[property="og:description"]')?.getAttribute("content");
|
|
1791
|
+
const ogImage = document.querySelector('meta[property="og:image"]')?.getAttribute("content");
|
|
1792
|
+
const ogUrl = document.querySelector('meta[property="og:url"]')?.getAttribute("content");
|
|
1793
|
+
const ogType = document.querySelector('meta[property="og:type"]')?.getAttribute("content");
|
|
1794
|
+
const title = document.querySelector("title")?.textContent?.trim();
|
|
1795
|
+
const metaDesc = document.querySelector('meta[name="description"]')?.getAttribute("content");
|
|
1796
|
+
if (!ogType) {
|
|
1797
|
+
results.push({
|
|
1798
|
+
ruleId: "social-preview-render",
|
|
1799
|
+
ruleName: "Social Preview Completeness",
|
|
1800
|
+
message: "Missing og:type meta tag \u2014 social platforms may not render the preview correctly",
|
|
1801
|
+
severity: "INFO",
|
|
1802
|
+
category: "SEO",
|
|
1803
|
+
tier: "pro",
|
|
1804
|
+
fix: 'Add <meta property="og:type" content="website" /> (or "article" for blog posts) to your <head>.'
|
|
1805
|
+
});
|
|
1806
|
+
}
|
|
1807
|
+
if (ogTitle && title && ogTitle.length > 0 && title.length > 0) {
|
|
1808
|
+
if (ogTitle.length > 70) {
|
|
1809
|
+
results.push({
|
|
1810
|
+
ruleId: "social-preview-render",
|
|
1811
|
+
ruleName: "Social Preview Completeness",
|
|
1812
|
+
message: `og:title is ${ogTitle.length} characters \u2014 may be truncated on social platforms (recommended: under 70)`,
|
|
1813
|
+
severity: "INFO",
|
|
1814
|
+
category: "SEO",
|
|
1815
|
+
tier: "pro",
|
|
1816
|
+
fix: "Keep og:title under 70 characters for best display on social platforms.",
|
|
1817
|
+
data: { ogTitleLength: ogTitle.length }
|
|
1818
|
+
});
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
if (ogDesc && ogDesc.length > 200) {
|
|
1822
|
+
results.push({
|
|
1823
|
+
ruleId: "social-preview-render",
|
|
1824
|
+
ruleName: "Social Preview Completeness",
|
|
1825
|
+
message: `og:description is ${ogDesc.length} characters \u2014 may be truncated on social platforms (recommended: under 200)`,
|
|
1826
|
+
severity: "INFO",
|
|
1827
|
+
category: "SEO",
|
|
1828
|
+
tier: "pro",
|
|
1829
|
+
fix: "Keep og:description under 200 characters for best display on social platforms.",
|
|
1830
|
+
data: { ogDescLength: ogDesc.length }
|
|
1831
|
+
});
|
|
1832
|
+
}
|
|
1833
|
+
if (ogUrl && !ogUrl.startsWith("http")) {
|
|
1834
|
+
results.push({
|
|
1835
|
+
ruleId: "social-preview-render",
|
|
1836
|
+
ruleName: "Social Preview Completeness",
|
|
1837
|
+
message: "og:url should be an absolute URL starting with https://",
|
|
1838
|
+
severity: "WARNING",
|
|
1839
|
+
category: "SEO",
|
|
1840
|
+
tier: "pro",
|
|
1841
|
+
fix: "Change og:url to an absolute URL (e.g., https://yoursite.com/page)."
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
if (ogImage && !ogImage.startsWith("http")) {
|
|
1845
|
+
results.push({
|
|
1846
|
+
ruleId: "social-preview-render",
|
|
1847
|
+
ruleName: "Social Preview Completeness",
|
|
1848
|
+
message: "og:image should be an absolute URL starting with https://",
|
|
1849
|
+
severity: "WARNING",
|
|
1850
|
+
category: "SEO",
|
|
1851
|
+
tier: "pro",
|
|
1852
|
+
fix: "Change og:image to an absolute URL (e.g., https://yoursite.com/image.png)."
|
|
1853
|
+
});
|
|
1854
|
+
}
|
|
1855
|
+
return results;
|
|
1856
|
+
}
|
|
1857
|
+
};
|
|
1858
|
+
var titleKeywordStuffingRule = {
|
|
1859
|
+
meta: {
|
|
1860
|
+
id: "title-keyword-stuffing",
|
|
1861
|
+
name: "Title Keyword Stuffing",
|
|
1862
|
+
category: "SEO",
|
|
1863
|
+
tier: "pro",
|
|
1864
|
+
description: "Detects potential keyword stuffing in the page title"
|
|
1865
|
+
},
|
|
1866
|
+
run(context) {
|
|
1867
|
+
const { document } = context;
|
|
1868
|
+
const results = [];
|
|
1869
|
+
const title = document.querySelector("title")?.textContent?.trim();
|
|
1870
|
+
if (!title) return results;
|
|
1871
|
+
const words = title.toLowerCase().split(/[\s\-|:,]+/).filter((w) => w.length > 3);
|
|
1872
|
+
const wordCounts = /* @__PURE__ */ new Map();
|
|
1873
|
+
for (const word of words) {
|
|
1874
|
+
wordCounts.set(word, (wordCounts.get(word) || 0) + 1);
|
|
1875
|
+
}
|
|
1876
|
+
const stuffedWords = [];
|
|
1877
|
+
for (const [word, count] of wordCounts) {
|
|
1878
|
+
if (count >= 3) stuffedWords.push(`"${word}" (${count}x)`);
|
|
1879
|
+
}
|
|
1880
|
+
if (stuffedWords.length > 0) {
|
|
1881
|
+
results.push({
|
|
1882
|
+
ruleId: "title-keyword-stuffing",
|
|
1883
|
+
ruleName: "Title Keyword Stuffing",
|
|
1884
|
+
message: `Potential keyword stuffing in title: ${stuffedWords.join(", ")}`,
|
|
1885
|
+
severity: "WARNING",
|
|
1886
|
+
category: "SEO",
|
|
1887
|
+
tier: "pro",
|
|
1888
|
+
fix: "Write a natural, readable title. Avoid repeating the same keyword more than twice. Search engines may penalize keyword stuffing.",
|
|
1889
|
+
data: { title, stuffedWords }
|
|
1890
|
+
});
|
|
1891
|
+
}
|
|
1892
|
+
const separatorCount = (title.match(/[|–—]/g) || []).length;
|
|
1893
|
+
if (separatorCount >= 3) {
|
|
1894
|
+
results.push({
|
|
1895
|
+
ruleId: "title-keyword-stuffing",
|
|
1896
|
+
ruleName: "Title Keyword Stuffing",
|
|
1897
|
+
message: `Title has ${separatorCount} separators \u2014 may appear spammy to search engines`,
|
|
1898
|
+
severity: "INFO",
|
|
1899
|
+
category: "SEO",
|
|
1900
|
+
tier: "pro",
|
|
1901
|
+
fix: "Simplify your title. Use at most one separator (|, \u2013 or \u2014) to separate the page name from your brand.",
|
|
1902
|
+
data: { separatorCount }
|
|
1903
|
+
});
|
|
1904
|
+
}
|
|
1905
|
+
return results;
|
|
1906
|
+
}
|
|
1907
|
+
};
|
|
1908
|
+
var contentToHtmlRatioRule = {
|
|
1909
|
+
meta: {
|
|
1910
|
+
id: "content-to-html-ratio",
|
|
1911
|
+
name: "Content-to-HTML Ratio",
|
|
1912
|
+
category: "SEO",
|
|
1913
|
+
tier: "pro",
|
|
1914
|
+
description: "Checks the ratio of visible text to total HTML markup"
|
|
1915
|
+
},
|
|
1916
|
+
run(context) {
|
|
1917
|
+
const { document } = context;
|
|
1918
|
+
const results = [];
|
|
1919
|
+
const htmlLength = document.documentElement?.outerHTML?.length || 0;
|
|
1920
|
+
if (htmlLength === 0) return results;
|
|
1921
|
+
const textContent = document.body?.textContent || "";
|
|
1922
|
+
const textLength = textContent.replace(/\s+/g, " ").trim().length;
|
|
1923
|
+
const ratio = Math.round(textLength / htmlLength * 100);
|
|
1924
|
+
if (ratio < 10) {
|
|
1925
|
+
results.push({
|
|
1926
|
+
ruleId: "content-to-html-ratio",
|
|
1927
|
+
ruleName: "Content-to-HTML Ratio",
|
|
1928
|
+
message: `Low content-to-HTML ratio (${ratio}%) \u2014 search engines may view this as thin or boilerplate content`,
|
|
1929
|
+
severity: "WARNING",
|
|
1930
|
+
category: "SEO",
|
|
1931
|
+
tier: "pro",
|
|
1932
|
+
fix: "Increase meaningful text content relative to HTML markup. Remove unnecessary divs, inline styles, and JavaScript.",
|
|
1933
|
+
data: { ratio, textLength, htmlLength }
|
|
1934
|
+
});
|
|
1935
|
+
} else if (ratio < 20) {
|
|
1936
|
+
results.push({
|
|
1937
|
+
ruleId: "content-to-html-ratio",
|
|
1938
|
+
ruleName: "Content-to-HTML Ratio",
|
|
1939
|
+
message: `Content-to-HTML ratio is ${ratio}% \u2014 could be improved (aim for 25%+)`,
|
|
1940
|
+
severity: "INFO",
|
|
1941
|
+
category: "SEO",
|
|
1942
|
+
tier: "pro",
|
|
1943
|
+
fix: "Consider adding more text content or reducing unnecessary HTML markup to improve the ratio.",
|
|
1944
|
+
data: { ratio, textLength, htmlLength }
|
|
1945
|
+
});
|
|
1946
|
+
}
|
|
1947
|
+
return results;
|
|
1948
|
+
}
|
|
1949
|
+
};
|
|
1950
|
+
var titleUniquenessRule = {
|
|
1951
|
+
meta: {
|
|
1952
|
+
id: "title-uniqueness",
|
|
1953
|
+
name: "Title Uniqueness",
|
|
1954
|
+
category: "SEO",
|
|
1955
|
+
tier: "pro",
|
|
1956
|
+
description: "Flags titles that appear generic or auto-generated (single-page heuristic)"
|
|
1957
|
+
},
|
|
1958
|
+
run(context) {
|
|
1959
|
+
const { document, url } = context;
|
|
1960
|
+
const results = [];
|
|
1961
|
+
const title = document.querySelector("title")?.textContent?.trim();
|
|
1962
|
+
if (!title) return results;
|
|
1963
|
+
const genericPatterns = [
|
|
1964
|
+
/^home$/i,
|
|
1965
|
+
/^untitled/i,
|
|
1966
|
+
/^page \d+$/i,
|
|
1967
|
+
/^welcome$/i,
|
|
1968
|
+
/^index$/i,
|
|
1969
|
+
/^document$/i,
|
|
1970
|
+
/^my site$/i,
|
|
1971
|
+
/^my website$/i,
|
|
1972
|
+
/^website$/i,
|
|
1973
|
+
/^new page$/i
|
|
1974
|
+
];
|
|
1975
|
+
for (const pattern of genericPatterns) {
|
|
1976
|
+
if (pattern.test(title)) {
|
|
1977
|
+
results.push({
|
|
1978
|
+
ruleId: "title-uniqueness",
|
|
1979
|
+
ruleName: "Title Uniqueness",
|
|
1980
|
+
message: `Title "${title}" appears to be a generic/default title \u2014 use a unique, descriptive title`,
|
|
1981
|
+
severity: "WARNING",
|
|
1982
|
+
category: "SEO",
|
|
1983
|
+
tier: "pro",
|
|
1984
|
+
fix: "Write a unique, descriptive title for each page that includes your target keyword.",
|
|
1985
|
+
data: { title }
|
|
1986
|
+
});
|
|
1987
|
+
break;
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
try {
|
|
1991
|
+
const hostname = new URL(url).hostname.replace("www.", "");
|
|
1992
|
+
const domainName = hostname.split(".")[0];
|
|
1993
|
+
if (domainName && title.toLowerCase() === domainName.toLowerCase()) {
|
|
1994
|
+
results.push({
|
|
1995
|
+
ruleId: "title-uniqueness",
|
|
1996
|
+
ruleName: "Title Uniqueness",
|
|
1997
|
+
message: "Title is just the domain name \u2014 add a descriptive page-specific title",
|
|
1998
|
+
severity: "WARNING",
|
|
1999
|
+
category: "SEO",
|
|
2000
|
+
tier: "pro",
|
|
2001
|
+
fix: 'Include a page-specific description in your title, e.g., "Product Name \u2014 Your Brand".',
|
|
2002
|
+
data: { title, hostname }
|
|
2003
|
+
});
|
|
2004
|
+
}
|
|
2005
|
+
} catch {
|
|
2006
|
+
}
|
|
2007
|
+
return results;
|
|
2008
|
+
}
|
|
2009
|
+
};
|
|
2010
|
+
var descriptionUniquenessRule = {
|
|
2011
|
+
meta: {
|
|
2012
|
+
id: "description-uniqueness",
|
|
2013
|
+
name: "Description Uniqueness",
|
|
2014
|
+
category: "SEO",
|
|
2015
|
+
tier: "pro",
|
|
2016
|
+
description: "Flags meta descriptions that appear generic or auto-generated (single-page heuristic)"
|
|
2017
|
+
},
|
|
2018
|
+
run(context) {
|
|
2019
|
+
const { document } = context;
|
|
2020
|
+
const results = [];
|
|
2021
|
+
const metaDesc = document.querySelector('meta[name="description"]');
|
|
2022
|
+
const description = metaDesc?.getAttribute("content")?.trim();
|
|
2023
|
+
if (!description) return results;
|
|
2024
|
+
const genericPatterns = [
|
|
2025
|
+
/^welcome to/i,
|
|
2026
|
+
/^this is a website/i,
|
|
2027
|
+
/^a website about/i,
|
|
2028
|
+
/^home page/i,
|
|
2029
|
+
/^we are a company/i,
|
|
2030
|
+
/^default description/i
|
|
2031
|
+
];
|
|
2032
|
+
for (const pattern of genericPatterns) {
|
|
2033
|
+
if (pattern.test(description)) {
|
|
2034
|
+
results.push({
|
|
2035
|
+
ruleId: "description-uniqueness",
|
|
2036
|
+
ruleName: "Description Uniqueness",
|
|
2037
|
+
message: `Meta description appears generic \u2014 write a unique, compelling description for this page`,
|
|
2038
|
+
severity: "WARNING",
|
|
2039
|
+
category: "SEO",
|
|
2040
|
+
tier: "pro",
|
|
2041
|
+
fix: "Write a unique meta description for each page that summarizes the specific content and includes a call to action.",
|
|
2042
|
+
data: { description }
|
|
2043
|
+
});
|
|
2044
|
+
break;
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
const title = document.querySelector("title")?.textContent?.trim();
|
|
2048
|
+
if (title && description.toLowerCase() === title.toLowerCase()) {
|
|
2049
|
+
results.push({
|
|
2050
|
+
ruleId: "description-uniqueness",
|
|
2051
|
+
ruleName: "Description Uniqueness",
|
|
2052
|
+
message: "Meta description is identical to the title \u2014 they should be different and complementary",
|
|
2053
|
+
severity: "WARNING",
|
|
2054
|
+
category: "SEO",
|
|
2055
|
+
tier: "pro",
|
|
2056
|
+
fix: "Write a meta description that expands on your title with more detail, a value proposition, or a call to action.",
|
|
2057
|
+
data: { description, title }
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
2060
|
+
return results;
|
|
2061
|
+
}
|
|
2062
|
+
};
|
|
2063
|
+
var REQUIRED_FIELDS = {
|
|
2064
|
+
Organization: ["name", "url"],
|
|
2065
|
+
WebSite: ["name", "url"],
|
|
2066
|
+
WebPage: ["name"],
|
|
2067
|
+
Article: ["headline", "author", "datePublished"],
|
|
2068
|
+
Product: ["name", "image"],
|
|
2069
|
+
BreadcrumbList: ["itemListElement"],
|
|
2070
|
+
FAQPage: ["mainEntity"],
|
|
2071
|
+
LocalBusiness: ["name", "address"]
|
|
2072
|
+
};
|
|
2073
|
+
var structuredDataValidateRule = {
|
|
2074
|
+
meta: {
|
|
2075
|
+
id: "structured-data-validate",
|
|
2076
|
+
name: "Structured Data Validation",
|
|
2077
|
+
category: "SEO",
|
|
2078
|
+
tier: "pro",
|
|
2079
|
+
description: "Validates JSON-LD structured data for required fields based on schema type"
|
|
2080
|
+
},
|
|
2081
|
+
run(context) {
|
|
2082
|
+
const { document } = context;
|
|
2083
|
+
const results = [];
|
|
2084
|
+
const jsonLdScripts = document.querySelectorAll(
|
|
2085
|
+
'script[type="application/ld+json"]'
|
|
2086
|
+
);
|
|
2087
|
+
jsonLdScripts.forEach((script) => {
|
|
2088
|
+
let data;
|
|
2089
|
+
try {
|
|
2090
|
+
data = JSON.parse(script.textContent || "");
|
|
2091
|
+
} catch {
|
|
2092
|
+
return;
|
|
2093
|
+
}
|
|
2094
|
+
const type = data["@type"];
|
|
2095
|
+
if (!type) {
|
|
2096
|
+
results.push({
|
|
2097
|
+
ruleId: "structured-data-validate",
|
|
2098
|
+
ruleName: "Structured Data Validation",
|
|
2099
|
+
message: "JSON-LD block missing @type property",
|
|
2100
|
+
severity: "WARNING",
|
|
2101
|
+
category: "SEO",
|
|
2102
|
+
tier: "pro",
|
|
2103
|
+
fix: 'Add an @type property (e.g., "Organization", "WebPage", "Article") to your JSON-LD.'
|
|
2104
|
+
});
|
|
2105
|
+
return;
|
|
2106
|
+
}
|
|
2107
|
+
if (!data["@context"]) {
|
|
2108
|
+
results.push({
|
|
2109
|
+
ruleId: "structured-data-validate",
|
|
2110
|
+
ruleName: "Structured Data Validation",
|
|
2111
|
+
message: `JSON-LD "${type}" missing @context \u2014 should be "https://schema.org"`,
|
|
2112
|
+
severity: "WARNING",
|
|
2113
|
+
category: "SEO",
|
|
2114
|
+
tier: "pro",
|
|
2115
|
+
fix: 'Add "@context": "https://schema.org" to your JSON-LD block.',
|
|
2116
|
+
data: { type }
|
|
2117
|
+
});
|
|
2118
|
+
}
|
|
2119
|
+
const required = REQUIRED_FIELDS[type];
|
|
2120
|
+
if (required) {
|
|
2121
|
+
const missing = required.filter((field) => !data[field]);
|
|
2122
|
+
if (missing.length > 0) {
|
|
2123
|
+
results.push({
|
|
2124
|
+
ruleId: "structured-data-validate",
|
|
2125
|
+
ruleName: "Structured Data Validation",
|
|
2126
|
+
message: `JSON-LD "${type}" missing required fields: ${missing.join(", ")}`,
|
|
2127
|
+
severity: "WARNING",
|
|
2128
|
+
category: "SEO",
|
|
2129
|
+
tier: "pro",
|
|
2130
|
+
fix: `Add the missing fields to your ${type} schema: ${missing.join(", ")}.`,
|
|
2131
|
+
data: { type, missing }
|
|
2132
|
+
});
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
});
|
|
2136
|
+
return results;
|
|
2137
|
+
}
|
|
2138
|
+
};
|
|
2139
|
+
var hreflangRule = {
|
|
2140
|
+
meta: {
|
|
2141
|
+
id: "hreflang",
|
|
2142
|
+
name: "Hreflang Tags",
|
|
2143
|
+
category: "SEO",
|
|
2144
|
+
tier: "pro",
|
|
2145
|
+
description: "Validates hreflang tags for multi-language pages"
|
|
2146
|
+
},
|
|
2147
|
+
run(context) {
|
|
2148
|
+
const { document, url } = context;
|
|
2149
|
+
const results = [];
|
|
2150
|
+
const hreflangTags = document.querySelectorAll(
|
|
2151
|
+
'link[rel="alternate"][hreflang]'
|
|
2152
|
+
);
|
|
2153
|
+
if (hreflangTags.length === 0) return results;
|
|
2154
|
+
const hasXDefault = Array.from(hreflangTags).some(
|
|
2155
|
+
(tag) => tag.getAttribute("hreflang") === "x-default"
|
|
2156
|
+
);
|
|
2157
|
+
if (!hasXDefault) {
|
|
2158
|
+
results.push({
|
|
2159
|
+
ruleId: "hreflang",
|
|
2160
|
+
ruleName: "Hreflang Tags",
|
|
2161
|
+
message: "Hreflang tags found but missing x-default \u2014 add a fallback for unmatched languages",
|
|
2162
|
+
severity: "WARNING",
|
|
2163
|
+
category: "SEO",
|
|
2164
|
+
tier: "pro",
|
|
2165
|
+
fix: 'Add <link rel="alternate" hreflang="x-default" href="..." /> to specify the default/fallback page.'
|
|
2166
|
+
});
|
|
2167
|
+
}
|
|
2168
|
+
const hasSelfRef = Array.from(hreflangTags).some((tag) => {
|
|
2169
|
+
const href = tag.getAttribute("href");
|
|
2170
|
+
return href === url || href === url.replace(/\/$/, "");
|
|
2171
|
+
});
|
|
2172
|
+
if (!hasSelfRef) {
|
|
2173
|
+
results.push({
|
|
2174
|
+
ruleId: "hreflang",
|
|
2175
|
+
ruleName: "Hreflang Tags",
|
|
2176
|
+
message: "Hreflang tags do not include a self-referencing tag for the current page",
|
|
2177
|
+
severity: "WARNING",
|
|
2178
|
+
category: "SEO",
|
|
2179
|
+
tier: "pro",
|
|
2180
|
+
fix: "Add a hreflang tag that points to the current page URL with the appropriate language code."
|
|
2181
|
+
});
|
|
2182
|
+
}
|
|
2183
|
+
const langCodePattern = /^[a-z]{2}(-[A-Z]{2})?$/;
|
|
2184
|
+
hreflangTags.forEach((tag) => {
|
|
2185
|
+
const lang = tag.getAttribute("hreflang");
|
|
2186
|
+
if (lang && lang !== "x-default" && !langCodePattern.test(lang)) {
|
|
2187
|
+
results.push({
|
|
2188
|
+
ruleId: "hreflang",
|
|
2189
|
+
ruleName: "Hreflang Tags",
|
|
2190
|
+
message: `Invalid hreflang language code "${lang}" \u2014 use ISO 639-1 format (e.g., "en", "en-US")`,
|
|
2191
|
+
severity: "WARNING",
|
|
2192
|
+
category: "SEO",
|
|
2193
|
+
tier: "pro",
|
|
2194
|
+
fix: `Change "${lang}" to a valid ISO 639-1 language code (e.g., "en", "fr", "de-AT").`,
|
|
2195
|
+
data: { invalidLang: lang }
|
|
2196
|
+
});
|
|
2197
|
+
}
|
|
2198
|
+
const href = tag.getAttribute("href");
|
|
2199
|
+
if (href && !href.startsWith("http")) {
|
|
2200
|
+
results.push({
|
|
2201
|
+
ruleId: "hreflang",
|
|
2202
|
+
ruleName: "Hreflang Tags",
|
|
2203
|
+
message: `Hreflang href should be an absolute URL (found: "${href}")`,
|
|
2204
|
+
severity: "WARNING",
|
|
2205
|
+
category: "SEO",
|
|
2206
|
+
tier: "pro",
|
|
2207
|
+
fix: "Use absolute URLs (starting with https://) for all hreflang href attributes."
|
|
2208
|
+
});
|
|
2209
|
+
}
|
|
2210
|
+
});
|
|
2211
|
+
return results;
|
|
2212
|
+
}
|
|
2213
|
+
};
|
|
2214
|
+
var canonicalSelfReferencingRule = {
|
|
2215
|
+
meta: {
|
|
2216
|
+
id: "canonical-self-referencing",
|
|
2217
|
+
name: "Canonical Self-Referencing",
|
|
2218
|
+
category: "SEO",
|
|
2219
|
+
tier: "pro",
|
|
2220
|
+
description: "Checks that the canonical URL points to the current page (self-referencing canonical)"
|
|
2221
|
+
},
|
|
2222
|
+
run(context) {
|
|
2223
|
+
const { document, url } = context;
|
|
2224
|
+
const results = [];
|
|
2225
|
+
const canonical = document.querySelector('link[rel="canonical"]');
|
|
2226
|
+
if (!canonical) return results;
|
|
2227
|
+
const href = canonical.getAttribute("href")?.trim();
|
|
2228
|
+
if (!href) return results;
|
|
2229
|
+
const normalize = (u) => u.replace(/\/$/, "").toLowerCase();
|
|
2230
|
+
try {
|
|
2231
|
+
const canonicalUrl = new URL(href, url).href;
|
|
2232
|
+
const normalizedCanonical = normalize(canonicalUrl);
|
|
2233
|
+
const normalizedUrl = normalize(url);
|
|
2234
|
+
if (normalizedCanonical !== normalizedUrl) {
|
|
2235
|
+
const sameHost = new URL(canonicalUrl).hostname === new URL(url).hostname;
|
|
2236
|
+
if (sameHost) {
|
|
2237
|
+
results.push({
|
|
2238
|
+
ruleId: "canonical-self-referencing",
|
|
2239
|
+
ruleName: "Canonical Self-Referencing",
|
|
2240
|
+
message: `Canonical URL points to a different page on the same site \u2014 this tells search engines to index "${canonicalUrl}" instead of this page`,
|
|
2241
|
+
severity: "INFO",
|
|
2242
|
+
category: "SEO",
|
|
2243
|
+
tier: "pro",
|
|
2244
|
+
fix: "If this page should be indexed, change the canonical to point to itself. If this is intentional (e.g., pagination), you can ignore this.",
|
|
2245
|
+
data: { canonical: canonicalUrl, pageUrl: url }
|
|
2246
|
+
});
|
|
2247
|
+
} else {
|
|
2248
|
+
results.push({
|
|
2249
|
+
ruleId: "canonical-self-referencing",
|
|
2250
|
+
ruleName: "Canonical Self-Referencing",
|
|
2251
|
+
message: `Canonical URL points to a different domain ("${new URL(canonicalUrl).hostname}") \u2014 this is unusual and may be a misconfiguration`,
|
|
2252
|
+
severity: "WARNING",
|
|
2253
|
+
category: "SEO",
|
|
2254
|
+
tier: "pro",
|
|
2255
|
+
fix: "Cross-domain canonical tags are rarely correct. Verify this is intentional, otherwise change the canonical to point to this page.",
|
|
2256
|
+
data: { canonical: canonicalUrl, pageUrl: url }
|
|
2257
|
+
});
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
} catch {
|
|
2261
|
+
results.push({
|
|
2262
|
+
ruleId: "canonical-self-referencing",
|
|
2263
|
+
ruleName: "Canonical Self-Referencing",
|
|
2264
|
+
message: `Cannot parse canonical URL "${href}" \u2014 ensure it's a valid absolute URL`,
|
|
2265
|
+
severity: "WARNING",
|
|
2266
|
+
category: "SEO",
|
|
2267
|
+
tier: "pro",
|
|
2268
|
+
fix: "Use a valid absolute URL for your canonical tag (e.g., https://yoursite.com/page)."
|
|
2269
|
+
});
|
|
2270
|
+
}
|
|
2271
|
+
return results;
|
|
2272
|
+
}
|
|
2273
|
+
};
|
|
2274
|
+
var metaRenderBlockingRule = {
|
|
2275
|
+
meta: {
|
|
2276
|
+
id: "meta-render-blocking",
|
|
2277
|
+
name: "Render-Blocking Resources",
|
|
2278
|
+
category: "Performance",
|
|
2279
|
+
tier: "pro",
|
|
2280
|
+
description: "Checks for render-blocking stylesheets and synchronous scripts in the <head>"
|
|
2281
|
+
},
|
|
2282
|
+
run(context) {
|
|
2283
|
+
const { document } = context;
|
|
2284
|
+
const results = [];
|
|
2285
|
+
const head = document.querySelector("head");
|
|
2286
|
+
if (!head) return results;
|
|
2287
|
+
const headScripts = head.querySelectorAll("script[src]");
|
|
2288
|
+
let blockingScripts = 0;
|
|
2289
|
+
headScripts.forEach((script) => {
|
|
2290
|
+
const hasAsync = script.hasAttribute("async");
|
|
2291
|
+
const hasDefer = script.hasAttribute("defer");
|
|
2292
|
+
const type = script.getAttribute("type");
|
|
2293
|
+
if (!hasAsync && !hasDefer && type !== "module") {
|
|
2294
|
+
blockingScripts++;
|
|
2295
|
+
}
|
|
2296
|
+
});
|
|
2297
|
+
if (blockingScripts > 0) {
|
|
2298
|
+
results.push({
|
|
2299
|
+
ruleId: "meta-render-blocking",
|
|
2300
|
+
ruleName: "Render-Blocking Resources",
|
|
2301
|
+
message: `${blockingScripts} synchronous script(s) in <head> may block page rendering`,
|
|
2302
|
+
severity: "WARNING",
|
|
2303
|
+
category: "Performance",
|
|
2304
|
+
tier: "pro",
|
|
2305
|
+
fix: "Add async or defer attributes to non-critical scripts in the <head>, or move them to the end of <body>.",
|
|
2306
|
+
data: { blockingScripts }
|
|
2307
|
+
});
|
|
2308
|
+
}
|
|
2309
|
+
const stylesheets = head.querySelectorAll(
|
|
2310
|
+
'link[rel="stylesheet"]'
|
|
2311
|
+
);
|
|
2312
|
+
let blockingStylesheets = 0;
|
|
2313
|
+
stylesheets.forEach((link) => {
|
|
2314
|
+
const media = link.getAttribute("media");
|
|
2315
|
+
if (!media || media === "all") blockingStylesheets++;
|
|
2316
|
+
});
|
|
2317
|
+
if (blockingStylesheets > 3) {
|
|
2318
|
+
results.push({
|
|
2319
|
+
ruleId: "meta-render-blocking",
|
|
2320
|
+
ruleName: "Render-Blocking Resources",
|
|
2321
|
+
message: `${blockingStylesheets} render-blocking stylesheets in <head> \u2014 consider inlining critical CSS`,
|
|
2322
|
+
severity: "INFO",
|
|
2323
|
+
category: "Performance",
|
|
2324
|
+
tier: "pro",
|
|
2325
|
+
fix: 'Inline critical CSS and load non-critical stylesheets asynchronously using media="print" with an onload handler.',
|
|
2326
|
+
data: { blockingStylesheets }
|
|
2327
|
+
});
|
|
2328
|
+
}
|
|
2329
|
+
return results;
|
|
2330
|
+
}
|
|
2331
|
+
};
|
|
2332
|
+
var lazyLoadLcpRule = {
|
|
2333
|
+
meta: {
|
|
2334
|
+
id: "lazy-load-lcp",
|
|
2335
|
+
name: "Lazy Load LCP",
|
|
2336
|
+
category: "Performance",
|
|
2337
|
+
tier: "pro",
|
|
2338
|
+
description: "Checks that above-the-fold images (likely LCP candidates) are not lazy-loaded"
|
|
2339
|
+
},
|
|
2340
|
+
run(context) {
|
|
2341
|
+
const { document } = context;
|
|
2342
|
+
const results = [];
|
|
2343
|
+
const images = document.querySelectorAll("img");
|
|
2344
|
+
const firstImages = Array.from(images).slice(0, 3);
|
|
2345
|
+
for (const img of firstImages) {
|
|
2346
|
+
const loading = img.getAttribute("loading");
|
|
2347
|
+
const fetchpriority = img.getAttribute("fetchpriority");
|
|
2348
|
+
if (loading === "lazy") {
|
|
2349
|
+
const src = img.getAttribute("src") || "";
|
|
2350
|
+
const alt = img.getAttribute("alt") || "";
|
|
2351
|
+
const identifier = alt ? `"${alt.substring(0, 40)}"` : src ? `src="${src.substring(0, 50)}"` : "first image";
|
|
2352
|
+
results.push({
|
|
2353
|
+
ruleId: "lazy-load-lcp",
|
|
2354
|
+
ruleName: "Lazy Load LCP",
|
|
2355
|
+
message: `Above-the-fold image (${identifier}) has loading="lazy" \u2014 this delays the Largest Contentful Paint`,
|
|
2356
|
+
severity: "WARNING",
|
|
2357
|
+
category: "Performance",
|
|
2358
|
+
tier: "pro",
|
|
2359
|
+
fix: 'Remove loading="lazy" from above-the-fold images. Add fetchpriority="high" to the LCP image instead.'
|
|
2360
|
+
});
|
|
2361
|
+
break;
|
|
2362
|
+
}
|
|
2363
|
+
if (!fetchpriority && !loading) {
|
|
2364
|
+
results.push({
|
|
2365
|
+
ruleId: "lazy-load-lcp",
|
|
2366
|
+
ruleName: "Lazy Load LCP",
|
|
2367
|
+
message: 'Consider adding fetchpriority="high" to your hero/banner image to improve Largest Contentful Paint',
|
|
2368
|
+
severity: "INFO",
|
|
2369
|
+
category: "Performance",
|
|
2370
|
+
tier: "pro",
|
|
2371
|
+
fix: 'Add fetchpriority="high" to the most important above-the-fold image to prioritize its loading.'
|
|
2372
|
+
});
|
|
2373
|
+
break;
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
return results;
|
|
2377
|
+
}
|
|
2378
|
+
};
|
|
2379
|
+
var httpsLinksRule = {
|
|
2380
|
+
meta: {
|
|
2381
|
+
id: "https-links",
|
|
2382
|
+
name: "HTTPS Links",
|
|
2383
|
+
category: "Pre-Launch",
|
|
2384
|
+
tier: "pro",
|
|
2385
|
+
description: "Checks that internal links use HTTPS instead of HTTP"
|
|
2386
|
+
},
|
|
2387
|
+
run(context) {
|
|
2388
|
+
const { document, url } = context;
|
|
2389
|
+
const results = [];
|
|
2390
|
+
let hostname;
|
|
2391
|
+
try {
|
|
2392
|
+
hostname = new URL(url).hostname;
|
|
2393
|
+
} catch {
|
|
2394
|
+
return results;
|
|
2395
|
+
}
|
|
2396
|
+
const links = document.querySelectorAll('a[href^="http:"]');
|
|
2397
|
+
let internalHttpLinks = 0;
|
|
2398
|
+
let externalHttpLinks = 0;
|
|
2399
|
+
links.forEach((link) => {
|
|
2400
|
+
const href = link.getAttribute("href");
|
|
2401
|
+
if (!href) return;
|
|
2402
|
+
try {
|
|
2403
|
+
const linkHostname = new URL(href).hostname;
|
|
2404
|
+
if (linkHostname === hostname) {
|
|
2405
|
+
internalHttpLinks++;
|
|
2406
|
+
} else {
|
|
2407
|
+
externalHttpLinks++;
|
|
2408
|
+
}
|
|
2409
|
+
} catch {
|
|
2410
|
+
}
|
|
2411
|
+
});
|
|
2412
|
+
if (internalHttpLinks > 0) {
|
|
2413
|
+
results.push({
|
|
2414
|
+
ruleId: "https-links",
|
|
2415
|
+
ruleName: "HTTPS Links",
|
|
2416
|
+
message: `${internalHttpLinks} internal link(s) use HTTP instead of HTTPS`,
|
|
2417
|
+
severity: "WARNING",
|
|
2418
|
+
category: "Pre-Launch",
|
|
2419
|
+
tier: "pro",
|
|
2420
|
+
fix: "Change all internal links from http:// to https:// to avoid redirect chains and mixed content warnings.",
|
|
2421
|
+
data: { internalHttpLinks }
|
|
2422
|
+
});
|
|
2423
|
+
}
|
|
2424
|
+
if (externalHttpLinks > 0) {
|
|
2425
|
+
results.push({
|
|
2426
|
+
ruleId: "https-links",
|
|
2427
|
+
ruleName: "HTTPS Links",
|
|
2428
|
+
message: `${externalHttpLinks} external link(s) use HTTP \u2014 consider updating to HTTPS where available`,
|
|
2429
|
+
severity: "INFO",
|
|
2430
|
+
category: "Pre-Launch",
|
|
2431
|
+
tier: "pro",
|
|
2432
|
+
fix: "Update external links to use https:// where the destination supports it.",
|
|
2433
|
+
data: { externalHttpLinks }
|
|
2434
|
+
});
|
|
2435
|
+
}
|
|
2436
|
+
return results;
|
|
2437
|
+
}
|
|
2438
|
+
};
|
|
2439
|
+
var metaRefreshRedirectRule = {
|
|
2440
|
+
meta: {
|
|
2441
|
+
id: "meta-refresh-redirect",
|
|
2442
|
+
name: "Meta Refresh Redirect",
|
|
2443
|
+
category: "SEO",
|
|
2444
|
+
tier: "pro",
|
|
2445
|
+
description: 'Checks for <meta http-equiv="refresh"> redirects which are bad for SEO'
|
|
2446
|
+
},
|
|
2447
|
+
run(context) {
|
|
2448
|
+
const { document } = context;
|
|
2449
|
+
const results = [];
|
|
2450
|
+
const metaRefresh = document.querySelector(
|
|
2451
|
+
'meta[http-equiv="refresh"]'
|
|
2452
|
+
);
|
|
2453
|
+
if (!metaRefresh) return results;
|
|
2454
|
+
const content = metaRefresh.getAttribute("content") || "";
|
|
2455
|
+
const hasUrl = content.toLowerCase().includes("url=");
|
|
2456
|
+
const delay = Number.parseInt(content.split(";")[0] || "", 10);
|
|
2457
|
+
if (hasUrl) {
|
|
2458
|
+
results.push({
|
|
2459
|
+
ruleId: "meta-refresh-redirect",
|
|
2460
|
+
ruleName: "Meta Refresh Redirect",
|
|
2461
|
+
message: `Page uses a meta refresh redirect${!Number.isNaN(delay) ? ` (${delay}s delay)` : ""} \u2014 use server-side 301 redirects instead`,
|
|
2462
|
+
severity: "WARNING",
|
|
2463
|
+
category: "SEO",
|
|
2464
|
+
tier: "pro",
|
|
2465
|
+
fix: 'Replace <meta http-equiv="refresh"> with a server-side 301 redirect. Meta refreshes are bad for SEO and user experience.',
|
|
2466
|
+
data: { content, delay: Number.isNaN(delay) ? void 0 : delay }
|
|
2467
|
+
});
|
|
2468
|
+
} else if (!Number.isNaN(delay) && delay > 0) {
|
|
2469
|
+
results.push({
|
|
2470
|
+
ruleId: "meta-refresh-redirect",
|
|
2471
|
+
ruleName: "Meta Refresh Redirect",
|
|
2472
|
+
message: `Page auto-refreshes every ${delay} seconds \u2014 this may cause usability issues`,
|
|
2473
|
+
severity: "INFO",
|
|
2474
|
+
category: "SEO",
|
|
2475
|
+
tier: "pro",
|
|
2476
|
+
fix: "Consider removing the auto-refresh meta tag unless it serves a clear user need.",
|
|
2477
|
+
data: { content, delay }
|
|
2478
|
+
});
|
|
2479
|
+
}
|
|
2480
|
+
return results;
|
|
2481
|
+
}
|
|
2482
|
+
};
|
|
2483
|
+
var nofollowAuditRule = {
|
|
2484
|
+
meta: {
|
|
2485
|
+
id: "nofollow-audit",
|
|
2486
|
+
name: "Nofollow Audit",
|
|
2487
|
+
category: "SEO",
|
|
2488
|
+
tier: "pro",
|
|
2489
|
+
description: 'Audits the use of rel="nofollow" on internal vs. external links'
|
|
2490
|
+
},
|
|
2491
|
+
run(context) {
|
|
2492
|
+
const { document, url } = context;
|
|
2493
|
+
const results = [];
|
|
2494
|
+
let hostname;
|
|
2495
|
+
try {
|
|
2496
|
+
hostname = new URL(url).hostname;
|
|
2497
|
+
} catch {
|
|
2498
|
+
return results;
|
|
2499
|
+
}
|
|
2500
|
+
const nofollowLinks = document.querySelectorAll('a[rel~="nofollow"]');
|
|
2501
|
+
let internalNofollow = 0;
|
|
2502
|
+
nofollowLinks.forEach((link) => {
|
|
2503
|
+
const href = link.getAttribute("href");
|
|
2504
|
+
if (!href) return;
|
|
2505
|
+
try {
|
|
2506
|
+
const linkHostname = new URL(href, url).hostname;
|
|
2507
|
+
if (linkHostname === hostname) internalNofollow++;
|
|
2508
|
+
} catch {
|
|
2509
|
+
if (href.startsWith("/") || href.startsWith(".")) {
|
|
2510
|
+
internalNofollow++;
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
});
|
|
2514
|
+
if (internalNofollow > 0) {
|
|
2515
|
+
results.push({
|
|
2516
|
+
ruleId: "nofollow-audit",
|
|
2517
|
+
ruleName: "Nofollow Audit",
|
|
2518
|
+
message: `${internalNofollow} internal link(s) have rel="nofollow" \u2014 this wastes PageRank and hurts internal linking`,
|
|
2519
|
+
severity: "WARNING",
|
|
2520
|
+
category: "SEO",
|
|
2521
|
+
tier: "pro",
|
|
2522
|
+
fix: 'Remove rel="nofollow" from internal links. Nofollow should only be used for external links you do not want to endorse (e.g., user-generated content, sponsored links).',
|
|
2523
|
+
data: { internalNofollow, totalNofollow: nofollowLinks.length }
|
|
2524
|
+
});
|
|
2525
|
+
}
|
|
2526
|
+
return results;
|
|
2527
|
+
}
|
|
2528
|
+
};
|
|
2529
|
+
var proRules = [
|
|
2530
|
+
// Ported — Pre-Launch
|
|
2531
|
+
sslRule,
|
|
2532
|
+
trackingRule,
|
|
2533
|
+
xRobotsTagRule,
|
|
2534
|
+
// Ported — Content / SEO
|
|
2535
|
+
thinContentRule,
|
|
2536
|
+
duplicateMetaRule,
|
|
2537
|
+
structuredDataRule,
|
|
2538
|
+
charsetRule,
|
|
2539
|
+
// Ported — Accessibility
|
|
2540
|
+
imageAltTextRule,
|
|
2541
|
+
accessibilityRule,
|
|
2542
|
+
semanticStructureRule,
|
|
2543
|
+
// Ported — Performance
|
|
2544
|
+
performanceRule,
|
|
2545
|
+
imageDimensionsRule,
|
|
2546
|
+
// Ported — Security
|
|
2547
|
+
mixedContentRule,
|
|
2548
|
+
securityHeadersRule,
|
|
2549
|
+
// New — Social
|
|
2550
|
+
ogImageSizeRule,
|
|
2551
|
+
ogImageTypeRule,
|
|
2552
|
+
twitterImageRule,
|
|
2553
|
+
socialPreviewRenderRule,
|
|
2554
|
+
// New — Content
|
|
2555
|
+
titleKeywordStuffingRule,
|
|
2556
|
+
contentToHtmlRatioRule,
|
|
2557
|
+
titleUniquenessRule,
|
|
2558
|
+
descriptionUniquenessRule,
|
|
2559
|
+
// New — Technical
|
|
2560
|
+
structuredDataValidateRule,
|
|
2561
|
+
hreflangRule,
|
|
2562
|
+
canonicalSelfReferencingRule,
|
|
2563
|
+
// New — Performance
|
|
2564
|
+
metaRenderBlockingRule,
|
|
2565
|
+
lazyLoadLcpRule,
|
|
2566
|
+
// New — Security / SEO
|
|
2567
|
+
httpsLinksRule,
|
|
2568
|
+
metaRefreshRedirectRule,
|
|
2569
|
+
nofollowAuditRule
|
|
2570
|
+
];
|
|
2571
|
+
var proStandaloneRules = [
|
|
2572
|
+
robotsTxtCheckRule,
|
|
2573
|
+
sitemapPresenceRule,
|
|
2574
|
+
ttfbRule
|
|
2575
|
+
];
|
|
2576
|
+
var PUBLIC_KEY_JWK = {
|
|
2577
|
+
kty: "OKP",
|
|
2578
|
+
crv: "Ed25519",
|
|
2579
|
+
x: "Q628CrspKqI_ig04oril9DaBhFaCJ2fJtoeFJhzrWek"
|
|
2580
|
+
};
|
|
2581
|
+
var cachedPublicKey = null;
|
|
2582
|
+
async function getPublicKey() {
|
|
2583
|
+
if (!cachedPublicKey) {
|
|
2584
|
+
cachedPublicKey = await jose.importJWK(PUBLIC_KEY_JWK, "EdDSA");
|
|
2585
|
+
}
|
|
2586
|
+
return cachedPublicKey;
|
|
2587
|
+
}
|
|
2588
|
+
async function validateLicense(token) {
|
|
2589
|
+
try {
|
|
2590
|
+
const publicKey = await getPublicKey();
|
|
2591
|
+
const { payload } = await jose.jwtVerify(token, publicKey, {
|
|
2592
|
+
algorithms: ["EdDSA"],
|
|
2593
|
+
issuer: "lintpage",
|
|
2594
|
+
audience: "lintpage-pro"
|
|
2595
|
+
});
|
|
2596
|
+
const licensePayload = {
|
|
2597
|
+
sub: payload.sub,
|
|
2598
|
+
plan: payload.plan,
|
|
2599
|
+
iat: payload.iat,
|
|
2600
|
+
exp: payload.exp
|
|
2601
|
+
};
|
|
2602
|
+
return { valid: true, payload: licensePayload };
|
|
2603
|
+
} catch (err) {
|
|
2604
|
+
const message = err instanceof Error ? err.message : "Invalid license key";
|
|
2605
|
+
return { valid: false, error: message };
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
var proPlugin = {
|
|
2609
|
+
name: "@lintpage/pro",
|
|
2610
|
+
rules: proRules,
|
|
2611
|
+
standaloneRules: proStandaloneRules
|
|
2612
|
+
};
|
|
2613
|
+
function loadProPlugin() {
|
|
2614
|
+
return proPlugin;
|
|
2615
|
+
}
|
|
10
2616
|
|
|
11
2617
|
// src/formatter.ts
|
|
12
2618
|
import chalk from "chalk";
|
|
@@ -129,8 +2735,8 @@ async function reportResults(result, options) {
|
|
|
129
2735
|
}
|
|
130
2736
|
|
|
131
2737
|
// src/cli.ts
|
|
132
|
-
import { writeFileSync, readFileSync, existsSync } from "fs";
|
|
133
|
-
import { join } from "path";
|
|
2738
|
+
import { writeFileSync, readFileSync as readFileSync2, existsSync as existsSync2 } from "fs";
|
|
2739
|
+
import { join as join2 } from "path";
|
|
134
2740
|
var cli = cac("lintpage");
|
|
135
2741
|
var EXIT_PASS = 0;
|
|
136
2742
|
var EXIT_FAIL = 1;
|
|
@@ -224,8 +2830,8 @@ cli.command("<url>", "Run an audit on a URL").option("--format <format>", "Outpu
|
|
|
224
2830
|
}
|
|
225
2831
|
});
|
|
226
2832
|
cli.command("init", "Generate a .lintpagerc.json config file").action(() => {
|
|
227
|
-
const configPath =
|
|
228
|
-
if (
|
|
2833
|
+
const configPath = join2(process.cwd(), ".lintpagerc.json");
|
|
2834
|
+
if (existsSync2(configPath)) {
|
|
229
2835
|
console.log(chalk2.yellow(".lintpagerc.json already exists"));
|
|
230
2836
|
process.exit(EXIT_PASS);
|
|
231
2837
|
}
|
|
@@ -235,8 +2841,8 @@ cli.command("init", "Generate a .lintpagerc.json config file").action(() => {
|
|
|
235
2841
|
process.exit(EXIT_PASS);
|
|
236
2842
|
});
|
|
237
2843
|
cli.help();
|
|
238
|
-
var pkgPath =
|
|
239
|
-
var pkgJson =
|
|
2844
|
+
var pkgPath = join2(__dirname, "..", "package.json");
|
|
2845
|
+
var pkgJson = existsSync2(pkgPath) ? JSON.parse(readFileSync2(pkgPath, "utf-8")) : { version: "0.0.0" };
|
|
240
2846
|
cli.version(pkgJson.version);
|
|
241
2847
|
cli.parse();
|
|
242
2848
|
//# sourceMappingURL=cli.mjs.map
|