@jay-framework/seo-validator 0.25.5 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tools.d.ts +9 -2
- package/dist/tools.js +181 -1
- package/package.json +10 -7
- package/plugin.yaml +5 -0
package/dist/tools.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import { JayHtmlValidatorFn } from '@jay-framework/compiler-shared';
|
|
1
|
+
import { JayHtmlValidatorFn, ProjectValidatorFn } from '@jay-framework/compiler-shared';
|
|
2
2
|
|
|
3
3
|
declare const validate: JayHtmlValidatorFn;
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Project-level SEO/discovery checks (DL#232, moved out of core `validate.ts`): robots.txt presence,
|
|
7
|
+
* site.baseUrl / site.name (DL#175/#213), and ARD presence + shape (DL#214). Decision C: the context
|
|
8
|
+
* is only `{ projectRoot }`, so `.jay` config is read here, not passed in.
|
|
9
|
+
*/
|
|
10
|
+
declare const validateProject: ProjectValidatorFn;
|
|
11
|
+
|
|
12
|
+
export { validate, validateProject };
|
package/dist/tools.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { walkElements } from "@jay-framework/compiler-shared";
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
+
import fs$1, { promises } from "fs";
|
|
5
|
+
import path$1 from "path";
|
|
6
|
+
import { parse } from "yaml";
|
|
4
7
|
function isComponent(filePath) {
|
|
5
8
|
const normalized = filePath.replace(/\\/g, "/");
|
|
6
9
|
return normalized.includes("/components/");
|
|
@@ -274,6 +277,183 @@ const validate = (ctx) => {
|
|
|
274
277
|
}
|
|
275
278
|
return findings;
|
|
276
279
|
};
|
|
280
|
+
const URN_PATTERN = /^urn:air:[^:\s]+:[^:\s]+:[^:\s]+$/;
|
|
281
|
+
const MEDIA_TYPE_PATTERN = /^[a-z]+\/[A-Za-z0-9.+-]+$/;
|
|
282
|
+
const ARD_SUGGEST = "See developer/seo-guide.md (ARD v0.91) for the schema and a worked example.";
|
|
283
|
+
function validateArdDocument(doc) {
|
|
284
|
+
const findings = [];
|
|
285
|
+
if (!doc || typeof doc !== "object") {
|
|
286
|
+
return [
|
|
287
|
+
{
|
|
288
|
+
message: "ard.json must be a JSON object with an `entries` array.",
|
|
289
|
+
severity: "error",
|
|
290
|
+
suggestion: ARD_SUGGEST
|
|
291
|
+
}
|
|
292
|
+
];
|
|
293
|
+
}
|
|
294
|
+
const entries = doc.entries;
|
|
295
|
+
if (!Array.isArray(entries)) {
|
|
296
|
+
return [
|
|
297
|
+
{
|
|
298
|
+
message: "ard.json is missing the required `entries` array.",
|
|
299
|
+
severity: "error",
|
|
300
|
+
suggestion: ARD_SUGGEST
|
|
301
|
+
}
|
|
302
|
+
];
|
|
303
|
+
}
|
|
304
|
+
entries.forEach((entry, i) => {
|
|
305
|
+
const at = `ard.json entries[${i}]`;
|
|
306
|
+
if (!entry || typeof entry !== "object") {
|
|
307
|
+
findings.push({ message: `${at} must be an object.`, severity: "error" });
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (typeof entry.identifier !== "string" || !URN_PATTERN.test(entry.identifier)) {
|
|
311
|
+
findings.push({
|
|
312
|
+
message: `${at}.identifier must match urn:air:<publisher>:<namespace>:<name>.`,
|
|
313
|
+
severity: "error",
|
|
314
|
+
suggestion: ARD_SUGGEST
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
if (typeof entry.displayName !== "string" || entry.displayName.trim() === "") {
|
|
318
|
+
findings.push({
|
|
319
|
+
message: `${at}.displayName is required.`,
|
|
320
|
+
severity: "error"
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
if (typeof entry.type !== "string" || !MEDIA_TYPE_PATTERN.test(entry.type)) {
|
|
324
|
+
findings.push({
|
|
325
|
+
message: `${at}.type must be an IANA media type (e.g. application/mcp-server-card+json).`,
|
|
326
|
+
severity: "error"
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
const hasUrl = entry.url !== void 0;
|
|
330
|
+
const hasData = entry.data !== void 0;
|
|
331
|
+
if (hasUrl === hasData) {
|
|
332
|
+
findings.push({
|
|
333
|
+
message: `${at} must have exactly one of \`url\` or \`data\`.`,
|
|
334
|
+
severity: "error"
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
const rq = entry.representativeQueries;
|
|
338
|
+
if (rq === void 0) {
|
|
339
|
+
findings.push({
|
|
340
|
+
message: `${at} is missing representativeQueries (2–5 recommended) — agents may not surface this resource.`,
|
|
341
|
+
severity: "warning",
|
|
342
|
+
suggestion: ARD_SUGGEST
|
|
343
|
+
});
|
|
344
|
+
} else if (!Array.isArray(rq) || rq.length < 2 || rq.length > 5) {
|
|
345
|
+
findings.push({
|
|
346
|
+
message: `${at}.representativeQueries should list 2–5 example queries.`,
|
|
347
|
+
severity: "warning"
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
return findings;
|
|
352
|
+
}
|
|
353
|
+
async function checkArdFiles(projectRoot) {
|
|
354
|
+
const wellKnown = path$1.resolve(projectRoot, "public/.well-known");
|
|
355
|
+
const ardPath = path$1.join(wellKnown, "ard.json");
|
|
356
|
+
const aliasPath = path$1.join(wellKnown, "ai-catalog.json");
|
|
357
|
+
const ardRaw = await readIfExists(ardPath);
|
|
358
|
+
const aliasRaw = await readIfExists(aliasPath);
|
|
359
|
+
if (ardRaw === null && aliasRaw === null) {
|
|
360
|
+
return { findings: [], absent: true };
|
|
361
|
+
}
|
|
362
|
+
const findings = [];
|
|
363
|
+
if (ardRaw === null && aliasRaw !== null) {
|
|
364
|
+
findings.push({
|
|
365
|
+
message: "Only public/.well-known/ai-catalog.json found — ARD renamed this to ard.json. Add ard.json (keep ai-catalog.json as a copy for older clients).",
|
|
366
|
+
severity: "warning",
|
|
367
|
+
suggestion: ARD_SUGGEST
|
|
368
|
+
});
|
|
369
|
+
} else if (ardRaw !== null && aliasRaw !== null && ardRaw.trim() !== aliasRaw.trim()) {
|
|
370
|
+
findings.push({
|
|
371
|
+
message: "public/.well-known/ard.json and ai-catalog.json differ — the alias should be a copy of ard.json.",
|
|
372
|
+
severity: "warning"
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
const canonicalRaw = ardRaw ?? aliasRaw;
|
|
376
|
+
let parsed;
|
|
377
|
+
try {
|
|
378
|
+
parsed = JSON.parse(canonicalRaw);
|
|
379
|
+
} catch (e) {
|
|
380
|
+
findings.push({
|
|
381
|
+
message: `${ardRaw !== null ? "ard.json" : "ai-catalog.json"} is not valid JSON: ${e.message}`,
|
|
382
|
+
severity: "error"
|
|
383
|
+
});
|
|
384
|
+
return { findings, absent: false };
|
|
385
|
+
}
|
|
386
|
+
findings.push(...validateArdDocument(parsed));
|
|
387
|
+
return { findings, absent: false };
|
|
388
|
+
}
|
|
389
|
+
async function readIfExists(p) {
|
|
390
|
+
try {
|
|
391
|
+
return await promises.readFile(p, "utf8");
|
|
392
|
+
} catch {
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
function readJayConfig(projectRoot) {
|
|
397
|
+
const configPath = path$1.join(projectRoot, ".jay");
|
|
398
|
+
try {
|
|
399
|
+
const parsed = parse(fs$1.readFileSync(configPath, "utf-8")) ?? {};
|
|
400
|
+
return { site: parsed.site, validations: parsed.validations };
|
|
401
|
+
} catch {
|
|
402
|
+
return {};
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
const validateProject = async (ctx) => {
|
|
406
|
+
const { projectRoot } = ctx;
|
|
407
|
+
const findings = [];
|
|
408
|
+
if (!fs$1.existsSync(path$1.resolve(projectRoot, "public/robots.txt"))) {
|
|
409
|
+
findings.push({
|
|
410
|
+
severity: "warning",
|
|
411
|
+
file: "public/robots.txt",
|
|
412
|
+
message: "public/robots.txt not found — search engines may crawl pages you don't intend to expose.",
|
|
413
|
+
suggestion: "Create public/robots.txt with: User-agent: *\nAllow: /\nSitemap: https://your-domain.com/sitemap.xml"
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
const config = readJayConfig(projectRoot);
|
|
417
|
+
if (!config.site?.baseUrl) {
|
|
418
|
+
findings.push({
|
|
419
|
+
severity: "warning",
|
|
420
|
+
file: ".jay",
|
|
421
|
+
message: "site.baseUrl not configured — sitemap.xml will not be generated in production.",
|
|
422
|
+
suggestion: "Add to .jay config:\n site:\n baseUrl: https://your-domain.com"
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
if (!config.site?.name) {
|
|
426
|
+
findings.push({
|
|
427
|
+
severity: "warning",
|
|
428
|
+
file: ".jay",
|
|
429
|
+
message: "site.name not configured — Organization/WebSite JSON-LD and llms.txt will not be emitted, reducing how well search engines and agents understand the site.",
|
|
430
|
+
suggestion: "Add to .jay config:\n site:\n name: Your Site Name\n logo: /logo.png\n description: What your site is about"
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
const allowNoArd = config.validations?.["allow-no-ard"] === true;
|
|
434
|
+
const ardResult = await checkArdFiles(projectRoot);
|
|
435
|
+
if (ardResult.absent) {
|
|
436
|
+
if (!allowNoArd) {
|
|
437
|
+
findings.push({
|
|
438
|
+
severity: "warning",
|
|
439
|
+
file: "public/.well-known/ard.json",
|
|
440
|
+
message: "public/.well-known/ard.json not found — agents cannot discover this site’s resources/APIs via Agentic Resource Discovery.",
|
|
441
|
+
suggestion: "Author public/.well-known/ard.json (ARD v0.91), or suppress with `validations: { allow-no-ard: true }` in .jay if the site has no agent resources to advertise. See developer/seo-guide.md."
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
} else {
|
|
445
|
+
for (const finding of ardResult.findings) {
|
|
446
|
+
findings.push({
|
|
447
|
+
severity: finding.severity,
|
|
448
|
+
file: "public/.well-known/ard.json",
|
|
449
|
+
message: finding.message,
|
|
450
|
+
suggestion: finding.suggestion
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return findings;
|
|
455
|
+
};
|
|
277
456
|
export {
|
|
278
|
-
validate
|
|
457
|
+
validate,
|
|
458
|
+
validateProject
|
|
279
459
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/seo-validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "SEO validation plugin for Jay Framework — checks jay-html templates for SEO best practices",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -25,18 +25,21 @@
|
|
|
25
25
|
"test": "vitest run"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@jay-framework/compiler-shared": "^0.
|
|
28
|
+
"@jay-framework/compiler-shared": "^0.26.0"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"yaml": "^2.3.4"
|
|
29
32
|
},
|
|
30
33
|
"devDependencies": {
|
|
31
|
-
"@jay-framework/compiler-shared": "^0.
|
|
32
|
-
"@jay-framework/dev-environment": "^0.
|
|
33
|
-
"@jay-framework/jay-stack-cli": "^0.
|
|
34
|
+
"@jay-framework/compiler-shared": "^0.26.0",
|
|
35
|
+
"@jay-framework/dev-environment": "^0.26.0",
|
|
36
|
+
"@jay-framework/jay-stack-cli": "^0.26.0",
|
|
34
37
|
"@types/node": "^22.15.21",
|
|
35
38
|
"node-html-parser": "^6.1.0",
|
|
36
39
|
"rimraf": "^5.0.5",
|
|
37
40
|
"tsup": "^8.0.1",
|
|
38
41
|
"typescript": "^5.3.3",
|
|
39
|
-
"vite": "^
|
|
40
|
-
"vitest": "^1.
|
|
42
|
+
"vite": "^6.4.4",
|
|
43
|
+
"vitest": "^4.1.11"
|
|
41
44
|
}
|
|
42
45
|
}
|
package/plugin.yaml
CHANGED
|
@@ -4,3 +4,8 @@ validators:
|
|
|
4
4
|
- name: seo
|
|
5
5
|
handler: validate
|
|
6
6
|
description: Validates jay-html templates for SEO best practices
|
|
7
|
+
|
|
8
|
+
projectValidators:
|
|
9
|
+
- name: seo-site
|
|
10
|
+
handler: validateProject
|
|
11
|
+
description: robots.txt, site.baseUrl, site.name, and ARD (/.well-known/ard.json) checks
|