@duffcloudservices/cms 0.13.13 → 0.13.15

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.
@@ -1,21 +1,22 @@
1
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-JWXI5HAZ.js';
2
2
  export { buildVitePressSeoHead, createSeoTransformPageData, defaultRelativePathToRoute } from '../chunk-JWXI5HAZ.js';
3
- import fs5 from 'fs';
4
- import path5 from 'path';
3
+ import fs7 from 'fs';
4
+ import path7 from 'path';
5
5
  import yaml4 from 'js-yaml';
6
+ import crypto from 'crypto';
6
7
  import http from 'http';
7
8
  import { defineComponent, h } from 'vue';
8
9
  import { isVectorImageUrl } from '@duffcloudservices/cms-core';
9
10
 
10
11
  function dcsSearchPaths(projectRoot, relPath) {
11
12
  return [
12
- path5.resolve(projectRoot, relPath),
13
- path5.resolve(projectRoot, "..", relPath),
14
- path5.resolve(process.cwd(), relPath)
13
+ path7.resolve(projectRoot, relPath),
14
+ path7.resolve(projectRoot, "..", relPath),
15
+ path7.resolve(process.cwd(), relPath)
15
16
  ];
16
17
  }
17
18
  function resolveDcsFile(projectRoot, relPath) {
18
- return dcsSearchPaths(projectRoot, relPath).find((p) => fs5.existsSync(p));
19
+ return dcsSearchPaths(projectRoot, relPath).find((p) => fs7.existsSync(p));
19
20
  }
20
21
  function readDcsYamlFresh(projectRoot, relPath, label, debug = false) {
21
22
  const found = resolveDcsFile(projectRoot, relPath);
@@ -24,7 +25,7 @@ function readDcsYamlFresh(projectRoot, relPath, label, debug = false) {
24
25
  return void 0;
25
26
  }
26
27
  try {
27
- return yaml4.load(fs5.readFileSync(found, "utf8"));
28
+ return yaml4.load(fs7.readFileSync(found, "utf8"));
28
29
  } catch (error) {
29
30
  console.warn(`[${label}] serve: failed to parse ${relPath}:`, error);
30
31
  return void 0;
@@ -97,13 +98,13 @@ function readSiteSlug(projectRoot) {
97
98
  }
98
99
  function readSiteYaml(projectRoot) {
99
100
  const candidates = [
100
- ...SITE_YAML_CANDIDATES.map((rel) => path5.resolve(projectRoot, rel)),
101
- path5.resolve(process.cwd(), ".dcs/site.yaml")
101
+ ...SITE_YAML_CANDIDATES.map((rel) => path7.resolve(projectRoot, rel)),
102
+ path7.resolve(process.cwd(), ".dcs/site.yaml")
102
103
  ];
103
104
  for (const candidate of candidates) {
104
105
  try {
105
- if (!fs5.existsSync(candidate)) continue;
106
- const parsed = yaml4.load(fs5.readFileSync(candidate, "utf8"));
106
+ if (!fs7.existsSync(candidate)) continue;
107
+ const parsed = yaml4.load(fs7.readFileSync(candidate, "utf8"));
107
108
  const slug = parsed && typeof parsed.site_slug === "string" ? parsed.site_slug.trim() : "";
108
109
  if (parsed && slug) return { slug, fields: parsed };
109
110
  } catch {
@@ -165,13 +166,13 @@ function dcsContentPlugin(options = {}) {
165
166
  }
166
167
  const projectRoot = config2.root || process.cwd();
167
168
  const possiblePaths = [
168
- path5.resolve(projectRoot, contentPath),
169
- path5.resolve(projectRoot, "..", contentPath),
170
- path5.resolve(process.cwd(), contentPath)
169
+ path7.resolve(projectRoot, contentPath),
170
+ path7.resolve(projectRoot, "..", contentPath),
171
+ path7.resolve(process.cwd(), contentPath)
171
172
  ];
172
173
  let foundPath;
173
174
  for (const testPath of possiblePaths) {
174
- if (fs5.existsSync(testPath)) {
175
+ if (fs7.existsSync(testPath)) {
175
176
  foundPath = testPath;
176
177
  break;
177
178
  }
@@ -190,7 +191,7 @@ function dcsContentPlugin(options = {}) {
190
191
  };
191
192
  }
192
193
  try {
193
- const fileContent = fs5.readFileSync(foundPath, "utf8");
194
+ const fileContent = fs7.readFileSync(foundPath, "utf8");
194
195
  const content = yaml4.load(fileContent);
195
196
  if (debug) {
196
197
  console.log(`[dcs-content] Loaded ${foundPath}`);
@@ -281,17 +282,17 @@ function dcsContentPlugin(options = {}) {
281
282
  configureServer(server) {
282
283
  const projectRoot = resolvedConfig?.root || process.cwd();
283
284
  const watchPaths = [
284
- path5.resolve(projectRoot, contentPath),
285
- path5.resolve(projectRoot, "..", contentPath)
286
- ].map((p) => path5.normalize(p));
285
+ path7.resolve(projectRoot, contentPath),
286
+ path7.resolve(projectRoot, "..", contentPath)
287
+ ].map((p) => path7.normalize(p));
287
288
  watchPaths.forEach((watchPath) => {
288
- if (fs5.existsSync(watchPath)) {
289
+ if (fs7.existsSync(watchPath)) {
289
290
  server.watcher.add(watchPath);
290
291
  }
291
292
  });
292
293
  let reloadTimer;
293
294
  server.watcher.on("change", (changedPath) => {
294
- if (!watchPaths.includes(path5.normalize(changedPath))) return;
295
+ if (!watchPaths.includes(path7.normalize(changedPath))) return;
295
296
  if (reloadTimer) clearTimeout(reloadTimer);
296
297
  reloadTimer = setTimeout(() => {
297
298
  if (debug) {
@@ -303,6 +304,266 @@ function dcsContentPlugin(options = {}) {
303
304
  }
304
305
  };
305
306
  }
307
+ var BASE_CDN_ASSET = /^https?:\/\/files\.[^/]+\/(?:content\/)?[^/]+\/assets\/(?:[^/]+\/)*[a-f0-9-]+\.\w+(?:[?#].*)?$/i;
308
+ function isFullSizeCdnUrl(url) {
309
+ return BASE_CDN_ASSET.test(url.trim());
310
+ }
311
+ function readAttr(tag, name) {
312
+ const m = tag.match(new RegExp(`\\b${name}=("([^"]*)"|'([^']*)')`, "i"));
313
+ if (!m) return null;
314
+ return m[2] ?? m[3] ?? "";
315
+ }
316
+ function findFullSizeCdnImages(html) {
317
+ const violations = [];
318
+ for (const m of html.matchAll(/<img\b[^>]*>/gi)) {
319
+ const src = readAttr(m[0], "src");
320
+ if (src && isFullSizeCdnUrl(src)) {
321
+ violations.push({ url: src.trim(), tag: "img" });
322
+ }
323
+ }
324
+ for (const m of html.matchAll(/<source\b[^>]*>/gi)) {
325
+ const srcset = readAttr(m[0], "srcset");
326
+ if (!srcset) continue;
327
+ for (const candidate of srcset.split(",")) {
328
+ const url = candidate.trim().split(/\s+/)[0];
329
+ if (url && isFullSizeCdnUrl(url)) {
330
+ violations.push({ url, tag: "source" });
331
+ }
332
+ }
333
+ }
334
+ return violations;
335
+ }
336
+ function dcsResponsiveImageLint(options = {}) {
337
+ const { failOnViolation = false, extensions = [".html"], debug = false } = options;
338
+ return async (siteConfig) => {
339
+ const report = { filesScanned: 0, violations: [] };
340
+ const outDir = siteConfig.outDir;
341
+ if (!outDir || !fs7.existsSync(outDir)) return report;
342
+ const walk = (dir) => {
343
+ for (const entry of fs7.readdirSync(dir, { withFileTypes: true })) {
344
+ const full = path7.join(dir, entry.name);
345
+ if (entry.isDirectory()) {
346
+ walk(full);
347
+ } else if (extensions.some((ext) => entry.name.endsWith(ext))) {
348
+ report.filesScanned++;
349
+ const html = fs7.readFileSync(full, "utf8");
350
+ if (!html.includes("/assets/")) continue;
351
+ const rel = path7.relative(outDir, full);
352
+ for (const v of findFullSizeCdnImages(html)) {
353
+ report.violations.push({ ...v, file: rel });
354
+ if (debug) {
355
+ console.log(`[dcs-responsive-lint] ${rel}: <${v.tag}> full-size ${v.url}`);
356
+ }
357
+ }
358
+ }
359
+ }
360
+ };
361
+ walk(outDir);
362
+ if (report.violations.length > 0) {
363
+ const lines = report.violations.map((v) => ` ${v.file}: <${v.tag}> ${v.url}`).join("\n");
364
+ 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):
365
+ ${lines}`;
366
+ if (failOnViolation) {
367
+ throw new Error(summary);
368
+ }
369
+ console.warn(summary);
370
+ } else if (debug) {
371
+ console.log(
372
+ `[dcs-responsive-lint] clean \u2014 scanned ${report.filesScanned} file(s), no full-size images.`
373
+ );
374
+ }
375
+ return report;
376
+ };
377
+ }
378
+ function chainBuildEnd(...hooks) {
379
+ const active = hooks.filter(
380
+ (h2) => typeof h2 === "function"
381
+ );
382
+ return async (siteConfig) => {
383
+ for (const hook of active) {
384
+ await hook(siteConfig);
385
+ }
386
+ };
387
+ }
388
+
389
+ // src/plugins/dcsDirIndex.ts
390
+ var DIR_INDEX_INSTALLED = /* @__PURE__ */ Symbol.for("dcs.cms.dirIndex.installed");
391
+ var DIR_INDEX_MANIFEST_ENV = "DCS_DIR_INDEX_MANIFEST";
392
+ var DIR_INDEX_MANIFEST_SCHEMA = "dcs.cms.dir-index-manifest/v1";
393
+ var INDEX_PAGE = /(^|\/)index\.md$/;
394
+ var DirIndexError = class extends Error {
395
+ constructor(message) {
396
+ super(message);
397
+ this.name = "DirIndexError";
398
+ }
399
+ };
400
+ function dirIndexCandidates(siteConfig) {
401
+ const map = siteConfig.rewrites?.map ?? {};
402
+ const out = [];
403
+ for (const page of siteConfig.pages) {
404
+ const mapped = (map[page] || page).replace(/\\/g, "/");
405
+ if (!mapped.endsWith(".md")) continue;
406
+ if (INDEX_PAGE.test(mapped)) continue;
407
+ if (mapped === "404.md") continue;
408
+ out.push(mapped);
409
+ }
410
+ return [...new Set(out)].sort();
411
+ }
412
+ function resolveManifestPath(options) {
413
+ const raw = options.manifestPath ?? process.env[DIR_INDEX_MANIFEST_ENV];
414
+ return raw ? path7.resolve(raw) : void 0;
415
+ }
416
+ function realpathNearest(p) {
417
+ let cur = path7.resolve(p);
418
+ const tail = [];
419
+ while (!fs7.existsSync(cur)) {
420
+ const parent = path7.dirname(cur);
421
+ if (parent === cur) break;
422
+ tail.unshift(path7.basename(cur));
423
+ cur = parent;
424
+ }
425
+ let real = cur;
426
+ try {
427
+ real = fs7.realpathSync.native(cur);
428
+ } catch {
429
+ }
430
+ return path7.join(real, ...tail);
431
+ }
432
+ function isInsideDir(dir, p) {
433
+ const abs = path7.resolve(p);
434
+ const dest = path7.join(realpathNearest(path7.dirname(abs)), path7.basename(abs));
435
+ const rel = path7.relative(realpathNearest(dir), dest);
436
+ if (rel === "") return true;
437
+ if (path7.isAbsolute(rel)) return false;
438
+ return !(rel === ".." || rel.startsWith(".." + path7.sep));
439
+ }
440
+ function clearDirIndexManifest(manifestPath = process.env[DIR_INDEX_MANIFEST_ENV]) {
441
+ if (!manifestPath) return void 0;
442
+ const file = path7.resolve(manifestPath);
443
+ try {
444
+ const st = fs7.lstatSync(file);
445
+ if (!st.isFile() && !st.isSymbolicLink()) return void 0;
446
+ } catch {
447
+ return void 0;
448
+ }
449
+ fs7.unlinkSync(file);
450
+ return file;
451
+ }
452
+ var sha256 = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex");
453
+ function writeManifest(file, manifest) {
454
+ fs7.mkdirSync(path7.dirname(file), { recursive: true });
455
+ const tmp = `${file}.${process.pid}.tmp`;
456
+ fs7.writeFileSync(tmp, `${JSON.stringify(manifest, null, 2)}
457
+ `);
458
+ fs7.renameSync(tmp, file);
459
+ }
460
+ function emitDirectoryIndexes(siteConfig, options = {}) {
461
+ const outDir = siteConfig.outDir;
462
+ const manifestPath = resolveManifestPath(options);
463
+ if (manifestPath) {
464
+ if (isInsideDir(outDir, manifestPath)) {
465
+ throw new DirIndexError(
466
+ `[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.`
467
+ );
468
+ }
469
+ fs7.rmSync(manifestPath, { force: true });
470
+ }
471
+ if (siteConfig.cleanUrls !== true) {
472
+ if (!manifestPath) return { written: 0, identical: 0, twins: [] };
473
+ writeManifest(manifestPath, { schema: DIR_INDEX_MANIFEST_SCHEMA, outDir: path7.resolve(outDir), cleanUrls: false, twins: [] });
474
+ return { written: 0, identical: 0, twins: [], manifestPath };
475
+ }
476
+ const missing = [];
477
+ const unequal = [];
478
+ const toWrite = [];
479
+ const identicalRel = [];
480
+ const entries = [];
481
+ for (const page of dirIndexCandidates(siteConfig)) {
482
+ const stem = page.slice(0, -".md".length);
483
+ const srcRel = `${stem}.html`;
484
+ const dstRel = `${stem}/index.html`;
485
+ const src = path7.join(outDir, srcRel);
486
+ const dst = path7.join(outDir, dstRel);
487
+ if (!fs7.existsSync(src) || !fs7.statSync(src).isFile()) {
488
+ missing.push(`${page} -> ${srcRel}`);
489
+ continue;
490
+ }
491
+ const bytes = fs7.readFileSync(src);
492
+ if (fs7.existsSync(dst)) {
493
+ const existing = fs7.statSync(dst).isFile() ? fs7.readFileSync(dst) : null;
494
+ if (existing && existing.equals(bytes)) {
495
+ identicalRel.push(dstRel);
496
+ entries.push({ twin: dstRel, source: srcRel, sha256: sha256(bytes) });
497
+ } else {
498
+ unequal.push(`${srcRel} != ${dstRel}`);
499
+ }
500
+ continue;
501
+ }
502
+ toWrite.push({ src, dst, rel: dstRel, srcRel, bytes });
503
+ }
504
+ const problems = [];
505
+ if (missing.length > 0) {
506
+ problems.push(
507
+ `${missing.length} page(s) VitePress lists have no rendered flat HTML:
508
+ ` + missing.map((m) => ` ${m}`).join("\n")
509
+ );
510
+ }
511
+ if (unequal.length > 0) {
512
+ problems.push(
513
+ `${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:
514
+ ` + unequal.map((u) => ` ${u}`).join("\n")
515
+ );
516
+ }
517
+ if (problems.length > 0) {
518
+ throw new DirIndexError(`[dcs-dir-index] build refused (nothing written).
519
+ ${problems.join("\n")}`);
520
+ }
521
+ for (const t of toWrite) {
522
+ fs7.mkdirSync(path7.dirname(t.dst), { recursive: true });
523
+ fs7.writeFileSync(t.dst, t.bytes);
524
+ entries.push({ twin: t.rel, source: t.srcRel, sha256: sha256(t.bytes) });
525
+ }
526
+ const twins = [...toWrite.map((t) => t.rel), ...identicalRel].sort();
527
+ console.log(`[dcs-dir-index] twins written=${toWrite.length} identical=${identicalRel.length}`);
528
+ if (!manifestPath) return { written: toWrite.length, identical: identicalRel.length, twins };
529
+ entries.sort((a, b) => a.twin < b.twin ? -1 : a.twin > b.twin ? 1 : 0);
530
+ writeManifest(manifestPath, { schema: DIR_INDEX_MANIFEST_SCHEMA, outDir: path7.resolve(outDir), cleanUrls: true, twins: entries });
531
+ console.log(`[dcs-dir-index] manifest ${manifestPath} (${entries.length} twin(s))`);
532
+ return { written: toWrite.length, identical: identicalRel.length, twins, manifestPath };
533
+ }
534
+ function emitOnce(siteConfig) {
535
+ const state = siteConfig[DIR_INDEX_INSTALLED];
536
+ if (state?.emitted) return void 0;
537
+ if (state) state.emitted = true;
538
+ return emitDirectoryIndexes(siteConfig);
539
+ }
540
+ function isVitePressSiteConfig(value) {
541
+ if (!value || typeof value !== "object") return false;
542
+ const v = value;
543
+ return typeof v.outDir === "string" && Array.isArray(v.pages);
544
+ }
545
+ function installDirIndex(siteConfig) {
546
+ const guarded = siteConfig;
547
+ if (guarded[DIR_INDEX_INSTALLED]) return false;
548
+ guarded[DIR_INDEX_INSTALLED] = { owner: "auto", emitted: false };
549
+ const original = siteConfig.buildEnd;
550
+ siteConfig.buildEnd = chainBuildEnd(
551
+ original ? (sc) => original.call(sc, sc) : void 0,
552
+ (sc) => {
553
+ emitOnce(sc);
554
+ }
555
+ );
556
+ return true;
557
+ }
558
+ function dcsDirIndexBuildEnd() {
559
+ return async (siteConfig) => {
560
+ const guarded = siteConfig;
561
+ const state = guarded[DIR_INDEX_INSTALLED];
562
+ if (state?.owner === "auto") return;
563
+ if (!state) guarded[DIR_INDEX_INSTALLED] = { owner: "manual", emitted: false };
564
+ emitOnce(guarded);
565
+ };
566
+ }
306
567
  function prerenderNavigationUrl(origin, routePath) {
307
568
  const url = new URL(routePath, origin);
308
569
  url.searchParams.set("dcs-no-telemetry", "");
@@ -356,32 +617,32 @@ async function startStaticServer(outDir) {
356
617
  } catch {
357
618
  pathname = "/";
358
619
  }
359
- const resolved = path5.resolve(outDir, "." + pathname);
360
- if (resolved !== outDir && !resolved.startsWith(outDir + path5.sep)) {
620
+ const resolved = path7.resolve(outDir, "." + pathname);
621
+ if (resolved !== outDir && !resolved.startsWith(outDir + path7.sep)) {
361
622
  res.writeHead(403);
362
623
  res.end();
363
624
  return;
364
625
  }
365
626
  let filePath = resolved;
366
627
  try {
367
- const stat = fs5.statSync(filePath);
368
- if (stat.isDirectory()) filePath = path5.join(filePath, "index.html");
628
+ const stat = fs7.statSync(filePath);
629
+ if (stat.isDirectory()) filePath = path7.join(filePath, "index.html");
369
630
  } catch {
370
- if (path5.extname(pathname)) {
631
+ if (path7.extname(pathname)) {
371
632
  res.writeHead(404);
372
633
  res.end();
373
634
  return;
374
635
  }
375
- filePath = path5.join(outDir, "index.html");
636
+ filePath = path7.join(outDir, "index.html");
376
637
  }
377
- fs5.readFile(filePath, (err, buf) => {
638
+ fs7.readFile(filePath, (err, buf) => {
378
639
  if (err) {
379
640
  res.writeHead(404);
380
641
  res.end();
381
642
  return;
382
643
  }
383
644
  res.writeHead(200, {
384
- "Content-Type": CONTENT_TYPES[path5.extname(filePath).toLowerCase()] ?? "application/octet-stream"
645
+ "Content-Type": CONTENT_TYPES[path7.extname(filePath).toLowerCase()] ?? "application/octet-stream"
385
646
  });
386
647
  res.end(buf);
387
648
  });
@@ -547,17 +808,17 @@ function readHonestyBlock(value) {
547
808
  }
548
809
  function resolveOutDir(config2) {
549
810
  const out = config2.build?.outDir || "dist";
550
- return path5.isAbsolute(out) ? out : path5.resolve(config2.root || process.cwd(), out);
811
+ return path7.isAbsolute(out) ? out : path7.resolve(config2.root || process.cwd(), out);
551
812
  }
552
813
  function loadSeoConfig(projectRoot, seoPath, debug) {
553
814
  const possiblePaths = [
554
- path5.resolve(projectRoot, seoPath),
555
- path5.resolve(projectRoot, "..", seoPath),
556
- path5.resolve(process.cwd(), seoPath)
815
+ path7.resolve(projectRoot, seoPath),
816
+ path7.resolve(projectRoot, "..", seoPath),
817
+ path7.resolve(process.cwd(), seoPath)
557
818
  ];
558
819
  let foundPath;
559
820
  for (const testPath of possiblePaths) {
560
- if (fs5.existsSync(testPath)) {
821
+ if (fs7.existsSync(testPath)) {
561
822
  foundPath = testPath;
562
823
  break;
563
824
  }
@@ -571,7 +832,7 @@ function loadSeoConfig(projectRoot, seoPath, debug) {
571
832
  return null;
572
833
  }
573
834
  try {
574
- const fileContent = fs5.readFileSync(foundPath, "utf8");
835
+ const fileContent = fs7.readFileSync(foundPath, "utf8");
575
836
  const config2 = yaml4.load(fileContent);
576
837
  return { config: config2, foundPath };
577
838
  } catch (error) {
@@ -581,17 +842,17 @@ function loadSeoConfig(projectRoot, seoPath, debug) {
581
842
  }
582
843
  function loadContentConfig(projectRoot, contentRelPath, debug) {
583
844
  const possiblePaths = [
584
- path5.resolve(projectRoot, contentRelPath),
585
- path5.resolve(projectRoot, "..", contentRelPath),
586
- path5.resolve(process.cwd(), contentRelPath)
845
+ path7.resolve(projectRoot, contentRelPath),
846
+ path7.resolve(projectRoot, "..", contentRelPath),
847
+ path7.resolve(process.cwd(), contentRelPath)
587
848
  ];
588
- const foundPath = possiblePaths.find((p) => fs5.existsSync(p));
849
+ const foundPath = possiblePaths.find((p) => fs7.existsSync(p));
589
850
  if (!foundPath) {
590
851
  if (debug) console.log(`[dcs-seo] No content.yaml found (reviews disabled)`);
591
852
  return void 0;
592
853
  }
593
854
  try {
594
- const parsed = yaml4.load(fs5.readFileSync(foundPath, "utf8"));
855
+ const parsed = yaml4.load(fs7.readFileSync(foundPath, "utf8"));
595
856
  if (!parsed || typeof parsed !== "object") return void 0;
596
857
  return parsed;
597
858
  } catch (error) {
@@ -601,14 +862,14 @@ function loadContentConfig(projectRoot, contentRelPath, debug) {
601
862
  }
602
863
  function loadExcludedGlobs(projectRoot, pagesPath) {
603
864
  const possiblePaths = [
604
- path5.resolve(projectRoot, pagesPath),
605
- path5.resolve(projectRoot, "..", pagesPath),
606
- path5.resolve(process.cwd(), pagesPath)
865
+ path7.resolve(projectRoot, pagesPath),
866
+ path7.resolve(projectRoot, "..", pagesPath),
867
+ path7.resolve(process.cwd(), pagesPath)
607
868
  ];
608
- const found = possiblePaths.find((p) => fs5.existsSync(p));
869
+ const found = possiblePaths.find((p) => fs7.existsSync(p));
609
870
  if (!found) return [];
610
871
  try {
611
- const raw = yaml4.load(fs5.readFileSync(found, "utf8"));
872
+ const raw = yaml4.load(fs7.readFileSync(found, "utf8"));
612
873
  const excluded = raw?.excluded;
613
874
  if (!Array.isArray(excluded)) return [];
614
875
  return excluded.filter((e) => typeof e === "string");
@@ -662,14 +923,14 @@ function deriveLastmod(seoConfig, projectRoot, pagesPath) {
662
923
  const fromSeo = seoConfig?.lastUpdated;
663
924
  if (typeof fromSeo === "string" && fromSeo.length > 0) return fromSeo;
664
925
  const possiblePaths = [
665
- path5.resolve(projectRoot, pagesPath),
666
- path5.resolve(projectRoot, "..", pagesPath),
667
- path5.resolve(process.cwd(), pagesPath)
926
+ path7.resolve(projectRoot, pagesPath),
927
+ path7.resolve(projectRoot, "..", pagesPath),
928
+ path7.resolve(process.cwd(), pagesPath)
668
929
  ];
669
- const found = possiblePaths.find((p) => fs5.existsSync(p));
930
+ const found = possiblePaths.find((p) => fs7.existsSync(p));
670
931
  if (!found) return void 0;
671
932
  try {
672
- const raw = yaml4.load(fs5.readFileSync(found, "utf8"));
933
+ const raw = yaml4.load(fs7.readFileSync(found, "utf8"));
673
934
  const fromPages = raw?.lastUpdated;
674
935
  if (typeof fromPages === "string" && fromPages.length > 0) return fromPages;
675
936
  } catch {
@@ -707,7 +968,7 @@ function emitSiteFiles(params) {
707
968
  lastmod
708
969
  });
709
970
  if (xml) {
710
- fs5.writeFileSync(path5.join(outDir, "sitemap.xml"), xml, "utf8");
971
+ fs7.writeFileSync(path7.join(outDir, "sitemap.xml"), xml, "utf8");
711
972
  wroteSitemap = true;
712
973
  written.push("sitemap.xml");
713
974
  if (debug) console.log("[dcs-seo] wrote sitemap.xml");
@@ -716,8 +977,8 @@ function emitSiteFiles(params) {
716
977
  }
717
978
  }
718
979
  if (robots.enabled ?? true) {
719
- const robotsPath = path5.join(outDir, "robots.txt");
720
- const existing = fs5.existsSync(robotsPath) && !robots.force ? fs5.readFileSync(robotsPath, "utf8") : null;
980
+ const robotsPath = path7.join(outDir, "robots.txt");
981
+ const existing = fs7.existsSync(robotsPath) && !robots.force ? fs7.readFileSync(robotsPath, "utf8") : null;
721
982
  const keepHandAuthored = existing !== null && isHandAuthoredRobotsAcceptable(existing);
722
983
  if (keepHandAuthored) {
723
984
  if (debug)
@@ -729,7 +990,7 @@ function emitSiteFiles(params) {
729
990
  robots,
730
991
  hasSitemap: wroteSitemap
731
992
  });
732
- fs5.writeFileSync(robotsPath, txt, "utf8");
993
+ fs7.writeFileSync(robotsPath, txt, "utf8");
733
994
  written.push("robots.txt");
734
995
  if (debug) {
735
996
  console.log(
@@ -748,7 +1009,7 @@ function emitSiteFiles(params) {
748
1009
  excludedGlobs
749
1010
  });
750
1011
  if (txt) {
751
- fs5.writeFileSync(path5.join(outDir, "llms.txt"), txt, "utf8");
1012
+ fs7.writeFileSync(path7.join(outDir, "llms.txt"), txt, "utf8");
752
1013
  written.push("llms.txt");
753
1014
  if (debug) console.log("[dcs-seo] wrote llms.txt");
754
1015
  } else if (debug) {
@@ -815,12 +1076,12 @@ function emitStaticSeoHtml(params) {
815
1076
  });
816
1077
  const html = spliceHeadHtml(shellHtml, tags);
817
1078
  const outFile = routeToOutputFile(outDir, route.path);
818
- fs5.mkdirSync(path5.dirname(outFile), { recursive: true });
819
- fs5.writeFileSync(outFile, html, "utf8");
1079
+ fs7.mkdirSync(path7.dirname(outFile), { recursive: true });
1080
+ fs7.writeFileSync(outFile, html, "utf8");
820
1081
  written++;
821
1082
  if (debug) {
822
1083
  console.log(
823
- `[dcs-seo] wrote ${path5.relative(outDir, outFile)} (title="${tags.title}"${forceNoindex ? ", noindex" : ""})`
1084
+ `[dcs-seo] wrote ${path7.relative(outDir, outFile)} (title="${tags.title}"${forceNoindex ? ", noindex" : ""})`
824
1085
  );
825
1086
  }
826
1087
  }
@@ -891,8 +1152,8 @@ async function runEmittedUrlHonesty(params) {
891
1152
  for (const route of routes) {
892
1153
  files.push({ path: routeToOutputFile(outDir, route.path), from: route.path, kind: "html" });
893
1154
  }
894
- files.push({ path: path5.join(outDir, "sitemap.xml"), from: "sitemap.xml", kind: "sitemap" });
895
- files.push({ path: path5.join(outDir, "llms.txt"), from: "llms.txt", kind: "llms" });
1155
+ files.push({ path: path7.join(outDir, "sitemap.xml"), from: "sitemap.xml", kind: "sitemap" });
1156
+ files.push({ path: path7.join(outDir, "llms.txt"), from: "llms.txt", kind: "llms" });
896
1157
  const collected = dedupeUrls(collectEmittedUrlsFromFiles(files));
897
1158
  const classified = collected.map((u) => classifyUrl(u, siteUrl));
898
1159
  const sameOrigin = auditSameOriginAssets({ urls: classified, outDir, base, allow });
@@ -974,11 +1235,11 @@ function runCharsetBudget(params) {
974
1235
  const file = routeToOutputFile(outDir, route.path);
975
1236
  let html;
976
1237
  try {
977
- html = fs5.readFileSync(file, "utf8");
1238
+ html = fs7.readFileSync(file, "utf8");
978
1239
  } catch {
979
1240
  continue;
980
1241
  }
981
- const rel = path5.relative(outDir, file);
1242
+ const rel = path7.relative(outDir, file);
982
1243
  const result = checkCharsetBudget(html);
983
1244
  worstOffset = Math.max(worstOffset, result.offset);
984
1245
  if (!result.ok) {
@@ -1022,7 +1283,8 @@ function dcsSeoPlugin(options = {}) {
1022
1283
  // Self-detect preview builds from DCS_PREVIEW (mirrors dcsEditorPlugin) so a
1023
1284
  // release/** SWA preview build never body-prerenders; an explicit option wins.
1024
1285
  preview = process.env.DCS_PREVIEW === "true",
1025
- llms = true
1286
+ llms = true,
1287
+ dirIndex = true
1026
1288
  } = options;
1027
1289
  let resolvedConfig;
1028
1290
  let isDev = false;
@@ -1031,6 +1293,13 @@ function dcsSeoPlugin(options = {}) {
1031
1293
  configResolved(config2) {
1032
1294
  resolvedConfig = config2;
1033
1295
  isDev = config2.command === "serve";
1296
+ if (config2.command === "build") {
1297
+ const siteConfig = config2.vitepress;
1298
+ if (isVitePressSiteConfig(siteConfig)) {
1299
+ if (dirIndex !== false) installDirIndex(siteConfig);
1300
+ else clearDirIndexManifest();
1301
+ }
1302
+ }
1034
1303
  },
1035
1304
  config(config2, env) {
1036
1305
  if (env.command === "serve") {
@@ -1116,12 +1385,12 @@ function dcsSeoPlugin(options = {}) {
1116
1385
  try {
1117
1386
  const projectRoot = resolvedConfig?.root || process.cwd();
1118
1387
  const outDir = resolveOutDir(resolvedConfig);
1119
- if (!fs5.existsSync(outDir)) {
1388
+ if (!fs7.existsSync(outDir)) {
1120
1389
  console.warn(`[dcs-seo] emitStaticHtml: outDir not found (${outDir}); skipping`);
1121
1390
  return;
1122
1391
  }
1123
- const shellPath = path5.join(outDir, "index.html");
1124
- if (!fs5.existsSync(shellPath)) {
1392
+ const shellPath = path7.join(outDir, "index.html");
1393
+ if (!fs7.existsSync(shellPath)) {
1125
1394
  console.warn(
1126
1395
  `[dcs-seo] emitStaticHtml: no index.html in ${outDir}; nothing to emit`
1127
1396
  );
@@ -1140,7 +1409,7 @@ function dcsSeoPlugin(options = {}) {
1140
1409
  `[dcs-seo] emitStaticHtml: ${seoPath} missing or unparseable; emitting with defaults only`
1141
1410
  );
1142
1411
  }
1143
- const rawShellHtml = fs5.readFileSync(shellPath, "utf8");
1412
+ const rawShellHtml = fs7.readFileSync(shellPath, "utf8");
1144
1413
  const shellHtml = hoistCharsetMeta(rawShellHtml);
1145
1414
  {
1146
1415
  const b = checkCharsetBudget(rawShellHtml);
@@ -1156,7 +1425,7 @@ function dcsSeoPlugin(options = {}) {
1156
1425
  };
1157
1426
  }
1158
1427
  if (shellHtml !== rawShellHtml) {
1159
- fs5.writeFileSync(shellPath, shellHtml, "utf8");
1428
+ fs7.writeFileSync(shellPath, shellHtml, "utf8");
1160
1429
  const before = checkCharsetBudget(rawShellHtml);
1161
1430
  const after = checkCharsetBudget(shellHtml);
1162
1431
  console.log(
@@ -1368,9 +1637,9 @@ function dcsSeoPlugin(options = {}) {
1368
1637
  } finally {
1369
1638
  if (reportPath) {
1370
1639
  try {
1371
- fs5.mkdirSync(path5.dirname(path5.resolve(reportPath)), { recursive: true });
1372
- fs5.writeFileSync(path5.resolve(reportPath), JSON.stringify(report, null, 2), "utf8");
1373
- console.log(`[dcs-seo] honesty report written: ${path5.resolve(reportPath)}`);
1640
+ fs7.mkdirSync(path7.dirname(path7.resolve(reportPath)), { recursive: true });
1641
+ fs7.writeFileSync(path7.resolve(reportPath), JSON.stringify(report, null, 2), "utf8");
1642
+ console.log(`[dcs-seo] honesty report written: ${path7.resolve(reportPath)}`);
1374
1643
  } catch (err) {
1375
1644
  console.warn("[dcs-seo] could not write honesty report:", err);
1376
1645
  }
@@ -1454,17 +1723,17 @@ function dcsSeoPlugin(options = {}) {
1454
1723
  configureServer(server) {
1455
1724
  const projectRoot = resolvedConfig?.root || process.cwd();
1456
1725
  const watchPaths = [
1457
- path5.resolve(projectRoot, seoPath),
1458
- path5.resolve(projectRoot, "..", seoPath)
1459
- ].map((p) => path5.normalize(p));
1726
+ path7.resolve(projectRoot, seoPath),
1727
+ path7.resolve(projectRoot, "..", seoPath)
1728
+ ].map((p) => path7.normalize(p));
1460
1729
  watchPaths.forEach((watchPath) => {
1461
- if (fs5.existsSync(watchPath)) {
1730
+ if (fs7.existsSync(watchPath)) {
1462
1731
  server.watcher.add(watchPath);
1463
1732
  }
1464
1733
  });
1465
1734
  let reloadTimer;
1466
1735
  server.watcher.on("change", (changedPath) => {
1467
- if (!watchPaths.includes(path5.normalize(changedPath))) return;
1736
+ if (!watchPaths.includes(path7.normalize(changedPath))) return;
1468
1737
  if (reloadTimer) clearTimeout(reloadTimer);
1469
1738
  reloadTimer = setTimeout(() => {
1470
1739
  if (debug) {
@@ -1630,14 +1899,14 @@ function buildPictureElement(entry, alt, extraAttrs, sizes) {
1630
1899
  }
1631
1900
  function loadCdnImageMap(projectRoot, relativeMapPath, debug) {
1632
1901
  const possiblePaths = [
1633
- path5.resolve(projectRoot, relativeMapPath),
1634
- path5.resolve(projectRoot, "..", relativeMapPath),
1635
- path5.resolve(process.cwd(), relativeMapPath)
1902
+ path7.resolve(projectRoot, relativeMapPath),
1903
+ path7.resolve(projectRoot, "..", relativeMapPath),
1904
+ path7.resolve(process.cwd(), relativeMapPath)
1636
1905
  ];
1637
1906
  for (const testPath of possiblePaths) {
1638
- if (fs5.existsSync(testPath)) {
1907
+ if (fs7.existsSync(testPath)) {
1639
1908
  try {
1640
- const raw = fs5.readFileSync(testPath, "utf8");
1909
+ const raw = fs7.readFileSync(testPath, "utf8");
1641
1910
  const data = JSON.parse(raw);
1642
1911
  const map = /* @__PURE__ */ new Map();
1643
1912
  for (const entry of data.images) {
@@ -1801,13 +2070,13 @@ function dcsCdnBuildEnd(options = {}) {
1801
2070
  return;
1802
2071
  }
1803
2072
  const outDir = siteConfig.outDir;
1804
- if (!fs5.existsSync(outDir)) return;
2073
+ if (!fs7.existsSync(outDir)) return;
1805
2074
  let filesProcessed = 0;
1806
2075
  let refsReplaced = 0;
1807
2076
  function walkDir(dir) {
1808
- const entries = fs5.readdirSync(dir, { withFileTypes: true });
2077
+ const entries = fs7.readdirSync(dir, { withFileTypes: true });
1809
2078
  for (const entry of entries) {
1810
- const fullPath = path5.join(dir, entry.name);
2079
+ const fullPath = path7.join(dir, entry.name);
1811
2080
  if (entry.isDirectory()) {
1812
2081
  walkDir(fullPath);
1813
2082
  } else if (extensions.some((ext) => entry.name.endsWith(ext))) {
@@ -1816,7 +2085,7 @@ function dcsCdnBuildEnd(options = {}) {
1816
2085
  }
1817
2086
  }
1818
2087
  function processFile(filePath) {
1819
- let content = fs5.readFileSync(filePath, "utf8");
2088
+ let content = fs7.readFileSync(filePath, "utf8");
1820
2089
  if (!pathPrefixes.some((p) => content.includes(p))) return;
1821
2090
  let changed = false;
1822
2091
  if (filePath.endsWith(".html")) {
@@ -1851,7 +2120,7 @@ function dcsCdnBuildEnd(options = {}) {
1851
2120
  }
1852
2121
  }
1853
2122
  if (changed) {
1854
- fs5.writeFileSync(filePath, content, "utf8");
2123
+ fs7.writeFileSync(filePath, content, "utf8");
1855
2124
  filesProcessed++;
1856
2125
  }
1857
2126
  }
@@ -1897,88 +2166,7 @@ function responsiveImagePlugin(md) {
1897
2166
  ].join("\n");
1898
2167
  };
1899
2168
  }
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
2169
 
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 };
2170
+ export { AGENT_CONFIG_ORIGINS, DCS_MOTION_TOKENS_CSS, DEFAULT_AGENT_API_BASE_URL, DEFAULT_AGENT_WIDGET_SCRIPT_URL, DIR_INDEX_INSTALLED, DIR_INDEX_MANIFEST_ENV, DIR_INDEX_MANIFEST_SCHEMA, DirIndexError, NoindexOrphanError, buildAgentWidgetLoaderScript, chainBuildEnd, clearDirIndexManifest, collectNoindexMatchKeys, dcsAgentWidgetLoaderTag, dcsCdnBuildEnd, dcsCdnImagePlugin, dcsContentPlugin, dcsDirIndexBuildEnd, dcsEditorPlugin, dcsMotionTokensStyleTag, dcsPreviewPlugin, dcsResponsiveImageLint, dcsSeoPlugin, dirIndexCandidates, emitDirectoryIndexes, emitSiteFiles, emitStaticSeoHtml, findFullSizeCdnImages, findOrphanNoindexEntries, installDirIndex, isFullSizeCdnUrl, readAgentConfigOrigin, readSiteSlug, responsiveImagePlugin };
1983
2171
  //# sourceMappingURL=index.js.map
1984
2172
  //# sourceMappingURL=index.js.map