@duffcloudservices/cms 0.13.13 → 0.14.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/README.md +59 -0
- package/dist/{chunk-P6HQW635.js → chunk-56RSSOAM.js} +3 -3
- package/dist/{chunk-P6HQW635.js.map → chunk-56RSSOAM.js.map} +1 -1
- package/dist/{chunk-JWXI5HAZ.js → chunk-CJATCOZJ.js} +198 -33
- package/dist/chunk-CJATCOZJ.js.map +1 -0
- package/dist/{headHonesty-OzxvLuwd.d.ts → headHonesty-k1IhGblP.d.ts} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/{installSeoHead-CuVdVCis.d.ts → installSeoHead-CcNfcxNF.d.ts} +2 -2
- package/dist/plugins/index.d.ts +355 -5
- package/dist/plugins/index.js +941 -190
- package/dist/plugins/index.js.map +1 -1
- package/dist/seo/index.d.ts +6 -6
- package/dist/seo/index.js +2 -2
- package/dist/{vitepressTransform-CZ_IB3dq.d.ts → vitepressTransform-CQXBpYEC.d.ts} +198 -20
- package/package.json +5 -4
- package/dist/chunk-JWXI5HAZ.js.map +0 -1
package/dist/plugins/index.js
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import { buildSitemapXml, isHandAuthoredRobotsAcceptable, buildRobotsTxt, buildLlmsTxt, routeExclusionReason, breadcrumbTrailFromRoute, findReviewItemsForPage, findBusinessLicense, buildHeadTags, spliceHeadHtml, routeToOutputFile, loadPagesManifest, hoistCharsetMeta, checkCharsetBudget, findPostalAddressGaps, formatPostalAddressGapReport, isBodyPrerenderEnabled, resolveHonestyMode, assertHeadHonestyExecuted, findHeadHonestyViolations, assertHeadHonesty, isRouteEmitted, findDuplicateNormalizedPaths, formatDuplicateNormalizedPaths, prerenderBodies, CharsetBudgetError, formatCharsetHeadroomWarning, dedupeUrls, collectEmittedUrlsFromFiles, classifyUrl, auditSameOriginAssets, checkRemoteAssets, auditCheckedTotal, EmittedUrlNotRunError, formatEmittedUrlAudit, formatEmittedUrlReport, EmittedUrlError } from '../chunk-
|
|
2
|
-
export { buildVitePressSeoHead, createSeoTransformPageData, defaultRelativePathToRoute } from '../chunk-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { buildSitemapXml, isHandAuthoredRobotsAcceptable, findAiTrainingRobotsConflicts, RobotsAiTrainingConflictError, appendAiTrainingOptOut, buildRobotsTxt, buildLlmsTxt, routeExclusionReason, breadcrumbTrailFromRoute, findReviewItemsForPage, findBusinessLicense, buildHeadTags, spliceHeadHtml, routeToOutputFile, loadPagesManifest, hoistCharsetMeta, checkCharsetBudget, findPostalAddressGaps, formatPostalAddressGapReport, isBodyPrerenderEnabled, resolveHonestyMode, assertHeadHonestyExecuted, findHeadHonestyViolations, assertHeadHonesty, isRouteEmitted, findDuplicateNormalizedPaths, formatDuplicateNormalizedPaths, prerenderBodies, CharsetBudgetError, formatCharsetHeadroomWarning, dedupeUrls, collectEmittedUrlsFromFiles, classifyUrl, auditSameOriginAssets, checkRemoteAssets, auditCheckedTotal, EmittedUrlNotRunError, formatEmittedUrlAudit, formatEmittedUrlReport, EmittedUrlError } from '../chunk-CJATCOZJ.js';
|
|
2
|
+
export { buildVitePressSeoHead, createSeoTransformPageData, defaultRelativePathToRoute } from '../chunk-CJATCOZJ.js';
|
|
3
|
+
import fs8 from 'fs';
|
|
4
|
+
import path7 from 'path';
|
|
5
|
+
import yaml5 from 'js-yaml';
|
|
6
|
+
import crypto from 'crypto';
|
|
6
7
|
import http from 'http';
|
|
8
|
+
import { execFileSync } from 'child_process';
|
|
9
|
+
import { builtinModules } from 'module';
|
|
7
10
|
import { defineComponent, h } from 'vue';
|
|
8
11
|
import { isVectorImageUrl } from '@duffcloudservices/cms-core';
|
|
9
12
|
|
|
10
13
|
function dcsSearchPaths(projectRoot, relPath) {
|
|
11
14
|
return [
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
path7.resolve(projectRoot, relPath),
|
|
16
|
+
path7.resolve(projectRoot, "..", relPath),
|
|
17
|
+
path7.resolve(process.cwd(), relPath)
|
|
15
18
|
];
|
|
16
19
|
}
|
|
17
20
|
function resolveDcsFile(projectRoot, relPath) {
|
|
18
|
-
return dcsSearchPaths(projectRoot, relPath).find((p) =>
|
|
21
|
+
return dcsSearchPaths(projectRoot, relPath).find((p) => fs8.existsSync(p));
|
|
19
22
|
}
|
|
20
23
|
function readDcsYamlFresh(projectRoot, relPath, label, debug = false) {
|
|
21
24
|
const found = resolveDcsFile(projectRoot, relPath);
|
|
@@ -24,7 +27,7 @@ function readDcsYamlFresh(projectRoot, relPath, label, debug = false) {
|
|
|
24
27
|
return void 0;
|
|
25
28
|
}
|
|
26
29
|
try {
|
|
27
|
-
return
|
|
30
|
+
return yaml5.load(fs8.readFileSync(found, "utf8"));
|
|
28
31
|
} catch (error) {
|
|
29
32
|
console.warn(`[${label}] serve: failed to parse ${relPath}:`, error);
|
|
30
33
|
return void 0;
|
|
@@ -97,13 +100,13 @@ function readSiteSlug(projectRoot) {
|
|
|
97
100
|
}
|
|
98
101
|
function readSiteYaml(projectRoot) {
|
|
99
102
|
const candidates = [
|
|
100
|
-
...SITE_YAML_CANDIDATES.map((rel) =>
|
|
101
|
-
|
|
103
|
+
...SITE_YAML_CANDIDATES.map((rel) => path7.resolve(projectRoot, rel)),
|
|
104
|
+
path7.resolve(process.cwd(), ".dcs/site.yaml")
|
|
102
105
|
];
|
|
103
106
|
for (const candidate of candidates) {
|
|
104
107
|
try {
|
|
105
|
-
if (!
|
|
106
|
-
const parsed =
|
|
108
|
+
if (!fs8.existsSync(candidate)) continue;
|
|
109
|
+
const parsed = yaml5.load(fs8.readFileSync(candidate, "utf8"));
|
|
107
110
|
const slug = parsed && typeof parsed.site_slug === "string" ? parsed.site_slug.trim() : "";
|
|
108
111
|
if (parsed && slug) return { slug, fields: parsed };
|
|
109
112
|
} catch {
|
|
@@ -165,13 +168,13 @@ function dcsContentPlugin(options = {}) {
|
|
|
165
168
|
}
|
|
166
169
|
const projectRoot = config2.root || process.cwd();
|
|
167
170
|
const possiblePaths = [
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
+
path7.resolve(projectRoot, contentPath),
|
|
172
|
+
path7.resolve(projectRoot, "..", contentPath),
|
|
173
|
+
path7.resolve(process.cwd(), contentPath)
|
|
171
174
|
];
|
|
172
175
|
let foundPath;
|
|
173
176
|
for (const testPath of possiblePaths) {
|
|
174
|
-
if (
|
|
177
|
+
if (fs8.existsSync(testPath)) {
|
|
175
178
|
foundPath = testPath;
|
|
176
179
|
break;
|
|
177
180
|
}
|
|
@@ -190,8 +193,8 @@ function dcsContentPlugin(options = {}) {
|
|
|
190
193
|
};
|
|
191
194
|
}
|
|
192
195
|
try {
|
|
193
|
-
const fileContent =
|
|
194
|
-
const content =
|
|
196
|
+
const fileContent = fs8.readFileSync(foundPath, "utf8");
|
|
197
|
+
const content = yaml5.load(fileContent);
|
|
195
198
|
if (debug) {
|
|
196
199
|
console.log(`[dcs-content] Loaded ${foundPath}`);
|
|
197
200
|
console.log(`[dcs-content] Version: ${content.version}`);
|
|
@@ -281,17 +284,17 @@ function dcsContentPlugin(options = {}) {
|
|
|
281
284
|
configureServer(server) {
|
|
282
285
|
const projectRoot = resolvedConfig?.root || process.cwd();
|
|
283
286
|
const watchPaths = [
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
].map((p) =>
|
|
287
|
+
path7.resolve(projectRoot, contentPath),
|
|
288
|
+
path7.resolve(projectRoot, "..", contentPath)
|
|
289
|
+
].map((p) => path7.normalize(p));
|
|
287
290
|
watchPaths.forEach((watchPath) => {
|
|
288
|
-
if (
|
|
291
|
+
if (fs8.existsSync(watchPath)) {
|
|
289
292
|
server.watcher.add(watchPath);
|
|
290
293
|
}
|
|
291
294
|
});
|
|
292
295
|
let reloadTimer;
|
|
293
296
|
server.watcher.on("change", (changedPath) => {
|
|
294
|
-
if (!watchPaths.includes(
|
|
297
|
+
if (!watchPaths.includes(path7.normalize(changedPath))) return;
|
|
295
298
|
if (reloadTimer) clearTimeout(reloadTimer);
|
|
296
299
|
reloadTimer = setTimeout(() => {
|
|
297
300
|
if (debug) {
|
|
@@ -303,6 +306,266 @@ function dcsContentPlugin(options = {}) {
|
|
|
303
306
|
}
|
|
304
307
|
};
|
|
305
308
|
}
|
|
309
|
+
var BASE_CDN_ASSET = /^https?:\/\/files\.[^/]+\/(?:content\/)?[^/]+\/assets\/(?:[^/]+\/)*[a-f0-9-]+\.\w+(?:[?#].*)?$/i;
|
|
310
|
+
function isFullSizeCdnUrl(url) {
|
|
311
|
+
return BASE_CDN_ASSET.test(url.trim());
|
|
312
|
+
}
|
|
313
|
+
function readAttr(tag, name) {
|
|
314
|
+
const m = tag.match(new RegExp(`\\b${name}=("([^"]*)"|'([^']*)')`, "i"));
|
|
315
|
+
if (!m) return null;
|
|
316
|
+
return m[2] ?? m[3] ?? "";
|
|
317
|
+
}
|
|
318
|
+
function findFullSizeCdnImages(html) {
|
|
319
|
+
const violations = [];
|
|
320
|
+
for (const m of html.matchAll(/<img\b[^>]*>/gi)) {
|
|
321
|
+
const src = readAttr(m[0], "src");
|
|
322
|
+
if (src && isFullSizeCdnUrl(src)) {
|
|
323
|
+
violations.push({ url: src.trim(), tag: "img" });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
for (const m of html.matchAll(/<source\b[^>]*>/gi)) {
|
|
327
|
+
const srcset = readAttr(m[0], "srcset");
|
|
328
|
+
if (!srcset) continue;
|
|
329
|
+
for (const candidate of srcset.split(",")) {
|
|
330
|
+
const url = candidate.trim().split(/\s+/)[0];
|
|
331
|
+
if (url && isFullSizeCdnUrl(url)) {
|
|
332
|
+
violations.push({ url, tag: "source" });
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return violations;
|
|
337
|
+
}
|
|
338
|
+
function dcsResponsiveImageLint(options = {}) {
|
|
339
|
+
const { failOnViolation = false, extensions = [".html"], debug = false } = options;
|
|
340
|
+
return async (siteConfig) => {
|
|
341
|
+
const report = { filesScanned: 0, violations: [] };
|
|
342
|
+
const outDir = siteConfig.outDir;
|
|
343
|
+
if (!outDir || !fs8.existsSync(outDir)) return report;
|
|
344
|
+
const walk = (dir) => {
|
|
345
|
+
for (const entry of fs8.readdirSync(dir, { withFileTypes: true })) {
|
|
346
|
+
const full = path7.join(dir, entry.name);
|
|
347
|
+
if (entry.isDirectory()) {
|
|
348
|
+
walk(full);
|
|
349
|
+
} else if (extensions.some((ext) => entry.name.endsWith(ext))) {
|
|
350
|
+
report.filesScanned++;
|
|
351
|
+
const html = fs8.readFileSync(full, "utf8");
|
|
352
|
+
if (!html.includes("/assets/")) continue;
|
|
353
|
+
const rel = path7.relative(outDir, full);
|
|
354
|
+
for (const v of findFullSizeCdnImages(html)) {
|
|
355
|
+
report.violations.push({ ...v, file: rel });
|
|
356
|
+
if (debug) {
|
|
357
|
+
console.log(`[dcs-responsive-lint] ${rel}: <${v.tag}> full-size ${v.url}`);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
walk(outDir);
|
|
364
|
+
if (report.violations.length > 0) {
|
|
365
|
+
const lines = report.violations.map((v) => ` ${v.file}: <${v.tag}> ${v.url}`).join("\n");
|
|
366
|
+
const summary = `[dcs-responsive-lint] ${report.violations.length} full-size CDN image(s) shipped without a -sm/-md/-lg responsive variant across ${report.filesScanned} file(s):
|
|
367
|
+
${lines}`;
|
|
368
|
+
if (failOnViolation) {
|
|
369
|
+
throw new Error(summary);
|
|
370
|
+
}
|
|
371
|
+
console.warn(summary);
|
|
372
|
+
} else if (debug) {
|
|
373
|
+
console.log(
|
|
374
|
+
`[dcs-responsive-lint] clean \u2014 scanned ${report.filesScanned} file(s), no full-size images.`
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
return report;
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
function chainBuildEnd(...hooks) {
|
|
381
|
+
const active = hooks.filter(
|
|
382
|
+
(h2) => typeof h2 === "function"
|
|
383
|
+
);
|
|
384
|
+
return async (siteConfig) => {
|
|
385
|
+
for (const hook of active) {
|
|
386
|
+
await hook(siteConfig);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// src/plugins/dcsDirIndex.ts
|
|
392
|
+
var DIR_INDEX_INSTALLED = /* @__PURE__ */ Symbol.for("dcs.cms.dirIndex.installed");
|
|
393
|
+
var DIR_INDEX_MANIFEST_ENV = "DCS_DIR_INDEX_MANIFEST";
|
|
394
|
+
var DIR_INDEX_MANIFEST_SCHEMA = "dcs.cms.dir-index-manifest/v1";
|
|
395
|
+
var INDEX_PAGE = /(^|\/)index\.md$/;
|
|
396
|
+
var DirIndexError = class extends Error {
|
|
397
|
+
constructor(message) {
|
|
398
|
+
super(message);
|
|
399
|
+
this.name = "DirIndexError";
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
function dirIndexCandidates(siteConfig) {
|
|
403
|
+
const map = siteConfig.rewrites?.map ?? {};
|
|
404
|
+
const out = [];
|
|
405
|
+
for (const page of siteConfig.pages) {
|
|
406
|
+
const mapped = (map[page] || page).replace(/\\/g, "/");
|
|
407
|
+
if (!mapped.endsWith(".md")) continue;
|
|
408
|
+
if (INDEX_PAGE.test(mapped)) continue;
|
|
409
|
+
if (mapped === "404.md") continue;
|
|
410
|
+
out.push(mapped);
|
|
411
|
+
}
|
|
412
|
+
return [...new Set(out)].sort();
|
|
413
|
+
}
|
|
414
|
+
function resolveManifestPath(options) {
|
|
415
|
+
const raw = options.manifestPath ?? process.env[DIR_INDEX_MANIFEST_ENV];
|
|
416
|
+
return raw ? path7.resolve(raw) : void 0;
|
|
417
|
+
}
|
|
418
|
+
function realpathNearest(p) {
|
|
419
|
+
let cur = path7.resolve(p);
|
|
420
|
+
const tail = [];
|
|
421
|
+
while (!fs8.existsSync(cur)) {
|
|
422
|
+
const parent = path7.dirname(cur);
|
|
423
|
+
if (parent === cur) break;
|
|
424
|
+
tail.unshift(path7.basename(cur));
|
|
425
|
+
cur = parent;
|
|
426
|
+
}
|
|
427
|
+
let real = cur;
|
|
428
|
+
try {
|
|
429
|
+
real = fs8.realpathSync.native(cur);
|
|
430
|
+
} catch {
|
|
431
|
+
}
|
|
432
|
+
return path7.join(real, ...tail);
|
|
433
|
+
}
|
|
434
|
+
function isInsideDir(dir, p) {
|
|
435
|
+
const abs = path7.resolve(p);
|
|
436
|
+
const dest = path7.join(realpathNearest(path7.dirname(abs)), path7.basename(abs));
|
|
437
|
+
const rel = path7.relative(realpathNearest(dir), dest);
|
|
438
|
+
if (rel === "") return true;
|
|
439
|
+
if (path7.isAbsolute(rel)) return false;
|
|
440
|
+
return !(rel === ".." || rel.startsWith(".." + path7.sep));
|
|
441
|
+
}
|
|
442
|
+
function clearDirIndexManifest(manifestPath = process.env[DIR_INDEX_MANIFEST_ENV]) {
|
|
443
|
+
if (!manifestPath) return void 0;
|
|
444
|
+
const file = path7.resolve(manifestPath);
|
|
445
|
+
try {
|
|
446
|
+
const st = fs8.lstatSync(file);
|
|
447
|
+
if (!st.isFile() && !st.isSymbolicLink()) return void 0;
|
|
448
|
+
} catch {
|
|
449
|
+
return void 0;
|
|
450
|
+
}
|
|
451
|
+
fs8.unlinkSync(file);
|
|
452
|
+
return file;
|
|
453
|
+
}
|
|
454
|
+
var sha256 = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex");
|
|
455
|
+
function writeManifest(file, manifest) {
|
|
456
|
+
fs8.mkdirSync(path7.dirname(file), { recursive: true });
|
|
457
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
458
|
+
fs8.writeFileSync(tmp, `${JSON.stringify(manifest, null, 2)}
|
|
459
|
+
`);
|
|
460
|
+
fs8.renameSync(tmp, file);
|
|
461
|
+
}
|
|
462
|
+
function emitDirectoryIndexes(siteConfig, options = {}) {
|
|
463
|
+
const outDir = siteConfig.outDir;
|
|
464
|
+
const manifestPath = resolveManifestPath(options);
|
|
465
|
+
if (manifestPath) {
|
|
466
|
+
if (isInsideDir(outDir, manifestPath)) {
|
|
467
|
+
throw new DirIndexError(
|
|
468
|
+
`[dcs-dir-index] ${DIR_INDEX_MANIFEST_ENV}=${manifestPath} is inside outDir ${outDir}; the manifest must not ship with the site. Point it outside the build output.`
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
fs8.rmSync(manifestPath, { force: true });
|
|
472
|
+
}
|
|
473
|
+
if (siteConfig.cleanUrls !== true) {
|
|
474
|
+
if (!manifestPath) return { written: 0, identical: 0, twins: [] };
|
|
475
|
+
writeManifest(manifestPath, { schema: DIR_INDEX_MANIFEST_SCHEMA, outDir: path7.resolve(outDir), cleanUrls: false, twins: [] });
|
|
476
|
+
return { written: 0, identical: 0, twins: [], manifestPath };
|
|
477
|
+
}
|
|
478
|
+
const missing = [];
|
|
479
|
+
const unequal = [];
|
|
480
|
+
const toWrite = [];
|
|
481
|
+
const identicalRel = [];
|
|
482
|
+
const entries = [];
|
|
483
|
+
for (const page of dirIndexCandidates(siteConfig)) {
|
|
484
|
+
const stem = page.slice(0, -".md".length);
|
|
485
|
+
const srcRel = `${stem}.html`;
|
|
486
|
+
const dstRel = `${stem}/index.html`;
|
|
487
|
+
const src = path7.join(outDir, srcRel);
|
|
488
|
+
const dst = path7.join(outDir, dstRel);
|
|
489
|
+
if (!fs8.existsSync(src) || !fs8.statSync(src).isFile()) {
|
|
490
|
+
missing.push(`${page} -> ${srcRel}`);
|
|
491
|
+
continue;
|
|
492
|
+
}
|
|
493
|
+
const bytes = fs8.readFileSync(src);
|
|
494
|
+
if (fs8.existsSync(dst)) {
|
|
495
|
+
const existing = fs8.statSync(dst).isFile() ? fs8.readFileSync(dst) : null;
|
|
496
|
+
if (existing && existing.equals(bytes)) {
|
|
497
|
+
identicalRel.push(dstRel);
|
|
498
|
+
entries.push({ twin: dstRel, source: srcRel, sha256: sha256(bytes) });
|
|
499
|
+
} else {
|
|
500
|
+
unequal.push(`${srcRel} != ${dstRel}`);
|
|
501
|
+
}
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
toWrite.push({ src, dst, rel: dstRel, srcRel, bytes });
|
|
505
|
+
}
|
|
506
|
+
const problems = [];
|
|
507
|
+
if (missing.length > 0) {
|
|
508
|
+
problems.push(
|
|
509
|
+
`${missing.length} page(s) VitePress lists have no rendered flat HTML:
|
|
510
|
+
` + missing.map((m) => ` ${m}`).join("\n")
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
if (unequal.length > 0) {
|
|
514
|
+
problems.push(
|
|
515
|
+
`${unequal.length} existing directory index(es) differ from their flat page. SWA serves <page>.html for /page and <page>/index.html for /page/, so these would publish two different documents on one route:
|
|
516
|
+
` + unequal.map((u) => ` ${u}`).join("\n")
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
if (problems.length > 0) {
|
|
520
|
+
throw new DirIndexError(`[dcs-dir-index] build refused (nothing written).
|
|
521
|
+
${problems.join("\n")}`);
|
|
522
|
+
}
|
|
523
|
+
for (const t of toWrite) {
|
|
524
|
+
fs8.mkdirSync(path7.dirname(t.dst), { recursive: true });
|
|
525
|
+
fs8.writeFileSync(t.dst, t.bytes);
|
|
526
|
+
entries.push({ twin: t.rel, source: t.srcRel, sha256: sha256(t.bytes) });
|
|
527
|
+
}
|
|
528
|
+
const twins = [...toWrite.map((t) => t.rel), ...identicalRel].sort();
|
|
529
|
+
console.log(`[dcs-dir-index] twins written=${toWrite.length} identical=${identicalRel.length}`);
|
|
530
|
+
if (!manifestPath) return { written: toWrite.length, identical: identicalRel.length, twins };
|
|
531
|
+
entries.sort((a, b) => a.twin < b.twin ? -1 : a.twin > b.twin ? 1 : 0);
|
|
532
|
+
writeManifest(manifestPath, { schema: DIR_INDEX_MANIFEST_SCHEMA, outDir: path7.resolve(outDir), cleanUrls: true, twins: entries });
|
|
533
|
+
console.log(`[dcs-dir-index] manifest ${manifestPath} (${entries.length} twin(s))`);
|
|
534
|
+
return { written: toWrite.length, identical: identicalRel.length, twins, manifestPath };
|
|
535
|
+
}
|
|
536
|
+
function emitOnce(siteConfig) {
|
|
537
|
+
const state = siteConfig[DIR_INDEX_INSTALLED];
|
|
538
|
+
if (state?.emitted) return void 0;
|
|
539
|
+
if (state) state.emitted = true;
|
|
540
|
+
return emitDirectoryIndexes(siteConfig);
|
|
541
|
+
}
|
|
542
|
+
function isVitePressSiteConfig(value) {
|
|
543
|
+
if (!value || typeof value !== "object") return false;
|
|
544
|
+
const v = value;
|
|
545
|
+
return typeof v.outDir === "string" && Array.isArray(v.pages);
|
|
546
|
+
}
|
|
547
|
+
function installDirIndex(siteConfig) {
|
|
548
|
+
const guarded = siteConfig;
|
|
549
|
+
if (guarded[DIR_INDEX_INSTALLED]) return false;
|
|
550
|
+
guarded[DIR_INDEX_INSTALLED] = { owner: "auto", emitted: false };
|
|
551
|
+
const original = siteConfig.buildEnd;
|
|
552
|
+
siteConfig.buildEnd = chainBuildEnd(
|
|
553
|
+
original ? (sc) => original.call(sc, sc) : void 0,
|
|
554
|
+
(sc) => {
|
|
555
|
+
emitOnce(sc);
|
|
556
|
+
}
|
|
557
|
+
);
|
|
558
|
+
return true;
|
|
559
|
+
}
|
|
560
|
+
function dcsDirIndexBuildEnd() {
|
|
561
|
+
return async (siteConfig) => {
|
|
562
|
+
const guarded = siteConfig;
|
|
563
|
+
const state = guarded[DIR_INDEX_INSTALLED];
|
|
564
|
+
if (state?.owner === "auto") return;
|
|
565
|
+
if (!state) guarded[DIR_INDEX_INSTALLED] = { owner: "manual", emitted: false };
|
|
566
|
+
emitOnce(guarded);
|
|
567
|
+
};
|
|
568
|
+
}
|
|
306
569
|
function prerenderNavigationUrl(origin, routePath) {
|
|
307
570
|
const url = new URL(routePath, origin);
|
|
308
571
|
url.searchParams.set("dcs-no-telemetry", "");
|
|
@@ -356,32 +619,32 @@ async function startStaticServer(outDir) {
|
|
|
356
619
|
} catch {
|
|
357
620
|
pathname = "/";
|
|
358
621
|
}
|
|
359
|
-
const resolved =
|
|
360
|
-
if (resolved !== outDir && !resolved.startsWith(outDir +
|
|
622
|
+
const resolved = path7.resolve(outDir, "." + pathname);
|
|
623
|
+
if (resolved !== outDir && !resolved.startsWith(outDir + path7.sep)) {
|
|
361
624
|
res.writeHead(403);
|
|
362
625
|
res.end();
|
|
363
626
|
return;
|
|
364
627
|
}
|
|
365
628
|
let filePath = resolved;
|
|
366
629
|
try {
|
|
367
|
-
const stat =
|
|
368
|
-
if (stat.isDirectory()) filePath =
|
|
630
|
+
const stat = fs8.statSync(filePath);
|
|
631
|
+
if (stat.isDirectory()) filePath = path7.join(filePath, "index.html");
|
|
369
632
|
} catch {
|
|
370
|
-
if (
|
|
633
|
+
if (path7.extname(pathname)) {
|
|
371
634
|
res.writeHead(404);
|
|
372
635
|
res.end();
|
|
373
636
|
return;
|
|
374
637
|
}
|
|
375
|
-
filePath =
|
|
638
|
+
filePath = path7.join(outDir, "index.html");
|
|
376
639
|
}
|
|
377
|
-
|
|
640
|
+
fs8.readFile(filePath, (err, buf) => {
|
|
378
641
|
if (err) {
|
|
379
642
|
res.writeHead(404);
|
|
380
643
|
res.end();
|
|
381
644
|
return;
|
|
382
645
|
}
|
|
383
646
|
res.writeHead(200, {
|
|
384
|
-
"Content-Type": CONTENT_TYPES[
|
|
647
|
+
"Content-Type": CONTENT_TYPES[path7.extname(filePath).toLowerCase()] ?? "application/octet-stream"
|
|
385
648
|
});
|
|
386
649
|
res.end(buf);
|
|
387
650
|
});
|
|
@@ -533,6 +796,551 @@ async function createPlaywrightRenderer(options) {
|
|
|
533
796
|
}
|
|
534
797
|
};
|
|
535
798
|
}
|
|
799
|
+
var IDENTICAL_LASTMOD_ROUTE_LIMIT = 3;
|
|
800
|
+
var CONTENT_WALK_LIMIT = 300;
|
|
801
|
+
var DEFAULT_LASTMOD_EXCLUDE = [
|
|
802
|
+
// App shell, routing, entry points
|
|
803
|
+
"App.vue",
|
|
804
|
+
"main.{ts,js,mts,mjs}",
|
|
805
|
+
"**/router/**",
|
|
806
|
+
// Layouts (VitePress theme Layout.vue, any layouts/ dir) and theme/config shell
|
|
807
|
+
"Layout.vue",
|
|
808
|
+
"**/layouts/**",
|
|
809
|
+
"**/.vitepress/config.*",
|
|
810
|
+
"**/.vitepress/theme/index.*",
|
|
811
|
+
// Site-wide header / footer / nav / banner chrome
|
|
812
|
+
"{App,Site,Main,Global,Top,Page,The,Mobile,}{Header,Footer,Nav,NavBar,Navbar,Navigation,NavMenu,Banner,AnnouncementBanner}.vue",
|
|
813
|
+
// Non-content code
|
|
814
|
+
"**/composables/**",
|
|
815
|
+
"**/stores/**",
|
|
816
|
+
"**/lib/**",
|
|
817
|
+
"**/utils/**",
|
|
818
|
+
"**/components/ui/**",
|
|
819
|
+
// Styles and tests
|
|
820
|
+
"*.{css,scss,sass,less,styl,pcss,postcss}",
|
|
821
|
+
"*.{test,spec}.*",
|
|
822
|
+
"**/__tests__/**",
|
|
823
|
+
// DCS metadata: seo/pages/site are head + registry, content is dated per route
|
|
824
|
+
"**/.dcs/{seo,pages,site,content}.yaml",
|
|
825
|
+
"**/node_modules/**"
|
|
826
|
+
];
|
|
827
|
+
var defaultGit = (args, cwd) => execFileSync("git", args, {
|
|
828
|
+
cwd,
|
|
829
|
+
encoding: "utf8",
|
|
830
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
831
|
+
timeout: 6e4,
|
|
832
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
833
|
+
windowsHide: true
|
|
834
|
+
});
|
|
835
|
+
function toPascal(value) {
|
|
836
|
+
return value.split(/[^A-Za-z0-9]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
837
|
+
}
|
|
838
|
+
function defaultRouteSourceCandidates(route) {
|
|
839
|
+
const rel = route.path.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
840
|
+
const isHome = rel === "";
|
|
841
|
+
const names = /* @__PURE__ */ new Set();
|
|
842
|
+
const slugName = toPascal(route.slug || "");
|
|
843
|
+
if (slugName) names.add(slugName);
|
|
844
|
+
const lastSegment = rel.split("/").pop() ?? "";
|
|
845
|
+
const segName = toPascal(lastSegment);
|
|
846
|
+
if (segName) names.add(segName);
|
|
847
|
+
if (isHome) names.add("Home");
|
|
848
|
+
const out = [];
|
|
849
|
+
for (const name of names) {
|
|
850
|
+
out.push(`src/views/${name}View.vue`, `src/views/${name}.vue`, `src/pages/${name}.vue`, `src/pages/${name}View.vue`);
|
|
851
|
+
}
|
|
852
|
+
if (isHome) {
|
|
853
|
+
out.push("index.md", "docs/index.md");
|
|
854
|
+
} else {
|
|
855
|
+
out.push(`${rel}.md`, `${rel}/index.md`, `docs/${rel}.md`, `docs/${rel}/index.md`);
|
|
856
|
+
}
|
|
857
|
+
return out;
|
|
858
|
+
}
|
|
859
|
+
function isFile(abs) {
|
|
860
|
+
try {
|
|
861
|
+
return fs8.statSync(abs).isFile();
|
|
862
|
+
} catch {
|
|
863
|
+
return false;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
function routeEntries(route, projectRoot, sourcesForRoute) {
|
|
867
|
+
const custom = sourcesForRoute?.(route);
|
|
868
|
+
if (custom) {
|
|
869
|
+
return [...new Set(custom.filter((c) => typeof c === "string" && c).map((c) => path7.resolve(projectRoot, c)))].filter(isFile);
|
|
870
|
+
}
|
|
871
|
+
const first = defaultRouteSourceCandidates(route).map((c) => path7.resolve(projectRoot, c)).find(isFile);
|
|
872
|
+
return first ? [first] : [];
|
|
873
|
+
}
|
|
874
|
+
function escapeRe(s) {
|
|
875
|
+
return s.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
876
|
+
}
|
|
877
|
+
function lastmodGlobToRegExp(glob) {
|
|
878
|
+
const convert = (g) => {
|
|
879
|
+
let re = "";
|
|
880
|
+
for (let i = 0; i < g.length; i++) {
|
|
881
|
+
const c = g[i];
|
|
882
|
+
if (c === "*") {
|
|
883
|
+
if (g[i + 1] === "*") {
|
|
884
|
+
if (g[i + 2] === "/") {
|
|
885
|
+
re += "(?:.*/)?";
|
|
886
|
+
i += 2;
|
|
887
|
+
} else {
|
|
888
|
+
re += ".*";
|
|
889
|
+
i += 1;
|
|
890
|
+
}
|
|
891
|
+
} else {
|
|
892
|
+
re += "[^/]*";
|
|
893
|
+
}
|
|
894
|
+
} else if (c === "?") {
|
|
895
|
+
re += "[^/]";
|
|
896
|
+
} else if (c === "{") {
|
|
897
|
+
const end = g.indexOf("}", i);
|
|
898
|
+
if (end > i) {
|
|
899
|
+
re += "(?:" + g.slice(i + 1, end).split(",").map(convert).join("|") + ")";
|
|
900
|
+
i = end;
|
|
901
|
+
} else {
|
|
902
|
+
re += "\\{";
|
|
903
|
+
}
|
|
904
|
+
} else {
|
|
905
|
+
re += escapeRe(c);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
return re;
|
|
909
|
+
};
|
|
910
|
+
return new RegExp("^" + convert(glob) + "$");
|
|
911
|
+
}
|
|
912
|
+
function toPosix(p) {
|
|
913
|
+
return p.split(path7.sep).join("/");
|
|
914
|
+
}
|
|
915
|
+
function makeExcluder(projectRoot, extra, alsoExcludeAbs) {
|
|
916
|
+
const plain = [...DEFAULT_LASTMOD_EXCLUDE, ...extra.filter((g) => !g.startsWith("!"))].map((g) => ({
|
|
917
|
+
re: lastmodGlobToRegExp(g),
|
|
918
|
+
base: !g.includes("/")
|
|
919
|
+
}));
|
|
920
|
+
const reinclude = extra.filter((g) => g.startsWith("!")).map((g) => ({ re: lastmodGlobToRegExp(g.slice(1)), base: !g.slice(1).includes("/") }));
|
|
921
|
+
const fixed = new Set(alsoExcludeAbs.map((a) => path7.resolve(a).toLowerCase()));
|
|
922
|
+
const test = (rules, rel) => rules.some((r) => r.re.test(r.base ? rel.split("/").pop() ?? rel : rel));
|
|
923
|
+
return (abs) => {
|
|
924
|
+
if (fixed.has(path7.resolve(abs).toLowerCase())) return true;
|
|
925
|
+
const rel = toPosix(path7.relative(projectRoot, abs));
|
|
926
|
+
if (!test(plain, rel)) return false;
|
|
927
|
+
return !test(reinclude, rel);
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
function expandGlob(absPattern) {
|
|
931
|
+
const posix = toPosix(absPattern);
|
|
932
|
+
const firstWild = posix.search(/[*?{]/);
|
|
933
|
+
if (firstWild < 0) return isFile(absPattern) ? [path7.resolve(absPattern)] : [];
|
|
934
|
+
const baseDir = posix.slice(0, posix.lastIndexOf("/", firstWild));
|
|
935
|
+
const re = lastmodGlobToRegExp(posix);
|
|
936
|
+
const out = [];
|
|
937
|
+
const walk = (dir, depth) => {
|
|
938
|
+
if (depth > 12) return;
|
|
939
|
+
let entries;
|
|
940
|
+
try {
|
|
941
|
+
entries = fs8.readdirSync(dir, { withFileTypes: true });
|
|
942
|
+
} catch {
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
for (const e of entries) {
|
|
946
|
+
if (e.name === "node_modules" || e.name === ".git") continue;
|
|
947
|
+
const full = path7.join(dir, e.name);
|
|
948
|
+
if (e.isDirectory()) walk(full, depth + 1);
|
|
949
|
+
else if (e.isFile() && re.test(toPosix(full))) out.push(path7.resolve(full));
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
walk(baseDir || "/", 0);
|
|
953
|
+
return out;
|
|
954
|
+
}
|
|
955
|
+
var CODE_EXT = /\.(vue|[cm]?[jt]sx?|md)$/i;
|
|
956
|
+
var RESOLVE_EXTENSIONS = ["", ".ts", ".js", ".mts", ".mjs", ".tsx", ".jsx", ".vue", ".json", "/index.ts", "/index.js", "/index.vue"];
|
|
957
|
+
var BUILTINS = new Set(builtinModules);
|
|
958
|
+
var VITEPRESS_BUILTIN_TAGS = /* @__PURE__ */ new Set(["Badge", "Content", "ClientOnly"]);
|
|
959
|
+
var VITEPRESS_BUILTIN_LAYOUTS = /* @__PURE__ */ new Set(["doc", "home", "page", "false"]);
|
|
960
|
+
function stripComments(src) {
|
|
961
|
+
return src.replace(/\/\*[\s\S]*?\*\//g, "").replace(/^\s*\/\/.*$/gm, "");
|
|
962
|
+
}
|
|
963
|
+
function findSrcDir(file) {
|
|
964
|
+
let dir = path7.dirname(file);
|
|
965
|
+
for (let i = 0; i < 12; i++) {
|
|
966
|
+
if (fs8.existsSync(path7.join(dir, ".vitepress"))) return dir;
|
|
967
|
+
const up = path7.dirname(dir);
|
|
968
|
+
if (up === dir) return void 0;
|
|
969
|
+
dir = up;
|
|
970
|
+
}
|
|
971
|
+
return void 0;
|
|
972
|
+
}
|
|
973
|
+
function hasPackage(specifier, fromFile) {
|
|
974
|
+
const parts = specifier.split("/");
|
|
975
|
+
const pkg = specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
|
|
976
|
+
let dir = path7.dirname(fromFile);
|
|
977
|
+
for (let i = 0; i < 40; i++) {
|
|
978
|
+
if (fs8.existsSync(path7.join(dir, "node_modules", pkg))) return true;
|
|
979
|
+
const up = path7.dirname(dir);
|
|
980
|
+
if (up === dir) return false;
|
|
981
|
+
dir = up;
|
|
982
|
+
}
|
|
983
|
+
return false;
|
|
984
|
+
}
|
|
985
|
+
function resolveWithExtensions(base) {
|
|
986
|
+
for (const ext of RESOLVE_EXTENSIONS) {
|
|
987
|
+
const c = base + ext;
|
|
988
|
+
if (isFile(c)) return path7.resolve(c);
|
|
989
|
+
}
|
|
990
|
+
return void 0;
|
|
991
|
+
}
|
|
992
|
+
function resolveImport(specifierRaw, fromFile, projectRoot) {
|
|
993
|
+
const specifier = specifierRaw.replace(/[?#].*$/, "");
|
|
994
|
+
if (!specifier) return { kind: "unresolved" };
|
|
995
|
+
if (specifier.startsWith("node:") || BUILTINS.has(specifier)) return { kind: "package" };
|
|
996
|
+
if (specifier.startsWith("virtual:") || specifier.startsWith("\0")) return { kind: "unresolved" };
|
|
997
|
+
let base;
|
|
998
|
+
if (specifier.startsWith(".")) base = path7.resolve(path7.dirname(fromFile), specifier);
|
|
999
|
+
else if (specifier.startsWith("@/") || specifier.startsWith("~/")) base = path7.join(projectRoot, "src", specifier.slice(2));
|
|
1000
|
+
else if (specifier.startsWith("@theme/")) {
|
|
1001
|
+
const srcDir = findSrcDir(fromFile);
|
|
1002
|
+
if (srcDir) base = path7.join(srcDir, ".vitepress", "theme", specifier.slice("@theme/".length));
|
|
1003
|
+
} else if (specifier.startsWith("/")) {
|
|
1004
|
+
const srcDir = findSrcDir(fromFile);
|
|
1005
|
+
const hit2 = resolveWithExtensions(path7.join(projectRoot, specifier)) ?? (srcDir ? resolveWithExtensions(path7.join(srcDir, specifier)) : void 0);
|
|
1006
|
+
return hit2 ? { kind: "file", file: hit2 } : { kind: "unresolved" };
|
|
1007
|
+
} else {
|
|
1008
|
+
return hasPackage(specifier, fromFile) ? { kind: "package" } : { kind: "unresolved" };
|
|
1009
|
+
}
|
|
1010
|
+
if (!base) return { kind: "unresolved" };
|
|
1011
|
+
const hit = resolveWithExtensions(base);
|
|
1012
|
+
return hit ? { kind: "file", file: hit } : { kind: "unresolved" };
|
|
1013
|
+
}
|
|
1014
|
+
function themeRegistry(srcDir, cache) {
|
|
1015
|
+
const hit = cache.get(srcDir);
|
|
1016
|
+
if (hit) return hit;
|
|
1017
|
+
const reg = /* @__PURE__ */ new Map();
|
|
1018
|
+
const themeDir = path7.join(srcDir, ".vitepress", "theme");
|
|
1019
|
+
const indexFile = ["index.ts", "index.js", "index.mts", "index.mjs"].map((f) => path7.join(themeDir, f)).find(isFile);
|
|
1020
|
+
if (indexFile) {
|
|
1021
|
+
const src = stripComments(fs8.readFileSync(indexFile, "utf8"));
|
|
1022
|
+
const idents = /* @__PURE__ */ new Map();
|
|
1023
|
+
for (const m of src.matchAll(/^\s*import\s+(\w+)\s+from\s+['"]([^'"]+)['"]/gm)) idents.set(m[1], m[2]);
|
|
1024
|
+
for (const m of src.matchAll(/\.component\(\s*['"]([\w-]+)['"]\s*,\s*(\w+)\s*\)/g)) {
|
|
1025
|
+
const spec = idents.get(m[2]);
|
|
1026
|
+
if (!spec) continue;
|
|
1027
|
+
const r = resolveImport(spec, indexFile, srcDir);
|
|
1028
|
+
if (r.kind === "file") {
|
|
1029
|
+
reg.set(m[1], r.file);
|
|
1030
|
+
reg.set(toPascal(m[1]), r.file);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
cache.set(srcDir, reg);
|
|
1035
|
+
return reg;
|
|
1036
|
+
}
|
|
1037
|
+
function dataLoaderInputs(src, loaderFile) {
|
|
1038
|
+
const srcDir = findSrcDir(loaderFile) ?? path7.dirname(loaderFile);
|
|
1039
|
+
const literals = (s) => [...s.matchAll(/['"]([^'"]+)['"]/g)].map((m) => m[1]);
|
|
1040
|
+
const out = [];
|
|
1041
|
+
let found = false;
|
|
1042
|
+
for (const m of src.matchAll(/createContentLoader\(\s*(\[[^\]]*\]|['"][^'"]+['"])/g)) {
|
|
1043
|
+
found = true;
|
|
1044
|
+
for (const g of literals(m[1])) out.push(...expandGlob(path7.resolve(srcDir, g)));
|
|
1045
|
+
}
|
|
1046
|
+
for (const m of src.matchAll(/\bwatch\s*:\s*(\[[^\]]*\]|['"][^'"]+['"])/g)) {
|
|
1047
|
+
found = true;
|
|
1048
|
+
for (const g of literals(m[1])) {
|
|
1049
|
+
const base = g.startsWith(".") ? path7.dirname(loaderFile) : srcDir;
|
|
1050
|
+
out.push(...expandGlob(path7.resolve(base, g)));
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
return found ? out : null;
|
|
1054
|
+
}
|
|
1055
|
+
function walkContentModules(entries, projectRoot, isExcluded, registryCache, fileCache) {
|
|
1056
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1057
|
+
const queue = [];
|
|
1058
|
+
for (const e of entries) {
|
|
1059
|
+
if (!seen.has(e)) {
|
|
1060
|
+
seen.add(e);
|
|
1061
|
+
queue.push(e);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
while (queue.length > 0) {
|
|
1065
|
+
const file = queue.shift();
|
|
1066
|
+
let info = fileCache.get(file);
|
|
1067
|
+
if (!info) {
|
|
1068
|
+
info = scanFile(file, projectRoot, registryCache);
|
|
1069
|
+
fileCache.set(file, info);
|
|
1070
|
+
}
|
|
1071
|
+
if (info.bad) return { files: [...seen], omitted: info.bad };
|
|
1072
|
+
for (const dep of info.deps) {
|
|
1073
|
+
if (seen.has(dep) || isExcluded(dep)) continue;
|
|
1074
|
+
seen.add(dep);
|
|
1075
|
+
queue.push(dep);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
return { files: [...seen] };
|
|
1079
|
+
}
|
|
1080
|
+
function scanFile(file, projectRoot, registryCache) {
|
|
1081
|
+
if (!CODE_EXT.test(file)) return { deps: [] };
|
|
1082
|
+
let raw;
|
|
1083
|
+
try {
|
|
1084
|
+
raw = fs8.readFileSync(file, "utf8");
|
|
1085
|
+
} catch {
|
|
1086
|
+
return { deps: [], bad: "unresolved-import" };
|
|
1087
|
+
}
|
|
1088
|
+
const isMd = /\.md$/i.test(file);
|
|
1089
|
+
if (isMd) {
|
|
1090
|
+
const fm = raw.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
1091
|
+
const layout = fm?.[1].match(/^layout\s*:\s*(.*?)\s*$/m)?.[1].replace(/^['"]|['"]$/g, "");
|
|
1092
|
+
if (layout && !VITEPRESS_BUILTIN_LAYOUTS.has(layout)) return { deps: [], bad: "custom-layout" };
|
|
1093
|
+
}
|
|
1094
|
+
const body = isMd ? raw.replace(/^(```|~~~)[\s\S]*?^\1/gm, "") : raw;
|
|
1095
|
+
const code = isMd ? [...body.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script>/gi)].map((m) => m[1]).join("\n") : body;
|
|
1096
|
+
const src = stripComments(code);
|
|
1097
|
+
const deps = /* @__PURE__ */ new Set();
|
|
1098
|
+
if (/\.data\.[cm]?[jt]s$/i.test(file)) {
|
|
1099
|
+
const inputs = dataLoaderInputs(src, file);
|
|
1100
|
+
if (inputs === null) return { deps: [], bad: "data-loader" };
|
|
1101
|
+
for (const f of inputs) deps.add(f);
|
|
1102
|
+
}
|
|
1103
|
+
for (const m of src.matchAll(/(?:\bfrom\s*|\bimport\s*\(\s*|^\s*import\s+)['"]([^'"]+)['"]/gm)) {
|
|
1104
|
+
const r = resolveImport(m[1], file, projectRoot);
|
|
1105
|
+
if (r.kind === "unresolved") return { deps: [], bad: "unresolved-import" };
|
|
1106
|
+
if (r.kind === "file" && r.file !== path7.resolve(file)) deps.add(r.file);
|
|
1107
|
+
}
|
|
1108
|
+
for (const m of src.matchAll(/import\.meta\.glob(?:<[^>]*>)?\(\s*(\[[^\]]*\]|['"][^'"]+['"])/g)) {
|
|
1109
|
+
for (const lit of [...m[1].matchAll(/['"]([^'"]+)['"]/g)].map((x) => x[1])) {
|
|
1110
|
+
if (lit.startsWith("!")) continue;
|
|
1111
|
+
const abs = lit.startsWith("/") ? path7.join(projectRoot, lit) : path7.resolve(path7.dirname(file), lit);
|
|
1112
|
+
for (const f of expandGlob(abs)) deps.add(f);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
const srcDir = findSrcDir(file);
|
|
1116
|
+
if (srcDir) {
|
|
1117
|
+
const reg = themeRegistry(srcDir, registryCache);
|
|
1118
|
+
const markup = isMd ? body.replace(/<script\b[\s\S]*?<\/script>/gi, "").replace(/`[^`\n]*`/g, "") : raw.match(/<template\b[\s\S]*<\/template>/i)?.[0] ?? "";
|
|
1119
|
+
const tags = /* @__PURE__ */ new Set();
|
|
1120
|
+
for (const m of markup.matchAll(/<([A-Z][A-Za-z0-9]*)\b/g)) tags.add(m[1]);
|
|
1121
|
+
for (const m of markup.matchAll(/<([a-z][a-z0-9]*(?:-[a-z0-9]+)+)\b/g)) tags.add(toPascal(m[1]));
|
|
1122
|
+
for (const tag of tags) {
|
|
1123
|
+
const target = reg.get(tag);
|
|
1124
|
+
if (target) deps.add(target);
|
|
1125
|
+
else if (isMd && !VITEPRESS_BUILTIN_TAGS.has(tag)) return { deps: [], bad: "unresolved-component" };
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
return { deps: [...deps] };
|
|
1129
|
+
}
|
|
1130
|
+
var ZERO_BLOB = /^0+$/;
|
|
1131
|
+
function findContentFile(projectRoot, contentPath) {
|
|
1132
|
+
const rel = contentPath ?? ".dcs/content.yaml";
|
|
1133
|
+
if (path7.isAbsolute(rel)) return isFile(rel) ? path7.resolve(rel) : void 0;
|
|
1134
|
+
return [path7.resolve(projectRoot, rel), path7.resolve(projectRoot, "..", rel), path7.resolve(process.cwd(), rel)].find(isFile);
|
|
1135
|
+
}
|
|
1136
|
+
function referencedGlobalKeys(files, globalKeys) {
|
|
1137
|
+
if (globalKeys.length === 0) return [];
|
|
1138
|
+
const text = files.filter((f) => CODE_EXT.test(f)).map((f) => {
|
|
1139
|
+
try {
|
|
1140
|
+
return fs8.readFileSync(f, "utf8");
|
|
1141
|
+
} catch {
|
|
1142
|
+
return "";
|
|
1143
|
+
}
|
|
1144
|
+
}).join("\n");
|
|
1145
|
+
return globalKeys.filter((k) => text.includes(`'${k}'`) || text.includes(`"${k}"`) || text.includes(`\`${k}\``));
|
|
1146
|
+
}
|
|
1147
|
+
function deriveRouteLastmods(options) {
|
|
1148
|
+
const {
|
|
1149
|
+
routes,
|
|
1150
|
+
projectRoot,
|
|
1151
|
+
sourcesForRoute,
|
|
1152
|
+
contentPath,
|
|
1153
|
+
exclude = [],
|
|
1154
|
+
contentWalkLimit = CONTENT_WALK_LIMIT,
|
|
1155
|
+
git = defaultGit,
|
|
1156
|
+
debug = false
|
|
1157
|
+
} = options;
|
|
1158
|
+
const omitted = /* @__PURE__ */ new Map();
|
|
1159
|
+
const sources = /* @__PURE__ */ new Map();
|
|
1160
|
+
const empty = (withheld) => {
|
|
1161
|
+
if (debug) console.log(`[dcs-seo] git-derived <lastmod> withheld: ${withheld}`);
|
|
1162
|
+
return { lastmods: /* @__PURE__ */ new Map(), withheld, omitted, sources };
|
|
1163
|
+
};
|
|
1164
|
+
let shallow;
|
|
1165
|
+
try {
|
|
1166
|
+
shallow = git(["rev-parse", "--is-shallow-repository"], projectRoot).trim();
|
|
1167
|
+
} catch {
|
|
1168
|
+
return empty("git-unavailable");
|
|
1169
|
+
}
|
|
1170
|
+
if (shallow === "true") return empty("shallow");
|
|
1171
|
+
if (shallow !== "false") return empty("git-unavailable");
|
|
1172
|
+
let top;
|
|
1173
|
+
try {
|
|
1174
|
+
top = path7.resolve(git(["rev-parse", "--show-toplevel"], projectRoot).trim());
|
|
1175
|
+
} catch {
|
|
1176
|
+
return empty("git-unavailable");
|
|
1177
|
+
}
|
|
1178
|
+
const relTop = (abs) => toPosix(path7.relative(top, abs));
|
|
1179
|
+
const contentFile = findContentFile(projectRoot, contentPath);
|
|
1180
|
+
const isExcluded = makeExcluder(projectRoot, exclude, contentFile ? [contentFile] : []);
|
|
1181
|
+
const registryCache = /* @__PURE__ */ new Map();
|
|
1182
|
+
const fileCache = /* @__PURE__ */ new Map();
|
|
1183
|
+
const routeFiles = /* @__PURE__ */ new Map();
|
|
1184
|
+
for (const route of routes) {
|
|
1185
|
+
if (routeFiles.has(route.path) || omitted.has(route.path)) continue;
|
|
1186
|
+
const entries = routeEntries(route, projectRoot, sourcesForRoute);
|
|
1187
|
+
if (entries.length === 0) {
|
|
1188
|
+
omitted.set(route.path, "no-source");
|
|
1189
|
+
continue;
|
|
1190
|
+
}
|
|
1191
|
+
const walked = walkContentModules(entries, projectRoot, isExcluded, registryCache, fileCache);
|
|
1192
|
+
if (walked.omitted) {
|
|
1193
|
+
omitted.set(route.path, walked.omitted);
|
|
1194
|
+
continue;
|
|
1195
|
+
}
|
|
1196
|
+
routeFiles.set(route.path, walked.files);
|
|
1197
|
+
}
|
|
1198
|
+
const allFiles = [...new Set([...routeFiles.values()].flat())];
|
|
1199
|
+
const material = contentFile ? [...allFiles, contentFile] : allFiles;
|
|
1200
|
+
const tracked = /* @__PURE__ */ new Set();
|
|
1201
|
+
const dirty = /* @__PURE__ */ new Set();
|
|
1202
|
+
const newest = /* @__PURE__ */ new Map();
|
|
1203
|
+
if (material.length > 0) {
|
|
1204
|
+
const rels = [...new Set(material.map(relTop))];
|
|
1205
|
+
try {
|
|
1206
|
+
for (const line of git(["-c", "core.quotepath=off", "ls-files"], top).split("\n")) {
|
|
1207
|
+
if (line.trim()) tracked.add(line.trim());
|
|
1208
|
+
}
|
|
1209
|
+
for (const line of git(["-c", "core.quotepath=off", "status", "--porcelain=v1", "--untracked-files=all"], top).split("\n")) {
|
|
1210
|
+
if (line.length <= 3) continue;
|
|
1211
|
+
for (const part of line.slice(3).trim().split(" -> ")) dirty.add(part.replace(/^"|"$/g, ""));
|
|
1212
|
+
}
|
|
1213
|
+
const dated = rels.filter((r) => tracked.has(r));
|
|
1214
|
+
for (let i = 0; i < dated.length; i += 150) {
|
|
1215
|
+
const out = git(
|
|
1216
|
+
["-c", "core.quotepath=off", "log", "--format=%x01%cI", "--name-only", "--cc", "--", ...dated.slice(i, i + 150)],
|
|
1217
|
+
top
|
|
1218
|
+
);
|
|
1219
|
+
let date = null;
|
|
1220
|
+
for (const line of out.split("\n")) {
|
|
1221
|
+
const t = line.trim();
|
|
1222
|
+
if (t.startsWith("")) {
|
|
1223
|
+
date = t.slice(1);
|
|
1224
|
+
continue;
|
|
1225
|
+
}
|
|
1226
|
+
if (!t || !date) continue;
|
|
1227
|
+
const known = newest.get(t);
|
|
1228
|
+
if (!known || Date.parse(date) > Date.parse(known)) newest.set(t, date);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
} catch {
|
|
1232
|
+
return empty("git-unavailable");
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
const isClean = (abs) => tracked.has(relTop(abs)) && !dirty.has(relTop(abs));
|
|
1236
|
+
let contentEntries = [];
|
|
1237
|
+
let contentCapped = false;
|
|
1238
|
+
let contentOk = true;
|
|
1239
|
+
const blobCache = /* @__PURE__ */ new Map();
|
|
1240
|
+
let globalKeys = [];
|
|
1241
|
+
if (contentFile) {
|
|
1242
|
+
if (!isClean(contentFile)) {
|
|
1243
|
+
contentOk = false;
|
|
1244
|
+
} else {
|
|
1245
|
+
try {
|
|
1246
|
+
const out = git(
|
|
1247
|
+
["log", "--first-parent", "-m", `-n${contentWalkLimit + 1}`, "--format=%x01%cI", "--raw", "--no-abbrev", "--", relTop(contentFile)],
|
|
1248
|
+
top
|
|
1249
|
+
);
|
|
1250
|
+
let date = null;
|
|
1251
|
+
for (const line of out.split("\n")) {
|
|
1252
|
+
const t = line.trim();
|
|
1253
|
+
if (t.startsWith("")) {
|
|
1254
|
+
date = t.slice(1);
|
|
1255
|
+
continue;
|
|
1256
|
+
}
|
|
1257
|
+
const m = t.match(/^:\d+ \d+ ([0-9a-f]+) ([0-9a-f]+) /);
|
|
1258
|
+
if (m && date) contentEntries.push({ date, oldBlob: m[1], newBlob: m[2] });
|
|
1259
|
+
}
|
|
1260
|
+
} catch {
|
|
1261
|
+
return empty("git-unavailable");
|
|
1262
|
+
}
|
|
1263
|
+
if (contentEntries.length > contentWalkLimit) {
|
|
1264
|
+
contentCapped = true;
|
|
1265
|
+
contentEntries = contentEntries.slice(0, contentWalkLimit);
|
|
1266
|
+
}
|
|
1267
|
+
try {
|
|
1268
|
+
const head = yaml5.load(fs8.readFileSync(contentFile, "utf8"));
|
|
1269
|
+
globalKeys = Object.keys(head?.global ?? {});
|
|
1270
|
+
} catch {
|
|
1271
|
+
contentOk = false;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
const loadBlob = (blob) => {
|
|
1276
|
+
if (ZERO_BLOB.test(blob)) return null;
|
|
1277
|
+
if (blobCache.has(blob)) return blobCache.get(blob) ?? null;
|
|
1278
|
+
let doc = null;
|
|
1279
|
+
try {
|
|
1280
|
+
doc = yaml5.load(git(["cat-file", "-p", blob], top)) ?? null;
|
|
1281
|
+
} catch {
|
|
1282
|
+
doc = null;
|
|
1283
|
+
}
|
|
1284
|
+
blobCache.set(blob, doc);
|
|
1285
|
+
return doc;
|
|
1286
|
+
};
|
|
1287
|
+
const subtreeKey = (doc, slug, keys) => {
|
|
1288
|
+
const pages = doc?.pages ?? {};
|
|
1289
|
+
const global = doc?.global ?? {};
|
|
1290
|
+
return JSON.stringify({ page: pages[slug] ?? null, global: keys.map((k) => [k, global[k] ?? null]) });
|
|
1291
|
+
};
|
|
1292
|
+
const lastmods = /* @__PURE__ */ new Map();
|
|
1293
|
+
for (const route of routes) {
|
|
1294
|
+
const files = routeFiles.get(route.path);
|
|
1295
|
+
if (!files || lastmods.has(route.path)) continue;
|
|
1296
|
+
if (!files.every(isClean)) {
|
|
1297
|
+
omitted.set(route.path, "untracked-source");
|
|
1298
|
+
continue;
|
|
1299
|
+
}
|
|
1300
|
+
let best = null;
|
|
1301
|
+
let undated = false;
|
|
1302
|
+
for (const f of files) {
|
|
1303
|
+
const d = newest.get(relTop(f));
|
|
1304
|
+
if (!d) {
|
|
1305
|
+
undated = true;
|
|
1306
|
+
break;
|
|
1307
|
+
}
|
|
1308
|
+
if (best === null || Date.parse(d) > Date.parse(best)) best = d;
|
|
1309
|
+
}
|
|
1310
|
+
if (undated || best === null) {
|
|
1311
|
+
omitted.set(route.path, "undated-source");
|
|
1312
|
+
continue;
|
|
1313
|
+
}
|
|
1314
|
+
if (contentFile) {
|
|
1315
|
+
if (!contentOk) {
|
|
1316
|
+
omitted.set(route.path, "content-untracked");
|
|
1317
|
+
continue;
|
|
1318
|
+
}
|
|
1319
|
+
const keys = referencedGlobalKeys(files, globalKeys);
|
|
1320
|
+
let contentDate = null;
|
|
1321
|
+
for (const e of contentEntries) {
|
|
1322
|
+
if (subtreeKey(loadBlob(e.newBlob), route.slug, keys) !== subtreeKey(loadBlob(e.oldBlob), route.slug, keys)) {
|
|
1323
|
+
contentDate = e.date;
|
|
1324
|
+
break;
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
if (contentDate === null && contentCapped) {
|
|
1328
|
+
omitted.set(route.path, "content-walk-cap");
|
|
1329
|
+
continue;
|
|
1330
|
+
}
|
|
1331
|
+
if (contentDate && Date.parse(contentDate) > Date.parse(best)) best = contentDate;
|
|
1332
|
+
}
|
|
1333
|
+
lastmods.set(route.path, best);
|
|
1334
|
+
sources.set(route.path, contentFile ? [...files, contentFile] : files);
|
|
1335
|
+
}
|
|
1336
|
+
if (lastmods.size >= IDENTICAL_LASTMOD_ROUTE_LIMIT && new Set(lastmods.values()).size === 1) {
|
|
1337
|
+
return empty("identical-dates");
|
|
1338
|
+
}
|
|
1339
|
+
if (debug) {
|
|
1340
|
+
for (const [p, why] of omitted) console.log(`[dcs-seo] <lastmod> omitted for ${p}: ${why}`);
|
|
1341
|
+
}
|
|
1342
|
+
return { lastmods, omitted, sources };
|
|
1343
|
+
}
|
|
536
1344
|
|
|
537
1345
|
// src/plugins/dcsSeoPlugin.ts
|
|
538
1346
|
function readHonestyBlock(value) {
|
|
@@ -547,17 +1355,17 @@ function readHonestyBlock(value) {
|
|
|
547
1355
|
}
|
|
548
1356
|
function resolveOutDir(config2) {
|
|
549
1357
|
const out = config2.build?.outDir || "dist";
|
|
550
|
-
return
|
|
1358
|
+
return path7.isAbsolute(out) ? out : path7.resolve(config2.root || process.cwd(), out);
|
|
551
1359
|
}
|
|
552
1360
|
function loadSeoConfig(projectRoot, seoPath, debug) {
|
|
553
1361
|
const possiblePaths = [
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
1362
|
+
path7.resolve(projectRoot, seoPath),
|
|
1363
|
+
path7.resolve(projectRoot, "..", seoPath),
|
|
1364
|
+
path7.resolve(process.cwd(), seoPath)
|
|
557
1365
|
];
|
|
558
1366
|
let foundPath;
|
|
559
1367
|
for (const testPath of possiblePaths) {
|
|
560
|
-
if (
|
|
1368
|
+
if (fs8.existsSync(testPath)) {
|
|
561
1369
|
foundPath = testPath;
|
|
562
1370
|
break;
|
|
563
1371
|
}
|
|
@@ -571,8 +1379,8 @@ function loadSeoConfig(projectRoot, seoPath, debug) {
|
|
|
571
1379
|
return null;
|
|
572
1380
|
}
|
|
573
1381
|
try {
|
|
574
|
-
const fileContent =
|
|
575
|
-
const config2 =
|
|
1382
|
+
const fileContent = fs8.readFileSync(foundPath, "utf8");
|
|
1383
|
+
const config2 = yaml5.load(fileContent);
|
|
576
1384
|
return { config: config2, foundPath };
|
|
577
1385
|
} catch (error) {
|
|
578
1386
|
console.warn("[dcs-seo] Failed to parse seo.yaml:", error);
|
|
@@ -581,17 +1389,17 @@ function loadSeoConfig(projectRoot, seoPath, debug) {
|
|
|
581
1389
|
}
|
|
582
1390
|
function loadContentConfig(projectRoot, contentRelPath, debug) {
|
|
583
1391
|
const possiblePaths = [
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
1392
|
+
path7.resolve(projectRoot, contentRelPath),
|
|
1393
|
+
path7.resolve(projectRoot, "..", contentRelPath),
|
|
1394
|
+
path7.resolve(process.cwd(), contentRelPath)
|
|
587
1395
|
];
|
|
588
|
-
const foundPath = possiblePaths.find((p) =>
|
|
1396
|
+
const foundPath = possiblePaths.find((p) => fs8.existsSync(p));
|
|
589
1397
|
if (!foundPath) {
|
|
590
1398
|
if (debug) console.log(`[dcs-seo] No content.yaml found (reviews disabled)`);
|
|
591
1399
|
return void 0;
|
|
592
1400
|
}
|
|
593
1401
|
try {
|
|
594
|
-
const parsed =
|
|
1402
|
+
const parsed = yaml5.load(fs8.readFileSync(foundPath, "utf8"));
|
|
595
1403
|
if (!parsed || typeof parsed !== "object") return void 0;
|
|
596
1404
|
return parsed;
|
|
597
1405
|
} catch (error) {
|
|
@@ -601,14 +1409,14 @@ function loadContentConfig(projectRoot, contentRelPath, debug) {
|
|
|
601
1409
|
}
|
|
602
1410
|
function loadExcludedGlobs(projectRoot, pagesPath) {
|
|
603
1411
|
const possiblePaths = [
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
1412
|
+
path7.resolve(projectRoot, pagesPath),
|
|
1413
|
+
path7.resolve(projectRoot, "..", pagesPath),
|
|
1414
|
+
path7.resolve(process.cwd(), pagesPath)
|
|
607
1415
|
];
|
|
608
|
-
const found = possiblePaths.find((p) =>
|
|
1416
|
+
const found = possiblePaths.find((p) => fs8.existsSync(p));
|
|
609
1417
|
if (!found) return [];
|
|
610
1418
|
try {
|
|
611
|
-
const raw =
|
|
1419
|
+
const raw = yaml5.load(fs8.readFileSync(found, "utf8"));
|
|
612
1420
|
const excluded = raw?.excluded;
|
|
613
1421
|
if (!Array.isArray(excluded)) return [];
|
|
614
1422
|
return excluded.filter((e) => typeof e === "string");
|
|
@@ -658,24 +1466,6 @@ function assertNoOrphanNoindexEntries(noindex, routes) {
|
|
|
658
1466
|
if (orphans.length === 0) return;
|
|
659
1467
|
throw new NoindexOrphanError(orphans, [...collectNoindexMatchKeys(routes)].sort());
|
|
660
1468
|
}
|
|
661
|
-
function deriveLastmod(seoConfig, projectRoot, pagesPath) {
|
|
662
|
-
const fromSeo = seoConfig?.lastUpdated;
|
|
663
|
-
if (typeof fromSeo === "string" && fromSeo.length > 0) return fromSeo;
|
|
664
|
-
const possiblePaths = [
|
|
665
|
-
path5.resolve(projectRoot, pagesPath),
|
|
666
|
-
path5.resolve(projectRoot, "..", pagesPath),
|
|
667
|
-
path5.resolve(process.cwd(), pagesPath)
|
|
668
|
-
];
|
|
669
|
-
const found = possiblePaths.find((p) => fs5.existsSync(p));
|
|
670
|
-
if (!found) return void 0;
|
|
671
|
-
try {
|
|
672
|
-
const raw = yaml4.load(fs5.readFileSync(found, "utf8"));
|
|
673
|
-
const fromPages = raw?.lastUpdated;
|
|
674
|
-
if (typeof fromPages === "string" && fromPages.length > 0) return fromPages;
|
|
675
|
-
} catch {
|
|
676
|
-
}
|
|
677
|
-
return void 0;
|
|
678
|
-
}
|
|
679
1469
|
function emitSiteFiles(params) {
|
|
680
1470
|
const {
|
|
681
1471
|
outDir,
|
|
@@ -689,12 +1479,25 @@ function emitSiteFiles(params) {
|
|
|
689
1479
|
preview = false,
|
|
690
1480
|
robots = {},
|
|
691
1481
|
llms = true,
|
|
1482
|
+
gitLastmod,
|
|
1483
|
+
lastmodSources,
|
|
1484
|
+
contentPath,
|
|
1485
|
+
git,
|
|
692
1486
|
debug = false
|
|
693
1487
|
} = params;
|
|
694
1488
|
const written = [];
|
|
695
1489
|
const effectiveSiteUrl = siteUrl || seoConfig?.global?.siteUrl;
|
|
696
1490
|
const excludedGlobs = loadExcludedGlobs(projectRoot, pagesPath);
|
|
697
|
-
const
|
|
1491
|
+
const gitOptIn = gitLastmod ?? seoConfig?.sitemap?.lastmodFromGit === true;
|
|
1492
|
+
const routeLastmods = !preview && gitOptIn ? deriveRouteLastmods({
|
|
1493
|
+
routes,
|
|
1494
|
+
projectRoot,
|
|
1495
|
+
sourcesForRoute: lastmodSources,
|
|
1496
|
+
contentPath,
|
|
1497
|
+
exclude: Array.isArray(seoConfig?.sitemap?.lastmodExclude) ? seoConfig.sitemap.lastmodExclude.filter((g) => typeof g === "string") : [],
|
|
1498
|
+
git,
|
|
1499
|
+
debug
|
|
1500
|
+
}).lastmods : void 0;
|
|
698
1501
|
let wroteSitemap = false;
|
|
699
1502
|
if (!preview) {
|
|
700
1503
|
const xml = buildSitemapXml({
|
|
@@ -704,10 +1507,10 @@ function emitSiteFiles(params) {
|
|
|
704
1507
|
exclude,
|
|
705
1508
|
noindex,
|
|
706
1509
|
excludedGlobs,
|
|
707
|
-
|
|
1510
|
+
routeLastmods
|
|
708
1511
|
});
|
|
709
1512
|
if (xml) {
|
|
710
|
-
|
|
1513
|
+
fs8.writeFileSync(path7.join(outDir, "sitemap.xml"), xml, "utf8");
|
|
711
1514
|
wroteSitemap = true;
|
|
712
1515
|
written.push("sitemap.xml");
|
|
713
1516
|
if (debug) console.log("[dcs-seo] wrote sitemap.xml");
|
|
@@ -715,21 +1518,36 @@ function emitSiteFiles(params) {
|
|
|
715
1518
|
console.log("[dcs-seo] no absolute <loc> derivable; sitemap.xml not written");
|
|
716
1519
|
}
|
|
717
1520
|
}
|
|
1521
|
+
const seoAiTraining = seoConfig?.robots?.aiTraining;
|
|
1522
|
+
const effectiveRobots = {
|
|
1523
|
+
...robots,
|
|
1524
|
+
aiTraining: robots.aiTraining ?? (typeof seoAiTraining === "boolean" ? seoAiTraining : true)
|
|
1525
|
+
};
|
|
718
1526
|
if (robots.enabled ?? true) {
|
|
719
|
-
const robotsPath =
|
|
720
|
-
const existing =
|
|
1527
|
+
const robotsPath = path7.join(outDir, "robots.txt");
|
|
1528
|
+
const existing = fs8.existsSync(robotsPath) && !robots.force ? fs8.readFileSync(robotsPath, "utf8") : null;
|
|
721
1529
|
const keepHandAuthored = existing !== null && isHandAuthoredRobotsAcceptable(existing);
|
|
722
1530
|
if (keepHandAuthored) {
|
|
723
|
-
if (
|
|
1531
|
+
if (effectiveRobots.aiTraining === false && !preview) {
|
|
1532
|
+
const conflicts = findAiTrainingRobotsConflicts(existing);
|
|
1533
|
+
if (conflicts.length > 0) throw new RobotsAiTrainingConflictError(robotsPath, conflicts);
|
|
1534
|
+
const { text, added } = appendAiTrainingOptOut(existing);
|
|
1535
|
+
if (added.length > 0) {
|
|
1536
|
+
fs8.writeFileSync(robotsPath, text, "utf8");
|
|
1537
|
+
written.push("robots.txt");
|
|
1538
|
+
}
|
|
1539
|
+
if (debug) console.log(`[dcs-seo] dist/robots.txt is hand-authored; appended AI training opt-out for ${added.join(", ") || "(none)"}`);
|
|
1540
|
+
} else if (debug) {
|
|
724
1541
|
console.log("[dcs-seo] dist/robots.txt is hand-authored and meets the floor; leaving it");
|
|
1542
|
+
}
|
|
725
1543
|
} else {
|
|
726
1544
|
const txt = buildRobotsTxt({
|
|
727
1545
|
siteUrl: effectiveSiteUrl,
|
|
728
1546
|
preview,
|
|
729
|
-
robots,
|
|
1547
|
+
robots: effectiveRobots,
|
|
730
1548
|
hasSitemap: wroteSitemap
|
|
731
1549
|
});
|
|
732
|
-
|
|
1550
|
+
fs8.writeFileSync(robotsPath, txt, "utf8");
|
|
733
1551
|
written.push("robots.txt");
|
|
734
1552
|
if (debug) {
|
|
735
1553
|
console.log(
|
|
@@ -748,7 +1566,7 @@ function emitSiteFiles(params) {
|
|
|
748
1566
|
excludedGlobs
|
|
749
1567
|
});
|
|
750
1568
|
if (txt) {
|
|
751
|
-
|
|
1569
|
+
fs8.writeFileSync(path7.join(outDir, "llms.txt"), txt, "utf8");
|
|
752
1570
|
written.push("llms.txt");
|
|
753
1571
|
if (debug) console.log("[dcs-seo] wrote llms.txt");
|
|
754
1572
|
} else if (debug) {
|
|
@@ -815,12 +1633,12 @@ function emitStaticSeoHtml(params) {
|
|
|
815
1633
|
});
|
|
816
1634
|
const html = spliceHeadHtml(shellHtml, tags);
|
|
817
1635
|
const outFile = routeToOutputFile(outDir, route.path);
|
|
818
|
-
|
|
819
|
-
|
|
1636
|
+
fs8.mkdirSync(path7.dirname(outFile), { recursive: true });
|
|
1637
|
+
fs8.writeFileSync(outFile, html, "utf8");
|
|
820
1638
|
written++;
|
|
821
1639
|
if (debug) {
|
|
822
1640
|
console.log(
|
|
823
|
-
`[dcs-seo] wrote ${
|
|
1641
|
+
`[dcs-seo] wrote ${path7.relative(outDir, outFile)} (title="${tags.title}"${forceNoindex ? ", noindex" : ""})`
|
|
824
1642
|
);
|
|
825
1643
|
}
|
|
826
1644
|
}
|
|
@@ -891,8 +1709,8 @@ async function runEmittedUrlHonesty(params) {
|
|
|
891
1709
|
for (const route of routes) {
|
|
892
1710
|
files.push({ path: routeToOutputFile(outDir, route.path), from: route.path, kind: "html" });
|
|
893
1711
|
}
|
|
894
|
-
files.push({ path:
|
|
895
|
-
files.push({ path:
|
|
1712
|
+
files.push({ path: path7.join(outDir, "sitemap.xml"), from: "sitemap.xml", kind: "sitemap" });
|
|
1713
|
+
files.push({ path: path7.join(outDir, "llms.txt"), from: "llms.txt", kind: "llms" });
|
|
896
1714
|
const collected = dedupeUrls(collectEmittedUrlsFromFiles(files));
|
|
897
1715
|
const classified = collected.map((u) => classifyUrl(u, siteUrl));
|
|
898
1716
|
const sameOrigin = auditSameOriginAssets({ urls: classified, outDir, base, allow });
|
|
@@ -974,11 +1792,11 @@ function runCharsetBudget(params) {
|
|
|
974
1792
|
const file = routeToOutputFile(outDir, route.path);
|
|
975
1793
|
let html;
|
|
976
1794
|
try {
|
|
977
|
-
html =
|
|
1795
|
+
html = fs8.readFileSync(file, "utf8");
|
|
978
1796
|
} catch {
|
|
979
1797
|
continue;
|
|
980
1798
|
}
|
|
981
|
-
const rel =
|
|
1799
|
+
const rel = path7.relative(outDir, file);
|
|
982
1800
|
const result = checkCharsetBudget(html);
|
|
983
1801
|
worstOffset = Math.max(worstOffset, result.offset);
|
|
984
1802
|
if (!result.ok) {
|
|
@@ -1022,7 +1840,10 @@ function dcsSeoPlugin(options = {}) {
|
|
|
1022
1840
|
// Self-detect preview builds from DCS_PREVIEW (mirrors dcsEditorPlugin) so a
|
|
1023
1841
|
// release/** SWA preview build never body-prerenders; an explicit option wins.
|
|
1024
1842
|
preview = process.env.DCS_PREVIEW === "true",
|
|
1025
|
-
llms = true
|
|
1843
|
+
llms = true,
|
|
1844
|
+
gitLastmod,
|
|
1845
|
+
lastmodSources,
|
|
1846
|
+
dirIndex = true
|
|
1026
1847
|
} = options;
|
|
1027
1848
|
let resolvedConfig;
|
|
1028
1849
|
let isDev = false;
|
|
@@ -1031,6 +1852,13 @@ function dcsSeoPlugin(options = {}) {
|
|
|
1031
1852
|
configResolved(config2) {
|
|
1032
1853
|
resolvedConfig = config2;
|
|
1033
1854
|
isDev = config2.command === "serve";
|
|
1855
|
+
if (config2.command === "build") {
|
|
1856
|
+
const siteConfig = config2.vitepress;
|
|
1857
|
+
if (isVitePressSiteConfig(siteConfig)) {
|
|
1858
|
+
if (dirIndex !== false) installDirIndex(siteConfig);
|
|
1859
|
+
else clearDirIndexManifest();
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1034
1862
|
},
|
|
1035
1863
|
config(config2, env) {
|
|
1036
1864
|
if (env.command === "serve") {
|
|
@@ -1116,12 +1944,12 @@ function dcsSeoPlugin(options = {}) {
|
|
|
1116
1944
|
try {
|
|
1117
1945
|
const projectRoot = resolvedConfig?.root || process.cwd();
|
|
1118
1946
|
const outDir = resolveOutDir(resolvedConfig);
|
|
1119
|
-
if (!
|
|
1947
|
+
if (!fs8.existsSync(outDir)) {
|
|
1120
1948
|
console.warn(`[dcs-seo] emitStaticHtml: outDir not found (${outDir}); skipping`);
|
|
1121
1949
|
return;
|
|
1122
1950
|
}
|
|
1123
|
-
const shellPath =
|
|
1124
|
-
if (!
|
|
1951
|
+
const shellPath = path7.join(outDir, "index.html");
|
|
1952
|
+
if (!fs8.existsSync(shellPath)) {
|
|
1125
1953
|
console.warn(
|
|
1126
1954
|
`[dcs-seo] emitStaticHtml: no index.html in ${outDir}; nothing to emit`
|
|
1127
1955
|
);
|
|
@@ -1140,7 +1968,7 @@ function dcsSeoPlugin(options = {}) {
|
|
|
1140
1968
|
`[dcs-seo] emitStaticHtml: ${seoPath} missing or unparseable; emitting with defaults only`
|
|
1141
1969
|
);
|
|
1142
1970
|
}
|
|
1143
|
-
const rawShellHtml =
|
|
1971
|
+
const rawShellHtml = fs8.readFileSync(shellPath, "utf8");
|
|
1144
1972
|
const shellHtml = hoistCharsetMeta(rawShellHtml);
|
|
1145
1973
|
{
|
|
1146
1974
|
const b = checkCharsetBudget(rawShellHtml);
|
|
@@ -1156,7 +1984,7 @@ function dcsSeoPlugin(options = {}) {
|
|
|
1156
1984
|
};
|
|
1157
1985
|
}
|
|
1158
1986
|
if (shellHtml !== rawShellHtml) {
|
|
1159
|
-
|
|
1987
|
+
fs8.writeFileSync(shellPath, shellHtml, "utf8");
|
|
1160
1988
|
const before = checkCharsetBudget(rawShellHtml);
|
|
1161
1989
|
const after = checkCharsetBudget(shellHtml);
|
|
1162
1990
|
console.log(
|
|
@@ -1196,6 +2024,9 @@ function dcsSeoPlugin(options = {}) {
|
|
|
1196
2024
|
preview,
|
|
1197
2025
|
robots,
|
|
1198
2026
|
llms,
|
|
2027
|
+
gitLastmod,
|
|
2028
|
+
lastmodSources,
|
|
2029
|
+
contentPath,
|
|
1199
2030
|
debug
|
|
1200
2031
|
});
|
|
1201
2032
|
if (debug) {
|
|
@@ -1270,6 +2101,7 @@ function dcsSeoPlugin(options = {}) {
|
|
|
1270
2101
|
renderForHonestyOnly
|
|
1271
2102
|
};
|
|
1272
2103
|
} catch (error) {
|
|
2104
|
+
if (error instanceof RobotsAiTrainingConflictError) throw error;
|
|
1273
2105
|
console.warn("[dcs-seo] emitStaticHtml failed; build output left unchanged:", error);
|
|
1274
2106
|
}
|
|
1275
2107
|
let headObservations = [];
|
|
@@ -1368,9 +2200,9 @@ function dcsSeoPlugin(options = {}) {
|
|
|
1368
2200
|
} finally {
|
|
1369
2201
|
if (reportPath) {
|
|
1370
2202
|
try {
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
console.log(`[dcs-seo] honesty report written: ${
|
|
2203
|
+
fs8.mkdirSync(path7.dirname(path7.resolve(reportPath)), { recursive: true });
|
|
2204
|
+
fs8.writeFileSync(path7.resolve(reportPath), JSON.stringify(report, null, 2), "utf8");
|
|
2205
|
+
console.log(`[dcs-seo] honesty report written: ${path7.resolve(reportPath)}`);
|
|
1374
2206
|
} catch (err) {
|
|
1375
2207
|
console.warn("[dcs-seo] could not write honesty report:", err);
|
|
1376
2208
|
}
|
|
@@ -1454,17 +2286,17 @@ function dcsSeoPlugin(options = {}) {
|
|
|
1454
2286
|
configureServer(server) {
|
|
1455
2287
|
const projectRoot = resolvedConfig?.root || process.cwd();
|
|
1456
2288
|
const watchPaths = [
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
].map((p) =>
|
|
2289
|
+
path7.resolve(projectRoot, seoPath),
|
|
2290
|
+
path7.resolve(projectRoot, "..", seoPath)
|
|
2291
|
+
].map((p) => path7.normalize(p));
|
|
1460
2292
|
watchPaths.forEach((watchPath) => {
|
|
1461
|
-
if (
|
|
2293
|
+
if (fs8.existsSync(watchPath)) {
|
|
1462
2294
|
server.watcher.add(watchPath);
|
|
1463
2295
|
}
|
|
1464
2296
|
});
|
|
1465
2297
|
let reloadTimer;
|
|
1466
2298
|
server.watcher.on("change", (changedPath) => {
|
|
1467
|
-
if (!watchPaths.includes(
|
|
2299
|
+
if (!watchPaths.includes(path7.normalize(changedPath))) return;
|
|
1468
2300
|
if (reloadTimer) clearTimeout(reloadTimer);
|
|
1469
2301
|
reloadTimer = setTimeout(() => {
|
|
1470
2302
|
if (debug) {
|
|
@@ -1630,14 +2462,14 @@ function buildPictureElement(entry, alt, extraAttrs, sizes) {
|
|
|
1630
2462
|
}
|
|
1631
2463
|
function loadCdnImageMap(projectRoot, relativeMapPath, debug) {
|
|
1632
2464
|
const possiblePaths = [
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
2465
|
+
path7.resolve(projectRoot, relativeMapPath),
|
|
2466
|
+
path7.resolve(projectRoot, "..", relativeMapPath),
|
|
2467
|
+
path7.resolve(process.cwd(), relativeMapPath)
|
|
1636
2468
|
];
|
|
1637
2469
|
for (const testPath of possiblePaths) {
|
|
1638
|
-
if (
|
|
2470
|
+
if (fs8.existsSync(testPath)) {
|
|
1639
2471
|
try {
|
|
1640
|
-
const raw =
|
|
2472
|
+
const raw = fs8.readFileSync(testPath, "utf8");
|
|
1641
2473
|
const data = JSON.parse(raw);
|
|
1642
2474
|
const map = /* @__PURE__ */ new Map();
|
|
1643
2475
|
for (const entry of data.images) {
|
|
@@ -1801,13 +2633,13 @@ function dcsCdnBuildEnd(options = {}) {
|
|
|
1801
2633
|
return;
|
|
1802
2634
|
}
|
|
1803
2635
|
const outDir = siteConfig.outDir;
|
|
1804
|
-
if (!
|
|
2636
|
+
if (!fs8.existsSync(outDir)) return;
|
|
1805
2637
|
let filesProcessed = 0;
|
|
1806
2638
|
let refsReplaced = 0;
|
|
1807
2639
|
function walkDir(dir) {
|
|
1808
|
-
const entries =
|
|
2640
|
+
const entries = fs8.readdirSync(dir, { withFileTypes: true });
|
|
1809
2641
|
for (const entry of entries) {
|
|
1810
|
-
const fullPath =
|
|
2642
|
+
const fullPath = path7.join(dir, entry.name);
|
|
1811
2643
|
if (entry.isDirectory()) {
|
|
1812
2644
|
walkDir(fullPath);
|
|
1813
2645
|
} else if (extensions.some((ext) => entry.name.endsWith(ext))) {
|
|
@@ -1816,7 +2648,7 @@ function dcsCdnBuildEnd(options = {}) {
|
|
|
1816
2648
|
}
|
|
1817
2649
|
}
|
|
1818
2650
|
function processFile(filePath) {
|
|
1819
|
-
let content =
|
|
2651
|
+
let content = fs8.readFileSync(filePath, "utf8");
|
|
1820
2652
|
if (!pathPrefixes.some((p) => content.includes(p))) return;
|
|
1821
2653
|
let changed = false;
|
|
1822
2654
|
if (filePath.endsWith(".html")) {
|
|
@@ -1851,7 +2683,7 @@ function dcsCdnBuildEnd(options = {}) {
|
|
|
1851
2683
|
}
|
|
1852
2684
|
}
|
|
1853
2685
|
if (changed) {
|
|
1854
|
-
|
|
2686
|
+
fs8.writeFileSync(filePath, content, "utf8");
|
|
1855
2687
|
filesProcessed++;
|
|
1856
2688
|
}
|
|
1857
2689
|
}
|
|
@@ -1897,88 +2729,7 @@ function responsiveImagePlugin(md) {
|
|
|
1897
2729
|
].join("\n");
|
|
1898
2730
|
};
|
|
1899
2731
|
}
|
|
1900
|
-
var BASE_CDN_ASSET = /^https?:\/\/files\.[^/]+\/(?:content\/)?[^/]+\/assets\/(?:[^/]+\/)*[a-f0-9-]+\.\w+(?:[?#].*)?$/i;
|
|
1901
|
-
function isFullSizeCdnUrl(url) {
|
|
1902
|
-
return BASE_CDN_ASSET.test(url.trim());
|
|
1903
|
-
}
|
|
1904
|
-
function readAttr(tag, name) {
|
|
1905
|
-
const m = tag.match(new RegExp(`\\b${name}=("([^"]*)"|'([^']*)')`, "i"));
|
|
1906
|
-
if (!m) return null;
|
|
1907
|
-
return m[2] ?? m[3] ?? "";
|
|
1908
|
-
}
|
|
1909
|
-
function findFullSizeCdnImages(html) {
|
|
1910
|
-
const violations = [];
|
|
1911
|
-
for (const m of html.matchAll(/<img\b[^>]*>/gi)) {
|
|
1912
|
-
const src = readAttr(m[0], "src");
|
|
1913
|
-
if (src && isFullSizeCdnUrl(src)) {
|
|
1914
|
-
violations.push({ url: src.trim(), tag: "img" });
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
for (const m of html.matchAll(/<source\b[^>]*>/gi)) {
|
|
1918
|
-
const srcset = readAttr(m[0], "srcset");
|
|
1919
|
-
if (!srcset) continue;
|
|
1920
|
-
for (const candidate of srcset.split(",")) {
|
|
1921
|
-
const url = candidate.trim().split(/\s+/)[0];
|
|
1922
|
-
if (url && isFullSizeCdnUrl(url)) {
|
|
1923
|
-
violations.push({ url, tag: "source" });
|
|
1924
|
-
}
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1927
|
-
return violations;
|
|
1928
|
-
}
|
|
1929
|
-
function dcsResponsiveImageLint(options = {}) {
|
|
1930
|
-
const { failOnViolation = false, extensions = [".html"], debug = false } = options;
|
|
1931
|
-
return async (siteConfig) => {
|
|
1932
|
-
const report = { filesScanned: 0, violations: [] };
|
|
1933
|
-
const outDir = siteConfig.outDir;
|
|
1934
|
-
if (!outDir || !fs5.existsSync(outDir)) return report;
|
|
1935
|
-
const walk = (dir) => {
|
|
1936
|
-
for (const entry of fs5.readdirSync(dir, { withFileTypes: true })) {
|
|
1937
|
-
const full = path5.join(dir, entry.name);
|
|
1938
|
-
if (entry.isDirectory()) {
|
|
1939
|
-
walk(full);
|
|
1940
|
-
} else if (extensions.some((ext) => entry.name.endsWith(ext))) {
|
|
1941
|
-
report.filesScanned++;
|
|
1942
|
-
const html = fs5.readFileSync(full, "utf8");
|
|
1943
|
-
if (!html.includes("/assets/")) continue;
|
|
1944
|
-
const rel = path5.relative(outDir, full);
|
|
1945
|
-
for (const v of findFullSizeCdnImages(html)) {
|
|
1946
|
-
report.violations.push({ ...v, file: rel });
|
|
1947
|
-
if (debug) {
|
|
1948
|
-
console.log(`[dcs-responsive-lint] ${rel}: <${v.tag}> full-size ${v.url}`);
|
|
1949
|
-
}
|
|
1950
|
-
}
|
|
1951
|
-
}
|
|
1952
|
-
}
|
|
1953
|
-
};
|
|
1954
|
-
walk(outDir);
|
|
1955
|
-
if (report.violations.length > 0) {
|
|
1956
|
-
const lines = report.violations.map((v) => ` ${v.file}: <${v.tag}> ${v.url}`).join("\n");
|
|
1957
|
-
const summary = `[dcs-responsive-lint] ${report.violations.length} full-size CDN image(s) shipped without a -sm/-md/-lg responsive variant across ${report.filesScanned} file(s):
|
|
1958
|
-
${lines}`;
|
|
1959
|
-
if (failOnViolation) {
|
|
1960
|
-
throw new Error(summary);
|
|
1961
|
-
}
|
|
1962
|
-
console.warn(summary);
|
|
1963
|
-
} else if (debug) {
|
|
1964
|
-
console.log(
|
|
1965
|
-
`[dcs-responsive-lint] clean \u2014 scanned ${report.filesScanned} file(s), no full-size images.`
|
|
1966
|
-
);
|
|
1967
|
-
}
|
|
1968
|
-
return report;
|
|
1969
|
-
};
|
|
1970
|
-
}
|
|
1971
|
-
function chainBuildEnd(...hooks) {
|
|
1972
|
-
const active = hooks.filter(
|
|
1973
|
-
(h2) => typeof h2 === "function"
|
|
1974
|
-
);
|
|
1975
|
-
return async (siteConfig) => {
|
|
1976
|
-
for (const hook of active) {
|
|
1977
|
-
await hook(siteConfig);
|
|
1978
|
-
}
|
|
1979
|
-
};
|
|
1980
|
-
}
|
|
1981
2732
|
|
|
1982
|
-
export { AGENT_CONFIG_ORIGINS, DCS_MOTION_TOKENS_CSS, DEFAULT_AGENT_API_BASE_URL, DEFAULT_AGENT_WIDGET_SCRIPT_URL, NoindexOrphanError, buildAgentWidgetLoaderScript, chainBuildEnd, collectNoindexMatchKeys, dcsAgentWidgetLoaderTag, dcsCdnBuildEnd, dcsCdnImagePlugin, dcsContentPlugin, dcsEditorPlugin, dcsMotionTokensStyleTag, dcsPreviewPlugin, dcsResponsiveImageLint, dcsSeoPlugin, emitSiteFiles, emitStaticSeoHtml, findFullSizeCdnImages, findOrphanNoindexEntries, isFullSizeCdnUrl, readAgentConfigOrigin, readSiteSlug, responsiveImagePlugin };
|
|
2733
|
+
export { AGENT_CONFIG_ORIGINS, CONTENT_WALK_LIMIT, DCS_MOTION_TOKENS_CSS, DEFAULT_AGENT_API_BASE_URL, DEFAULT_AGENT_WIDGET_SCRIPT_URL, DEFAULT_LASTMOD_EXCLUDE, DIR_INDEX_INSTALLED, DIR_INDEX_MANIFEST_ENV, DIR_INDEX_MANIFEST_SCHEMA, DirIndexError, IDENTICAL_LASTMOD_ROUTE_LIMIT, NoindexOrphanError, buildAgentWidgetLoaderScript, chainBuildEnd, clearDirIndexManifest, collectNoindexMatchKeys, dcsAgentWidgetLoaderTag, dcsCdnBuildEnd, dcsCdnImagePlugin, dcsContentPlugin, dcsDirIndexBuildEnd, dcsEditorPlugin, dcsMotionTokensStyleTag, dcsPreviewPlugin, dcsResponsiveImageLint, dcsSeoPlugin, defaultRouteSourceCandidates, deriveRouteLastmods, dirIndexCandidates, emitDirectoryIndexes, emitSiteFiles, emitStaticSeoHtml, findFullSizeCdnImages, findOrphanNoindexEntries, installDirIndex, isFullSizeCdnUrl, lastmodGlobToRegExp, readAgentConfigOrigin, readSiteSlug, responsiveImagePlugin };
|
|
1983
2734
|
//# sourceMappingURL=index.js.map
|
|
1984
2735
|
//# sourceMappingURL=index.js.map
|