@duffcloudservices/cms 0.8.0 → 0.9.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.
@@ -1,28 +1,66 @@
1
1
  import { buildSitemapXml, isHandAuthoredRobotsAcceptable, buildRobotsTxt, buildLlmsTxt, matchesExcludedGlob, breadcrumbTrailFromRoute, findReviewItemsForPage, buildHeadTags, spliceHeadHtml, loadPagesManifest } from '../chunk-UPAMLKOQ.js';
2
2
  export { buildVitePressSeoHead, createSeoTransformPageData, defaultRelativePathToRoute } from '../chunk-UPAMLKOQ.js';
3
- import fs2 from 'fs';
4
- import path2 from 'path';
5
- import yaml2 from 'js-yaml';
3
+ import fs3 from 'fs';
4
+ import path3 from 'path';
5
+ import yaml3 from 'js-yaml';
6
6
  import { defineComponent, h } from 'vue';
7
7
 
8
+ function dcsSearchPaths(projectRoot, relPath) {
9
+ return [
10
+ path3.resolve(projectRoot, relPath),
11
+ path3.resolve(projectRoot, "..", relPath),
12
+ path3.resolve(process.cwd(), relPath)
13
+ ];
14
+ }
15
+ function resolveDcsFile(projectRoot, relPath) {
16
+ return dcsSearchPaths(projectRoot, relPath).find((p) => fs3.existsSync(p));
17
+ }
18
+ function readDcsYamlFresh(projectRoot, relPath, label, debug = false) {
19
+ const found = resolveDcsFile(projectRoot, relPath);
20
+ if (!found) {
21
+ if (debug) console.log(`[${label}] serve: no ${relPath} found; global left unset`);
22
+ return void 0;
23
+ }
24
+ try {
25
+ return yaml3.load(fs3.readFileSync(found, "utf8"));
26
+ } catch (error) {
27
+ console.warn(`[${label}] serve: failed to parse ${relPath}:`, error);
28
+ return void 0;
29
+ }
30
+ }
31
+ function buildGlobalAssignScript(globalName, value) {
32
+ const json = JSON.stringify(value ?? null).replace(/</g, "\\u003c");
33
+ return `globalThis.${globalName} = ${json};`;
34
+ }
35
+
36
+ // src/plugins/dcsContentPlugin.ts
8
37
  function dcsContentPlugin(options = {}) {
9
38
  const { contentPath = ".dcs/content.yaml", debug = false } = options;
10
39
  let resolvedConfig;
40
+ let isDev = false;
11
41
  return {
12
42
  name: "dcs-content",
13
43
  configResolved(config) {
14
44
  resolvedConfig = config;
45
+ isDev = config.command === "serve";
15
46
  },
16
- config(config) {
47
+ config(config, env) {
48
+ if (env.command === "serve") {
49
+ return {
50
+ define: {
51
+ __DCS_CONTENT__: "globalThis.__DCS_CONTENT__"
52
+ }
53
+ };
54
+ }
17
55
  const projectRoot = config.root || process.cwd();
18
56
  const possiblePaths = [
19
- path2.resolve(projectRoot, contentPath),
20
- path2.resolve(projectRoot, "..", contentPath),
21
- path2.resolve(process.cwd(), contentPath)
57
+ path3.resolve(projectRoot, contentPath),
58
+ path3.resolve(projectRoot, "..", contentPath),
59
+ path3.resolve(process.cwd(), contentPath)
22
60
  ];
23
61
  let foundPath;
24
62
  for (const testPath of possiblePaths) {
25
- if (fs2.existsSync(testPath)) {
63
+ if (fs3.existsSync(testPath)) {
26
64
  foundPath = testPath;
27
65
  break;
28
66
  }
@@ -40,8 +78,8 @@ function dcsContentPlugin(options = {}) {
40
78
  };
41
79
  }
42
80
  try {
43
- const fileContent = fs2.readFileSync(foundPath, "utf8");
44
- const content = yaml2.load(fileContent);
81
+ const fileContent = fs3.readFileSync(foundPath, "utf8");
82
+ const content = yaml3.load(fileContent);
45
83
  if (debug) {
46
84
  console.log(`[dcs-content] Loaded ${foundPath}`);
47
85
  console.log(`[dcs-content] Version: ${content.version}`);
@@ -62,42 +100,88 @@ function dcsContentPlugin(options = {}) {
62
100
  };
63
101
  }
64
102
  },
65
- // Watch for changes in development
103
+ /**
104
+ * Dev-only: inject the FRESH on-disk `content.yaml` as an inline
105
+ * `globalThis.__DCS_CONTENT__ = {…}` classic script at the top of `<head>`.
106
+ *
107
+ * Runs on every dev HTML request, so the portal's `?_hc` hard reload (or any
108
+ * full page reload) re-reads the YAML with no restart. A classic `<script>`
109
+ * in `<head>` executes during HTML parsing, before the deferred module app
110
+ * entry, so the global is set before the consumer's `useTextContent` setup
111
+ * reads it. Gated on `isDev` so it never runs in `vite`/`vitepress build`
112
+ * (the build path keeps the baked `define` literal).
113
+ */
114
+ transformIndexHtml: {
115
+ order: "pre",
116
+ handler(html) {
117
+ if (!isDev) return html;
118
+ const projectRoot = resolvedConfig?.root || process.cwd();
119
+ const content = readDcsYamlFresh(
120
+ projectRoot,
121
+ contentPath,
122
+ "dcs-content",
123
+ debug
124
+ );
125
+ if (content === void 0) return html;
126
+ if (debug) {
127
+ console.log("[dcs-content] serve: injecting fresh __DCS_CONTENT__ into <head>");
128
+ }
129
+ const tags = [
130
+ {
131
+ tag: "script",
132
+ children: buildGlobalAssignScript("__DCS_CONTENT__", content),
133
+ injectTo: "head-prepend"
134
+ }
135
+ ];
136
+ return { html, tags };
137
+ }
138
+ },
139
+ // Watch for changes in development.
140
+ //
141
+ // Downgraded from `server.restart()` to a debounced client `full-reload`:
142
+ // freshness already comes from `transformIndexHtml` re-reading the YAML on
143
+ // every HTML request, so all we need on change is to nudge the browser to
144
+ // reload. A `server.restart()` would rebuild VitePress's dev MiniSearch
145
+ // index and can throw "server restart failed" on a duplicate heading id —
146
+ // exactly the fragility this fix removes. A `full-reload` does neither.
66
147
  configureServer(server) {
67
148
  const projectRoot = resolvedConfig?.root || process.cwd();
68
149
  const watchPaths = [
69
- path2.resolve(projectRoot, contentPath),
70
- path2.resolve(projectRoot, "..", contentPath)
71
- ];
150
+ path3.resolve(projectRoot, contentPath),
151
+ path3.resolve(projectRoot, "..", contentPath)
152
+ ].map((p) => path3.normalize(p));
72
153
  watchPaths.forEach((watchPath) => {
73
- if (fs2.existsSync(watchPath)) {
154
+ if (fs3.existsSync(watchPath)) {
74
155
  server.watcher.add(watchPath);
75
- server.watcher.on("change", (changedPath) => {
76
- if (changedPath === watchPath) {
77
- if (debug) {
78
- console.log("[dcs-content] content.yaml changed, triggering reload");
79
- }
80
- server.restart();
81
- }
82
- });
83
156
  }
84
157
  });
158
+ let reloadTimer;
159
+ server.watcher.on("change", (changedPath) => {
160
+ if (!watchPaths.includes(path3.normalize(changedPath))) return;
161
+ if (reloadTimer) clearTimeout(reloadTimer);
162
+ reloadTimer = setTimeout(() => {
163
+ if (debug) {
164
+ console.log("[dcs-content] content.yaml changed, sending full-reload");
165
+ }
166
+ server.ws.send({ type: "full-reload" });
167
+ }, 100);
168
+ });
85
169
  }
86
170
  };
87
171
  }
88
172
  function resolveOutDir(config) {
89
173
  const out = config.build?.outDir || "dist";
90
- return path2.isAbsolute(out) ? out : path2.resolve(config.root || process.cwd(), out);
174
+ return path3.isAbsolute(out) ? out : path3.resolve(config.root || process.cwd(), out);
91
175
  }
92
176
  function loadSeoConfig(projectRoot, seoPath, debug) {
93
177
  const possiblePaths = [
94
- path2.resolve(projectRoot, seoPath),
95
- path2.resolve(projectRoot, "..", seoPath),
96
- path2.resolve(process.cwd(), seoPath)
178
+ path3.resolve(projectRoot, seoPath),
179
+ path3.resolve(projectRoot, "..", seoPath),
180
+ path3.resolve(process.cwd(), seoPath)
97
181
  ];
98
182
  let foundPath;
99
183
  for (const testPath of possiblePaths) {
100
- if (fs2.existsSync(testPath)) {
184
+ if (fs3.existsSync(testPath)) {
101
185
  foundPath = testPath;
102
186
  break;
103
187
  }
@@ -111,8 +195,8 @@ function loadSeoConfig(projectRoot, seoPath, debug) {
111
195
  return null;
112
196
  }
113
197
  try {
114
- const fileContent = fs2.readFileSync(foundPath, "utf8");
115
- const config = yaml2.load(fileContent);
198
+ const fileContent = fs3.readFileSync(foundPath, "utf8");
199
+ const config = yaml3.load(fileContent);
116
200
  return { config, foundPath };
117
201
  } catch (error) {
118
202
  console.warn("[dcs-seo] Failed to parse seo.yaml:", error);
@@ -121,17 +205,17 @@ function loadSeoConfig(projectRoot, seoPath, debug) {
121
205
  }
122
206
  function loadContentConfig(projectRoot, contentRelPath, debug) {
123
207
  const possiblePaths = [
124
- path2.resolve(projectRoot, contentRelPath),
125
- path2.resolve(projectRoot, "..", contentRelPath),
126
- path2.resolve(process.cwd(), contentRelPath)
208
+ path3.resolve(projectRoot, contentRelPath),
209
+ path3.resolve(projectRoot, "..", contentRelPath),
210
+ path3.resolve(process.cwd(), contentRelPath)
127
211
  ];
128
- const foundPath = possiblePaths.find((p) => fs2.existsSync(p));
212
+ const foundPath = possiblePaths.find((p) => fs3.existsSync(p));
129
213
  if (!foundPath) {
130
214
  if (debug) console.log(`[dcs-seo] No content.yaml found (reviews disabled)`);
131
215
  return void 0;
132
216
  }
133
217
  try {
134
- const parsed = yaml2.load(fs2.readFileSync(foundPath, "utf8"));
218
+ const parsed = yaml3.load(fs3.readFileSync(foundPath, "utf8"));
135
219
  if (!parsed || typeof parsed !== "object") return void 0;
136
220
  return parsed;
137
221
  } catch (error) {
@@ -141,19 +225,19 @@ function loadContentConfig(projectRoot, contentRelPath, debug) {
141
225
  }
142
226
  function routeToOutputFile(outDir, routePath) {
143
227
  const trimmed = routePath.replace(/^\/+/, "").replace(/\/+$/, "");
144
- if (trimmed === "") return path2.join(outDir, "index.html");
145
- return path2.join(outDir, ...trimmed.split("/"), "index.html");
228
+ if (trimmed === "") return path3.join(outDir, "index.html");
229
+ return path3.join(outDir, ...trimmed.split("/"), "index.html");
146
230
  }
147
231
  function loadExcludedGlobs(projectRoot, pagesPath) {
148
232
  const possiblePaths = [
149
- path2.resolve(projectRoot, pagesPath),
150
- path2.resolve(projectRoot, "..", pagesPath),
151
- path2.resolve(process.cwd(), pagesPath)
233
+ path3.resolve(projectRoot, pagesPath),
234
+ path3.resolve(projectRoot, "..", pagesPath),
235
+ path3.resolve(process.cwd(), pagesPath)
152
236
  ];
153
- const found = possiblePaths.find((p) => fs2.existsSync(p));
237
+ const found = possiblePaths.find((p) => fs3.existsSync(p));
154
238
  if (!found) return [];
155
239
  try {
156
- const raw = yaml2.load(fs2.readFileSync(found, "utf8"));
240
+ const raw = yaml3.load(fs3.readFileSync(found, "utf8"));
157
241
  const excluded = raw?.excluded;
158
242
  if (!Array.isArray(excluded)) return [];
159
243
  return excluded.filter((e) => typeof e === "string");
@@ -165,14 +249,14 @@ function deriveLastmod(seoConfig, projectRoot, pagesPath) {
165
249
  const fromSeo = seoConfig?.lastUpdated;
166
250
  if (typeof fromSeo === "string" && fromSeo.length > 0) return fromSeo;
167
251
  const possiblePaths = [
168
- path2.resolve(projectRoot, pagesPath),
169
- path2.resolve(projectRoot, "..", pagesPath),
170
- path2.resolve(process.cwd(), pagesPath)
252
+ path3.resolve(projectRoot, pagesPath),
253
+ path3.resolve(projectRoot, "..", pagesPath),
254
+ path3.resolve(process.cwd(), pagesPath)
171
255
  ];
172
- const found = possiblePaths.find((p) => fs2.existsSync(p));
256
+ const found = possiblePaths.find((p) => fs3.existsSync(p));
173
257
  if (!found) return void 0;
174
258
  try {
175
- const raw = yaml2.load(fs2.readFileSync(found, "utf8"));
259
+ const raw = yaml3.load(fs3.readFileSync(found, "utf8"));
176
260
  const fromPages = raw?.lastUpdated;
177
261
  if (typeof fromPages === "string" && fromPages.length > 0) return fromPages;
178
262
  } catch {
@@ -210,7 +294,7 @@ function emitSiteFiles(params) {
210
294
  lastmod
211
295
  });
212
296
  if (xml) {
213
- fs2.writeFileSync(path2.join(outDir, "sitemap.xml"), xml, "utf8");
297
+ fs3.writeFileSync(path3.join(outDir, "sitemap.xml"), xml, "utf8");
214
298
  wroteSitemap = true;
215
299
  written.push("sitemap.xml");
216
300
  if (debug) console.log("[dcs-seo] wrote sitemap.xml");
@@ -219,8 +303,8 @@ function emitSiteFiles(params) {
219
303
  }
220
304
  }
221
305
  if (robots.enabled ?? true) {
222
- const robotsPath = path2.join(outDir, "robots.txt");
223
- const existing = fs2.existsSync(robotsPath) && !robots.force ? fs2.readFileSync(robotsPath, "utf8") : null;
306
+ const robotsPath = path3.join(outDir, "robots.txt");
307
+ const existing = fs3.existsSync(robotsPath) && !robots.force ? fs3.readFileSync(robotsPath, "utf8") : null;
224
308
  const keepHandAuthored = existing !== null && isHandAuthoredRobotsAcceptable(existing);
225
309
  if (keepHandAuthored) {
226
310
  if (debug)
@@ -232,7 +316,7 @@ function emitSiteFiles(params) {
232
316
  robots,
233
317
  hasSitemap: wroteSitemap
234
318
  });
235
- fs2.writeFileSync(robotsPath, txt, "utf8");
319
+ fs3.writeFileSync(robotsPath, txt, "utf8");
236
320
  written.push("robots.txt");
237
321
  if (debug) {
238
322
  console.log(
@@ -251,7 +335,7 @@ function emitSiteFiles(params) {
251
335
  excludedGlobs
252
336
  });
253
337
  if (txt) {
254
- fs2.writeFileSync(path2.join(outDir, "llms.txt"), txt, "utf8");
338
+ fs3.writeFileSync(path3.join(outDir, "llms.txt"), txt, "utf8");
255
339
  written.push("llms.txt");
256
340
  if (debug) console.log("[dcs-seo] wrote llms.txt");
257
341
  } else if (debug) {
@@ -316,12 +400,12 @@ function emitStaticSeoHtml(params) {
316
400
  });
317
401
  const html = spliceHeadHtml(shellHtml, tags);
318
402
  const outFile = routeToOutputFile(outDir, route.path);
319
- fs2.mkdirSync(path2.dirname(outFile), { recursive: true });
320
- fs2.writeFileSync(outFile, html, "utf8");
403
+ fs3.mkdirSync(path3.dirname(outFile), { recursive: true });
404
+ fs3.writeFileSync(outFile, html, "utf8");
321
405
  written++;
322
406
  if (debug) {
323
407
  console.log(
324
- `[dcs-seo] wrote ${path2.relative(outDir, outFile)} (title="${tags.title}"${forceNoindex ? ", noindex" : ""})`
408
+ `[dcs-seo] wrote ${path3.relative(outDir, outFile)} (title="${tags.title}"${forceNoindex ? ", noindex" : ""})`
325
409
  );
326
410
  }
327
411
  }
@@ -345,12 +429,21 @@ function dcsSeoPlugin(options = {}) {
345
429
  llms = true
346
430
  } = options;
347
431
  let resolvedConfig;
432
+ let isDev = false;
348
433
  return {
349
434
  name: "dcs-seo",
350
435
  configResolved(config) {
351
436
  resolvedConfig = config;
437
+ isDev = config.command === "serve";
352
438
  },
353
- config(config) {
439
+ config(config, env) {
440
+ if (env.command === "serve") {
441
+ return {
442
+ define: {
443
+ __DCS_SEO__: "globalThis.__DCS_SEO__"
444
+ }
445
+ };
446
+ }
354
447
  const projectRoot = config.root || process.cwd();
355
448
  const loaded = loadSeoConfig(projectRoot, seoPath, debug);
356
449
  if (!loaded) {
@@ -396,12 +489,12 @@ function dcsSeoPlugin(options = {}) {
396
489
  try {
397
490
  const projectRoot = resolvedConfig?.root || process.cwd();
398
491
  const outDir = resolveOutDir(resolvedConfig);
399
- if (!fs2.existsSync(outDir)) {
492
+ if (!fs3.existsSync(outDir)) {
400
493
  console.warn(`[dcs-seo] emitStaticHtml: outDir not found (${outDir}); skipping`);
401
494
  return;
402
495
  }
403
- const shellPath = path2.join(outDir, "index.html");
404
- if (!fs2.existsSync(shellPath)) {
496
+ const shellPath = path3.join(outDir, "index.html");
497
+ if (!fs3.existsSync(shellPath)) {
405
498
  console.warn(
406
499
  `[dcs-seo] emitStaticHtml: no index.html in ${outDir}; nothing to emit`
407
500
  );
@@ -420,7 +513,7 @@ function dcsSeoPlugin(options = {}) {
420
513
  `[dcs-seo] emitStaticHtml: ${seoPath} missing or unparseable; emitting with defaults only`
421
514
  );
422
515
  }
423
- const shellHtml = fs2.readFileSync(shellPath, "utf8");
516
+ const shellHtml = fs3.readFileSync(shellPath, "utf8");
424
517
  const excludedGlobs = loadExcludedGlobs(projectRoot, pagesPath);
425
518
  const contentConfig = loadContentConfig(projectRoot, contentPath, debug);
426
519
  const written = emitStaticSeoHtml({
@@ -462,26 +555,64 @@ function dcsSeoPlugin(options = {}) {
462
555
  console.warn("[dcs-seo] emitStaticHtml failed; build output left unchanged:", error);
463
556
  }
464
557
  },
465
- // Watch for changes in development
558
+ /**
559
+ * Dev-only: inject the FRESH on-disk `seo.yaml` as an inline
560
+ * `globalThis.__DCS_SEO__ = {…}` classic script at the top of `<head>`,
561
+ * mirroring dcsContentPlugin. Lets the runtime `useSEO` SPA path reflect
562
+ * on-disk SEO edits on the portal's `?_hc` hard reload with no restart.
563
+ * Gated on `isDev` so it never runs in `vite`/`vitepress build` (the build
564
+ * path keeps the baked `define` literal + the `writeBundle` emitter).
565
+ */
566
+ transformIndexHtml: {
567
+ order: "pre",
568
+ handler(html) {
569
+ if (!isDev) return html;
570
+ const projectRoot = resolvedConfig?.root || process.cwd();
571
+ const config = readDcsYamlFresh(projectRoot, seoPath, "dcs-seo", debug);
572
+ if (config === void 0) return html;
573
+ if (debug) {
574
+ console.log("[dcs-seo] serve: injecting fresh __DCS_SEO__ into <head>");
575
+ }
576
+ const tags = [
577
+ {
578
+ tag: "script",
579
+ children: buildGlobalAssignScript("__DCS_SEO__", config),
580
+ injectTo: "head-prepend"
581
+ }
582
+ ];
583
+ return { html, tags };
584
+ }
585
+ },
586
+ // Watch for changes in development.
587
+ //
588
+ // Downgraded from `server.restart()` to a debounced client `full-reload`:
589
+ // freshness already comes from `transformIndexHtml` re-reading the YAML on
590
+ // every HTML request, so all we need on change is a browser reload. A
591
+ // `server.restart()` would rebuild VitePress's dev MiniSearch index and can
592
+ // throw "server restart failed" on a duplicate heading id — the fragility
593
+ // this fix removes. A `full-reload` does neither.
466
594
  configureServer(server) {
467
595
  const projectRoot = resolvedConfig?.root || process.cwd();
468
596
  const watchPaths = [
469
- path2.resolve(projectRoot, seoPath),
470
- path2.resolve(projectRoot, "..", seoPath)
471
- ];
597
+ path3.resolve(projectRoot, seoPath),
598
+ path3.resolve(projectRoot, "..", seoPath)
599
+ ].map((p) => path3.normalize(p));
472
600
  watchPaths.forEach((watchPath) => {
473
- if (fs2.existsSync(watchPath)) {
601
+ if (fs3.existsSync(watchPath)) {
474
602
  server.watcher.add(watchPath);
475
- server.watcher.on("change", (changedPath) => {
476
- if (changedPath === watchPath) {
477
- if (debug) {
478
- console.log("[dcs-seo] seo.yaml changed, triggering reload");
479
- }
480
- server.restart();
481
- }
482
- });
483
603
  }
484
604
  });
605
+ let reloadTimer;
606
+ server.watcher.on("change", (changedPath) => {
607
+ if (!watchPaths.includes(path3.normalize(changedPath))) return;
608
+ if (reloadTimer) clearTimeout(reloadTimer);
609
+ reloadTimer = setTimeout(() => {
610
+ if (debug) {
611
+ console.log("[dcs-seo] seo.yaml changed, sending full-reload");
612
+ }
613
+ server.ws.send({ type: "full-reload" });
614
+ }, 100);
615
+ });
485
616
  }
486
617
  };
487
618
  }
@@ -493,11 +624,24 @@ function dcsEditorPlugin(options = {}) {
493
624
  const RIBBON_VIRTUAL_PATH = "/__dcs-preview-ribbon.js";
494
625
  let isDev = false;
495
626
  let basePath = "/";
627
+ let isPreview = false;
496
628
  return {
497
629
  name: "dcs-editor-bridge",
630
+ // Preview only: stop Vite running an unreachable HMR WebSocket server.
631
+ // Freshness comes from the cms content/seo plugins (fresh transformIndexHtml
632
+ // re-read) + the portal's ?_hc hard reload, not HMR. NOTE: this alone does
633
+ // NOT silence the browser — Vite still injects @vite/client and calls
634
+ // connect(); the client-side stub in transformIndexHtml is what removes the
635
+ // console errors. A normal local `vite dev` (no DCS_PREVIEW) keeps full HMR.
636
+ config(_config, env) {
637
+ if (env.command === "serve" && process.env.DCS_PREVIEW === "true") {
638
+ return { server: { hmr: false } };
639
+ }
640
+ },
498
641
  configResolved(config) {
499
642
  isDev = config.command === "serve";
500
643
  basePath = config.base ?? "/";
644
+ isPreview = process.env.DCS_PREVIEW === "true";
501
645
  },
502
646
  resolveId(id) {
503
647
  if (id === VIRTUAL_PATH || id === RIBBON_VIRTUAL_PATH) {
@@ -565,9 +709,15 @@ if (document.readyState === 'loading') {
565
709
  }
566
710
  const editorTag = `<script type="module" src="${VIRTUAL_PATH}"></script>`;
567
711
  const ribbonTag = `<script type="module" src="${RIBBON_VIRTUAL_PATH}"></script>`;
568
- return html.replace("</body>", `${editorTag}
712
+ const bodyHtml = html.replace("</body>", `${editorTag}
569
713
  ${ribbonTag}
570
714
  </body>`);
715
+ if (!isPreview) return bodyHtml;
716
+ const wsStub = `(function(){try{var N=window.WebSocket;if(!N)return;function hmr(p){return p==='vite-hmr'||(Array.isArray(p)&&p.indexOf('vite-hmr')!==-1)}function Inert(){this.readyState=0}Inert.prototype.send=function(){};Inert.prototype.close=function(){};Inert.prototype.addEventListener=function(){};Inert.prototype.removeEventListener=function(){};var W=function(u,p){if(hmr(p))return new Inert();return new N(u,p)};W.prototype=N.prototype;W.CONNECTING=N.CONNECTING;W.OPEN=N.OPEN;W.CLOSING=N.CLOSING;W.CLOSED=N.CLOSED;window.WebSocket=W}catch(e){}})()`;
717
+ return {
718
+ html: bodyHtml,
719
+ tags: [{ tag: "script", children: wsStub, injectTo: "head-prepend" }]
720
+ };
571
721
  }
572
722
  }
573
723
  };
@@ -611,14 +761,14 @@ function buildPictureElement(entry, alt, extraAttrs, sizes) {
611
761
  }
612
762
  function loadCdnImageMap(projectRoot, relativeMapPath, debug) {
613
763
  const possiblePaths = [
614
- path2.resolve(projectRoot, relativeMapPath),
615
- path2.resolve(projectRoot, "..", relativeMapPath),
616
- path2.resolve(process.cwd(), relativeMapPath)
764
+ path3.resolve(projectRoot, relativeMapPath),
765
+ path3.resolve(projectRoot, "..", relativeMapPath),
766
+ path3.resolve(process.cwd(), relativeMapPath)
617
767
  ];
618
768
  for (const testPath of possiblePaths) {
619
- if (fs2.existsSync(testPath)) {
769
+ if (fs3.existsSync(testPath)) {
620
770
  try {
621
- const raw = fs2.readFileSync(testPath, "utf8");
771
+ const raw = fs3.readFileSync(testPath, "utf8");
622
772
  const data = JSON.parse(raw);
623
773
  const map = /* @__PURE__ */ new Map();
624
774
  for (const entry of data.images) {
@@ -779,13 +929,13 @@ function dcsCdnBuildEnd(options = {}) {
779
929
  return;
780
930
  }
781
931
  const outDir = siteConfig.outDir;
782
- if (!fs2.existsSync(outDir)) return;
932
+ if (!fs3.existsSync(outDir)) return;
783
933
  let filesProcessed = 0;
784
934
  let refsReplaced = 0;
785
935
  function walkDir(dir) {
786
- const entries = fs2.readdirSync(dir, { withFileTypes: true });
936
+ const entries = fs3.readdirSync(dir, { withFileTypes: true });
787
937
  for (const entry of entries) {
788
- const fullPath = path2.join(dir, entry.name);
938
+ const fullPath = path3.join(dir, entry.name);
789
939
  if (entry.isDirectory()) {
790
940
  walkDir(fullPath);
791
941
  } else if (extensions.some((ext) => entry.name.endsWith(ext))) {
@@ -794,7 +944,7 @@ function dcsCdnBuildEnd(options = {}) {
794
944
  }
795
945
  }
796
946
  function processFile(filePath) {
797
- let content = fs2.readFileSync(filePath, "utf8");
947
+ let content = fs3.readFileSync(filePath, "utf8");
798
948
  if (!pathPrefixes.some((p) => content.includes(p))) return;
799
949
  let changed = false;
800
950
  if (filePath.endsWith(".html")) {
@@ -829,7 +979,7 @@ function dcsCdnBuildEnd(options = {}) {
829
979
  }
830
980
  }
831
981
  if (changed) {
832
- fs2.writeFileSync(filePath, content, "utf8");
982
+ fs3.writeFileSync(filePath, content, "utf8");
833
983
  filesProcessed++;
834
984
  }
835
985
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/dcsContentPlugin.ts","../../src/plugins/dcsSeoPlugin.ts","../../src/plugins/dcsEditorPlugin.ts","../../src/plugins/dcsPreviewPlugin.ts","../../src/plugins/dcsCdnImagePlugin.ts","../../src/plugins/responsiveImagePlugin.ts"],"names":["path","fs","yaml","escapeHtml"],"mappings":";;;;;;;AAqDO,SAAS,gBAAA,CAAiB,OAAA,GAAmC,EAAC,EAAW;AAC9E,EAAA,MAAM,EAAE,WAAA,GAAc,mBAAA,EAAqB,KAAA,GAAQ,OAAM,GAAI,OAAA;AAE7D,EAAA,IAAI,cAAA;AAEJ,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,aAAA;AAAA,IAEN,eAAe,MAAA,EAAQ;AACrB,MAAA,cAAA,GAAiB,MAAA;AAAA,IACnB,CAAA;AAAA,IAEA,OAAO,MAAA,EAAQ;AACb,MAAA,MAAM,WAAA,GAAc,MAAA,CAAO,IAAA,IAAQ,OAAA,CAAQ,GAAA,EAAI;AAI/C,MAAA,MAAM,aAAA,GAAgB;AAAA,QACpBA,KAAA,CAAK,OAAA,CAAQ,WAAA,EAAa,WAAW,CAAA;AAAA,QACrCA,KAAA,CAAK,OAAA,CAAQ,WAAA,EAAa,IAAA,EA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vite\n *\n * Reads `.dcs/content.yaml` at build time and injects content\n * as `__DCS_CONTENT__` global variable for use by useTextContent.\n *\n * @example\n * ```typescript\n * // vite.config.ts\n * import { dcsContentPlugin } from '@duffcloudservices/cms/plugins'\n *\n * export default defineConfig({\n * plugins: [\n * dcsContentPlugin({ debug: true })\n * ]\n * })\n * ```\n *\n * For VitePress:\n * ```typescript\n * // .vitepress/config.ts\n * import { defineConfig } from 'vitepress'\n * import { dcsContentPlugin } from '@duffcloudservices/cms/plugins'\n *\n * export default defineConfig({\n * vite: {\n * plugins: [\n * dcsContentPlugin()\n * ]\n * }\n * })\n * ```\n */\n\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport yaml from 'js-yaml'\nimport type { Plugin, ResolvedConfig } from 'vite'\nimport type { DcsContentFile } from '../types/content'\n\nexport interface DcsContentPluginOptions {\n /** Path to content.yaml relative to project root (default: '.dcs/content.yaml') */\n contentPath?: string\n /** Enable debug logging */\n debug?: boolean\n}\n\n/**\n * Vite plugin that injects .dcs/content.yaml at build time.\n *\n * @param options - Plugin configuration\n * @returns Vite plugin\n */\nexport function dcsContentPlugin(options: DcsContentPluginOptions = {}): Plugin {\n const { contentPath = '.dcs/content.yaml', debug = false } = options\n\n let resolvedConfig: ResolvedConfig\n\n return {\n name: 'dcs-content',\n\n configResolved(config) {\n resolvedConfig = config\n },\n\n config(config) {\n const projectRoot = config.root || process.cwd()\n\n // Try to find content.yaml in multiple locations\n // VitePress projects have the docs folder as root, so check parent too\n const possiblePaths = [\n path.resolve(projectRoot, contentPath),\n path.resolve(projectRoot, '..', contentPath),\n path.resolve(process.cwd(), contentPath),\n ]\n\n let foundPath: string | undefined\n for (const testPath of possiblePaths) {\n if (fs.existsSync(testPath)) {\n foundPath = testPath\n break\n }\n }\n\n if (!foundPath) {\n if (debug) {\n console.log('[dcs-content] No content.yaml found at:')\n possiblePaths.forEach((p) => console.log(` - ${p}`))\n console.log('[dcs-content] Using defaults only')\n }\n return {\n define: {\n __DCS_CONTENT__: 'undefined',\n },\n }\n }\n\n try {\n const fileContent = fs.readFileSync(foundPath, 'utf8')\n const content = yaml.load(fileContent) as DcsContentFile\n\n if (debug) {\n console.log(`[dcs-content] Loaded ${foundPath}`)\n console.log(`[dcs-content] Version: ${content.version}`)\n console.log(`[dcs-content] Pages: ${Object.keys(content.pages ?? {}).join(', ') || '(none)'}`)\n console.log(`[dcs-content] Global keys: ${Object.keys(content.global ?? {}).length}`)\n }\n\n return {\n define: {\n __DCS_CONTENT__: JSON.stringify(content),\n },\n }\n } catch (error) {\n console.warn('[dcs-content] Failed to parse content.yaml:', error)\n return {\n define: {\n __DCS_CONTENT__: 'undefined',\n },\n }\n }\n },\n\n // Watch for changes in development\n configureServer(server) {\n const projectRoot = resolvedConfig?.root || process.cwd()\n\n const watchPaths = [\n path.resolve(projectRoot, contentPath),\n path.resolve(projectRoot, '..', contentPath),\n ]\n\n watchPaths.forEach((watchPath) => {\n if (fs.existsSync(watchPath)) {\n server.watcher.add(watchPath)\n\n server.watcher.on('change', (changedPath) => {\n if (changedPath === watchPath) {\n if (debug) {\n console.log('[dcs-content] content.yaml changed, triggering reload')\n }\n server.restart()\n }\n })\n }\n })\n },\n }\n}\n","/**\n * DCS SEO Plugin for Vite\n *\n * Two responsibilities, both driven by `.dcs/seo.yaml`:\n *\n * 1. **Build-time define** (always on): reads `.dcs/seo.yaml` and injects it as\n * the `__DCS_SEO__` global for the runtime `useSEO` composable.\n *\n * 2. **Static `<head>` emitter** (opt-in via `emitStaticHtml: true`, default\n * OFF): after the bundle is written, reads the SPA's built `index.html`,\n * and for every route in `.dcs/pages.yaml` writes a per-route\n * `dist/<path>/index.html` whose `<head>` carries the resolved title, meta,\n * canonical, Open Graph, Twitter, and JSON-LD tags. This gives a Vue SPA\n * per-route static SEO **without** vite-ssg.\n *\n * VitePress sites already bake SEO via their own config, so they leave this\n * option OFF and are completely unaffected.\n *\n * @example Runtime define only (default — safe for VitePress)\n * ```typescript\n * // vite.config.ts\n * import { dcsSeoPlugin } from '@duffcloudservices/cms/plugins'\n *\n * export default defineConfig({\n * plugins: [dcsSeoPlugin({ debug: true })]\n * })\n * ```\n *\n * @example Vue SPA with per-route static <head> emission\n * ```typescript\n * // vite.config.ts\n * import { dcsSeoPlugin } from '@duffcloudservices/cms/plugins'\n *\n * export default defineConfig({\n * plugins: [\n * dcsSeoPlugin({\n * emitStaticHtml: true, // turn the emitter ON\n * pagesPath: '.dcs/pages.yaml', // route manifest (default)\n * noindex: ['account', 'projects'], // robots: noindex,nofollow\n * exclude: ['/preview'], // skip these routes entirely\n * })\n * ]\n * })\n * ```\n */\n\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport yaml from 'js-yaml'\nimport type { Plugin, ResolvedConfig } from 'vite'\nimport type { SeoConfiguration } from '../types/seo'\nimport { buildHeadTags } from '../seo/headTags'\nimport { spliceHeadHtml } from '../seo/spliceHeadHtml'\nimport { loadPagesManifest, type PageRouteEntry } from '../seo/pagesManifest'\nimport {\n buildSitemapXml,\n buildRobotsTxt,\n buildLlmsTxt,\n matchesExcludedGlob,\n isHandAuthoredRobotsAcceptable,\n type DcsRobotsOptions,\n} from '../seo/sitemap'\nimport {\n breadcrumbTrailFromRoute,\n findReviewItemsForPage,\n type ContentConfig,\n type ReviewSource,\n type BlogMeta,\n type FaqSource,\n} from '../seo/schemaGraph'\n\nexport interface DcsSeoPluginOptions {\n /** Path to seo.yaml relative to project root (default: '.dcs/seo.yaml') */\n seoPath?: string\n /** Enable debug logging */\n debug?: boolean\n\n /**\n * Opt-in: emit per-route static `<head>` (meta + JSON-LD) into the built\n * `dist/` at the end of the build. Default `false` — VitePress sites and any\n * site that bakes its own SEO are unaffected when this is off.\n */\n emitStaticHtml?: boolean\n\n /**\n * Path to the route manifest relative to project root, used only when\n * `emitStaticHtml` is true. Default `'.dcs/pages.yaml'`.\n */\n pagesPath?: string\n\n /**\n * Path to `content.yaml` relative to project root, used only when\n * `emitStaticHtml` is true. Threads REAL reviews into the honest\n * Review/aggregateRating on the per-route LocalBusiness node. Default\n * `'.dcs/content.yaml'`. Missing/unparseable ⇒ no reviews emitted.\n */\n contentPath?: string\n\n /**\n * Routes to skip entirely (no per-route HTML written). Matched against the\n * route `path` (e.g. `'/preview'`) OR the route `slug` (e.g. `'account'`).\n */\n exclude?: string[]\n\n /**\n * Routes that should receive `robots: noindex, nofollow`. Matched against the\n * route `path` OR `slug`. The home route (`/`) still overwrites\n * `dist/index.html`.\n */\n noindex?: string[]\n\n /**\n * Opt-in: emit the site-wide static files `dist/sitemap.xml`,\n * `dist/robots.txt`, and `dist/llms.txt` after the per-route HTML loop.\n *\n * Defaults to whatever `emitStaticHtml` is — so every site already calling\n * `dcsSeoPlugin({ emitStaticHtml: true })` gets sitemap/robots/llms for free\n * with zero per-site edits. Set explicitly to `false` to keep emitting\n * per-route HTML without the site files. The whole block is wrapped in the\n * same try/catch + existsSync guards, so it can never break a build.\n */\n emitSiteFiles?: boolean\n\n /**\n * Canonical production origin, e.g. `https://ironoakcontractors.com`. Used as\n * the sitemap/llms base and the absolute `Sitemap:` line in robots.txt. When\n * absent, falls back to `seo.yaml`'s `global.siteUrl`; if neither is known and\n * no per-page canonicals exist, the sitemap + llms.txt no-op (robots still\n * emits). Never guessed.\n */\n siteUrl?: string\n\n /** robots.txt override hooks (disallow/allow/extra/aiBots/force). */\n robots?: DcsRobotsOptions\n\n /**\n * Preview / staging gate. When `true`, robots.txt becomes `Disallow: /` (no\n * `Sitemap:` line) and neither sitemap.xml nor llms.txt is emitted (privacy).\n * Detected ONLY via this explicit option — never guessed.\n */\n preview?: boolean\n\n /** Emit `dist/llms.txt` (default `true`; always off in preview mode). */\n llms?: boolean\n}\n\n/** Resolve the SPA output directory from Vite config (absolute path). */\nfunction resolveOutDir(config: ResolvedConfig): string {\n const out = config.build?.outDir || 'dist'\n return path.isAbsolute(out) ? out : path.resolve(config.root || process.cwd(), out)\n}\n\n/**\n * Load + parse seo.yaml from the usual `.dcs` locations.\n * Returns `{ config, foundPath }` or `null` (missing/unparseable).\n */\nfunction loadSeoConfig(\n projectRoot: string,\n seoPath: string,\n debug: boolean\n): { config: SeoConfiguration; foundPath: string } | null {\n const possiblePaths = [\n path.resolve(projectRoot, seoPath),\n path.resolve(projectRoot, '..', seoPath),\n path.resolve(process.cwd(), seoPath),\n ]\n\n let foundPath: string | undefined\n for (const testPath of possiblePaths) {\n if (fs.existsSync(testPath)) {\n foundPath = testPath\n break\n }\n }\n\n if (!foundPath) {\n if (debug) {\n console.log('[dcs-seo] No seo.yaml found at:')\n possiblePaths.forEach((p) => console.log(` - ${p}`))\n console.log('[dcs-seo] Using defaults only')\n }\n return null\n }\n\n try {\n const fileContent = fs.readFileSync(foundPath, 'utf8')\n const config = yaml.load(fileContent) as SeoConfiguration\n return { config, foundPath }\n } catch (error) {\n console.warn('[dcs-seo] Failed to parse seo.yaml:', error)\n return null\n }\n}\n\n/**\n * Load + parse `.dcs/content.yaml` from the usual `.dcs` locations. Returns the\n * parsed config or `undefined` (missing/unparseable). Used to thread REAL\n * reviews into the honest Review/aggregateRating builder. Never throws.\n */\nfunction loadContentConfig(\n projectRoot: string,\n contentRelPath: string,\n debug: boolean\n): ContentConfig | undefined {\n const possiblePaths = [\n path.resolve(projectRoot, contentRelPath),\n path.resolve(projectRoot, '..', contentRelPath),\n path.resolve(process.cwd(), contentRelPath),\n ]\n const foundPath = possiblePaths.find((p) => fs.existsSync(p))\n if (!foundPath) {\n if (debug) console.log(`[dcs-seo] No content.yaml found (reviews disabled)`)\n return undefined\n }\n try {\n const parsed = yaml.load(fs.readFileSync(foundPath, 'utf8'))\n if (!parsed || typeof parsed !== 'object') return undefined\n return parsed as ContentConfig\n } catch (error) {\n console.warn('[dcs-seo] Failed to parse content.yaml (reviews disabled):', error)\n return undefined\n }\n}\n\n/**\n * Normalise a route path to the on-disk output file:\n * '/' -> '<outDir>/index.html'\n * '/services' -> '<outDir>/services/index.html'\n * '/blog/my-post' -> '<outDir>/blog/my-post/index.html'\n * '/services/' -> '<outDir>/services/index.html'\n */\nfunction routeToOutputFile(outDir: string, routePath: string): string {\n const trimmed = routePath.replace(/^\\/+/, '').replace(/\\/+$/, '')\n if (trimmed === '') return path.join(outDir, 'index.html')\n return path.join(outDir, ...trimmed.split('/'), 'index.html')\n}\n\n/** Extract the optional top-level `excluded:` glob list from pages.yaml. */\nfunction loadExcludedGlobs(projectRoot: string, pagesPath: string): string[] {\n const possiblePaths = [\n path.resolve(projectRoot, pagesPath),\n path.resolve(projectRoot, '..', pagesPath),\n path.resolve(process.cwd(), pagesPath),\n ]\n const found = possiblePaths.find((p) => fs.existsSync(p))\n if (!found) return []\n try {\n const raw = yaml.load(fs.readFileSync(found, 'utf8')) as { excluded?: unknown } | null\n const excluded = raw?.excluded\n if (!Array.isArray(excluded)) return []\n return excluded.filter((e): e is string => typeof e === 'string')\n } catch {\n return []\n }\n}\n\n/**\n * Derive a single site-wide lastmod from seo.yaml `lastUpdated` (preferred) or\n * pages.yaml `lastUpdated`. No fabricated per-page dates.\n */\nfunction deriveLastmod(\n seoConfig: SeoConfiguration | undefined,\n projectRoot: string,\n pagesPath: string\n): string | undefined {\n const fromSeo = seoConfig?.lastUpdated\n if (typeof fromSeo === 'string' && fromSeo.length > 0) return fromSeo\n\n const possiblePaths = [\n path.resolve(projectRoot, pagesPath),\n path.resolve(projectRoot, '..', pagesPath),\n path.resolve(process.cwd(), pagesPath),\n ]\n const found = possiblePaths.find((p) => fs.existsSync(p))\n if (!found) return undefined\n try {\n const raw = yaml.load(fs.readFileSync(found, 'utf8')) as { lastUpdated?: unknown } | null\n const fromPages = raw?.lastUpdated\n if (typeof fromPages === 'string' && fromPages.length > 0) return fromPages\n } catch {\n /* ignore */\n }\n return undefined\n}\n\n/**\n * Core site-file emitter, separated from Vite so it is unit-testable.\n *\n * Writes the site-wide static files into `outDir`, reusing the SAME routes +\n * seoConfig already loaded by the per-route HTML loop (no second manifest read):\n * - `sitemap.xml` (skipped in preview, or when no absolute base is derivable)\n * - `robots.txt` (always; preview = `Disallow: /`; don't-clobber unless force)\n * - `llms.txt` (skipped in preview, or when nothing indexable)\n *\n * Returns the list of relative filenames written. Pure aside from `fs` writes —\n * deterministic + idempotent. Never throws (the caller also wraps in try/catch).\n */\nexport function emitSiteFiles(params: {\n outDir: string\n projectRoot: string\n pagesPath: string\n routes: PageRouteEntry[]\n seoConfig: SeoConfiguration | undefined\n siteUrl?: string\n exclude?: string[]\n noindex?: string[]\n preview?: boolean\n robots?: DcsRobotsOptions\n llms?: boolean\n debug?: boolean\n}): string[] {\n const {\n outDir,\n projectRoot,\n pagesPath,\n routes,\n seoConfig,\n siteUrl,\n exclude = [],\n noindex = [],\n preview = false,\n robots = {},\n llms = true,\n debug = false,\n } = params\n\n const written: string[] = []\n\n const effectiveSiteUrl = siteUrl || seoConfig?.global?.siteUrl\n const excludedGlobs = loadExcludedGlobs(projectRoot, pagesPath)\n const lastmod = deriveLastmod(seoConfig, projectRoot, pagesPath)\n\n // ── sitemap.xml (not in preview) ──────────────────────────────────────────\n let wroteSitemap = false\n if (!preview) {\n const xml = buildSitemapXml({\n routes,\n siteUrl: effectiveSiteUrl,\n seoConfig,\n exclude,\n noindex,\n excludedGlobs,\n lastmod,\n })\n if (xml) {\n fs.writeFileSync(path.join(outDir, 'sitemap.xml'), xml, 'utf8')\n wroteSitemap = true\n written.push('sitemap.xml')\n if (debug) console.log('[dcs-seo] wrote sitemap.xml')\n } else if (debug) {\n console.log('[dcs-seo] no absolute <loc> derivable; sitemap.xml not written')\n }\n }\n\n // ── robots.txt (always, unless robots.enabled is false) ───────────────────\n if (robots.enabled ?? true) {\n const robotsPath = path.join(outDir, 'robots.txt')\n // Factory-as-single-source (validated override): a hand-authored\n // public/robots.txt Vite copied into dist is KEPT only when it meets the\n // factory floor (a real `User-agent: *` group + every AI-bot tier). A stub\n // (`Sitemap:`-only, like just-posh) or an SPA-shell HTML page fails the\n // floor and is overwritten so AI discovery is guaranteed on every site.\n // `force` always overwrites; an absent file is always written.\n const existing =\n fs.existsSync(robotsPath) && !robots.force ? fs.readFileSync(robotsPath, 'utf8') : null\n const keepHandAuthored = existing !== null && isHandAuthoredRobotsAcceptable(existing)\n if (keepHandAuthored) {\n if (debug)\n console.log('[dcs-seo] dist/robots.txt is hand-authored and meets the floor; leaving it')\n } else {\n const txt = buildRobotsTxt({\n siteUrl: effectiveSiteUrl,\n preview,\n robots,\n hasSitemap: wroteSitemap,\n })\n fs.writeFileSync(robotsPath, txt, 'utf8')\n written.push('robots.txt')\n if (debug) {\n console.log(\n existing !== null\n ? '[dcs-seo] dist/robots.txt failed the factory floor; overwrote with emitted robots'\n : '[dcs-seo] wrote robots.txt'\n )\n }\n }\n }\n\n // ── llms.txt (not in preview) ─────────────────────────────────────────────\n if (llms && !preview) {\n const txt = buildLlmsTxt({\n routes,\n siteUrl: effectiveSiteUrl,\n seoConfig,\n exclude,\n noindex,\n excludedGlobs,\n })\n if (txt) {\n fs.writeFileSync(path.join(outDir, 'llms.txt'), txt, 'utf8')\n written.push('llms.txt')\n if (debug) console.log('[dcs-seo] wrote llms.txt')\n } else if (debug) {\n console.log('[dcs-seo] nothing indexable; llms.txt not written')\n }\n }\n\n return written\n}\n\n/**\n * Pick a structured FAQ array (`[{ q, a }]`) for a page from content.yaml, if\n * one exists under a `faq` key (page-scoped, then global). Returns `undefined`\n * when there is no structured Q&A — a `<FaqPage />` component is NOT a source,\n * so its pages correctly yield nothing (honesty).\n */\nfunction pickPageFaq(\n content: ContentConfig | undefined,\n pageSlug: string\n): FaqSource[] | undefined {\n if (!content) return undefined\n const fromBlock = (block: Record<string, unknown> | undefined): FaqSource[] | undefined => {\n if (!block) return undefined\n const v = block['faq']\n return Array.isArray(v) ? (v as FaqSource[]) : undefined\n }\n return fromBlock(content.pages?.[pageSlug]) ?? fromBlock(content.global)\n}\n\n/**\n * Core emitter, separated from Vite so it is unit-testable.\n *\n * For each route: build the head tags from the shared resolver, splice them\n * into the shell HTML, and write `dist/<path>/index.html`. Returns the number\n * of files written. Pure aside from `fs` writes — deterministic + idempotent.\n */\nexport function emitStaticSeoHtml(params: {\n outDir: string\n shellHtml: string\n routes: PageRouteEntry[]\n seoConfig: SeoConfiguration | undefined\n /**\n * Parsed `.dcs/content.yaml` — threads REAL review items (honesty-gated) into\n * the per-route LocalBusiness node. Optional; omit ⇒ no Review/aggregateRating.\n */\n contentConfig?: ContentConfig\n exclude?: string[]\n noindex?: string[]\n /** `pages.yaml` top-level `excluded:` globs — routes matching are NOT emitted. */\n excludedGlobs?: string[]\n debug?: boolean\n}): number {\n const {\n outDir,\n shellHtml,\n routes,\n seoConfig,\n contentConfig,\n exclude = [],\n noindex = [],\n excludedGlobs = [],\n debug = false,\n } = params\n\n const excludeSet = new Set(exclude)\n const noindexSet = new Set(noindex)\n\n // Route → human title map (for breadcrumb hop labels), from the manifest.\n const siteUrl = seoConfig?.global?.siteUrl ?? ''\n const routeTitles: Record<string, string> = { '/': 'Home' }\n for (const r of routes) {\n if (r.title && r.path) routeTitles[r.path.replace(/\\/+$/, '') || '/'] = r.title\n }\n\n let written = 0\n for (const route of routes) {\n if (excludeSet.has(route.path) || (route.slug && excludeSet.has(route.slug))) {\n if (debug) console.log(`[dcs-seo] skip (excluded): ${route.path}`)\n continue\n }\n\n // Honor pages.yaml top-level `excluded:` globs (e.g. `/dev-*`, `/_*`): an\n // excluded route must NOT get a per-route index.html, or it becomes a\n // crawlable/indexable page despite being intentionally hidden — a privacy\n // and crawl-budget leak. Same glob semantics as the sitemap path.\n if (matchesExcludedGlob(route.path, excludedGlobs)) {\n if (debug) console.log(`[dcs-seo] skip (excluded glob): ${route.path}`)\n continue\n }\n\n const forceNoindex =\n noindexSet.has(route.path) || (route.slug && noindexSet.has(route.slug))\n\n // Breadcrumb trail from route depth (home ⇒ none); titles from the manifest.\n const breadcrumbTrail = siteUrl\n ? breadcrumbTrailFromRoute(route.path, siteUrl, routeTitles)\n : undefined\n\n // REAL reviews for this page from content.yaml (honesty-gated downstream).\n const reviews: ReviewSource[] | undefined = contentConfig\n ? findReviewItemsForPage(contentConfig, route.slug)\n : undefined\n\n // BlogPosting for a blog post route — only when seo.yaml has NOT already\n // hand-authored one (buildHeadTags skips ours if it has). A blog post is a\n // route nested under `/blog/` (depth ≥ 2) with a manifest title.\n const isBlogPost = /^\\/blog\\/.+/.test(route.path) && !!route.title\n const blogMeta: BlogMeta | undefined = isBlogPost\n ? { headline: route.title, url: breadcrumbTrail?.[breadcrumbTrail.length - 1]?.item }\n : undefined\n\n // FAQ from a structured `.dcs/faq.yaml`-style block on the content page, if\n // present (honesty-gated). Component-only FAQ pages carry no such data.\n const faq: FaqSource[] | undefined = pickPageFaq(contentConfig, route.slug)\n\n const tags = buildHeadTags(route.slug, route.path, seoConfig, {\n includeKeywords: true,\n fallbackTitle: route.title,\n robots: forceNoindex ? 'noindex, nofollow' : undefined,\n emitGraph: true,\n breadcrumbTrail,\n reviews,\n blogMeta,\n faq,\n })\n\n const html = spliceHeadHtml(shellHtml, tags)\n const outFile = routeToOutputFile(outDir, route.path)\n\n fs.mkdirSync(path.dirname(outFile), { recursive: true })\n fs.writeFileSync(outFile, html, 'utf8')\n written++\n\n if (debug) {\n console.log(\n `[dcs-seo] wrote ${path.relative(outDir, outFile)} (title=\"${tags.title}\"${\n forceNoindex ? ', noindex' : ''\n })`\n )\n }\n }\n\n return written\n}\n\n/**\n * Vite plugin that injects .dcs/seo.yaml at build time and, optionally, emits\n * per-route static `<head>` HTML for SPA SEO.\n *\n * @param options - Plugin configuration\n * @returns Vite plugin\n */\nexport function dcsSeoPlugin(options: DcsSeoPluginOptions = {}): Plugin {\n const {\n seoPath = '.dcs/seo.yaml',\n debug = false,\n emitStaticHtml = false,\n pagesPath = '.dcs/pages.yaml',\n contentPath = '.dcs/content.yaml',\n exclude = [],\n noindex = [],\n // Site files default ON whenever per-route HTML emission is on, so the\n // sites already using emitStaticHtml gain sitemap/robots/llms with no edit.\n emitSiteFiles: emitSiteFilesOpt = emitStaticHtml,\n siteUrl,\n robots = {},\n preview = false,\n llms = true,\n } = options\n\n let resolvedConfig: ResolvedConfig\n\n return {\n name: 'dcs-seo',\n\n configResolved(config) {\n resolvedConfig = config\n },\n\n config(config) {\n const projectRoot = config.root || process.cwd()\n\n const loaded = loadSeoConfig(projectRoot, seoPath, debug)\n if (!loaded) {\n return {\n define: {\n __DCS_SEO__: 'undefined',\n },\n }\n }\n\n if (debug) {\n console.log(`[dcs-seo] Loaded ${loaded.foundPath}`)\n console.log(`[dcs-seo] Version: ${loaded.config.version}`)\n console.log(`[dcs-seo] Site Name: ${loaded.config.global?.siteName || '(not set)'}`)\n console.log(\n `[dcs-seo] Pages: ${Object.keys(loaded.config.pages ?? {}).join(', ') || '(none)'}`\n )\n }\n\n return {\n define: {\n __DCS_SEO__: JSON.stringify(loaded.config),\n },\n }\n },\n\n /**\n * Build-time static `<head>` emitter (opt-in via `emitStaticHtml`).\n *\n * Runs after the bundle is written so the built `index.html` shell exists\n * on disk. For an SPA, Vite emits a single `index.html`; we fan it out to\n * per-route files with route-specific `<head>` content.\n *\n * Fully defensive: any missing/unparseable input logs a warning and\n * no-ops. Never throws (so it can never break a production build).\n */\n writeBundle() {\n if (!emitStaticHtml) {\n // The whole emit path is gated on emitStaticHtml. If the operator\n // explicitly asked for site files (`emitSiteFiles: true`) while\n // emitStaticHtml is off, that request is silently inert — warn so it's\n // not mistaken for \"robots/sitemap were emitted\".\n if (options.emitSiteFiles === true) {\n console.warn(\n '[dcs-seo] emitSiteFiles:true is ignored because emitStaticHtml is false; ' +\n 'set emitStaticHtml:true to emit sitemap.xml/robots.txt/llms.txt'\n )\n }\n return\n }\n\n try {\n const projectRoot = resolvedConfig?.root || process.cwd()\n const outDir = resolveOutDir(resolvedConfig)\n\n if (!fs.existsSync(outDir)) {\n console.warn(`[dcs-seo] emitStaticHtml: outDir not found (${outDir}); skipping`)\n return\n }\n\n const shellPath = path.join(outDir, 'index.html')\n if (!fs.existsSync(shellPath)) {\n console.warn(\n `[dcs-seo] emitStaticHtml: no index.html in ${outDir}; nothing to emit`\n )\n return\n }\n\n const routes = loadPagesManifest(projectRoot, pagesPath, debug)\n if (!routes) {\n console.warn(\n `[dcs-seo] emitStaticHtml: ${pagesPath} missing or empty; skipping per-route emission`\n )\n return\n }\n\n const loaded = loadSeoConfig(projectRoot, seoPath, debug)\n if (!loaded) {\n // seo.yaml is optional for emission — routes still get baked with\n // global/runtime defaults (which here means just the shell title and\n // a derived canonical-less head). Warn so the operator knows.\n console.warn(\n `[dcs-seo] emitStaticHtml: ${seoPath} missing or unparseable; emitting with defaults only`\n )\n }\n\n const shellHtml = fs.readFileSync(shellPath, 'utf8')\n\n // pages.yaml top-level `excluded:` globs gate BOTH the per-route HTML\n // emission below and the sitemap/llms set inside emitSiteFiles, so an\n // excluded route is never written as a crawlable index.html.\n const excludedGlobs = loadExcludedGlobs(projectRoot, pagesPath)\n // Optional: load content.yaml so REAL reviews can feed the honest\n // Review/aggregateRating on the per-route LocalBusiness node. Absent or\n // unparseable ⇒ undefined ⇒ no reviews emitted (no synthesis).\n const contentConfig = loadContentConfig(projectRoot, contentPath, debug)\n\n const written = emitStaticSeoHtml({\n outDir,\n shellHtml,\n routes,\n seoConfig: loaded?.config,\n contentConfig,\n exclude,\n noindex,\n excludedGlobs,\n debug,\n })\n\n if (debug) {\n console.log(`[dcs-seo] emitStaticHtml: wrote ${written} per-route HTML file(s)`)\n }\n\n // ── site-wide static files (sitemap.xml, robots.txt, llms.txt) ──────\n // Emitted AFTER the per-route HTML loop so canonicals/routes are\n // resolved and the shell exists. Reuses the already-loaded routes +\n // seoConfig (no second manifest read). Same outDir/existsSync guard +\n // the outer try/catch — so it can never break a production build.\n if (emitSiteFilesOpt) {\n const siteFiles = emitSiteFiles({\n outDir,\n projectRoot,\n pagesPath,\n routes,\n seoConfig: loaded?.config,\n siteUrl,\n exclude,\n noindex,\n preview,\n robots,\n llms,\n debug,\n })\n if (debug) {\n console.log(\n `[dcs-seo] emitSiteFiles: wrote ${siteFiles.length} site file(s): ${\n siteFiles.join(', ') || '(none)'\n }`\n )\n }\n }\n } catch (error) {\n // Never break the build on SEO emission failure.\n console.warn('[dcs-seo] emitStaticHtml failed; build output left unchanged:', error)\n }\n },\n\n // Watch for changes in development\n configureServer(server) {\n const projectRoot = resolvedConfig?.root || process.cwd()\n\n const watchPaths = [\n path.resolve(projectRoot, seoPath),\n path.resolve(projectRoot, '..', seoPath),\n ]\n\n watchPaths.forEach((watchPath) => {\n if (fs.existsSync(watchPath)) {\n server.watcher.add(watchPath)\n\n server.watcher.on('change', (changedPath) => {\n if (changedPath === watchPath) {\n if (debug) {\n console.log('[dcs-seo] seo.yaml changed, triggering reload')\n }\n server.restart()\n }\n })\n }\n })\n },\n }\n}\n","/**\n * DCS Editor Plugin for Vite\n *\n * Injects the editor bridge script into customer sites when running\n * in portal preview mode (inside the visual editor iframe).\n *\n * The bridge enables:\n * - Inline text editing via contenteditable\n * - Section hover highlights and AI ✨ buttons\n * - postMessage communication with the portal\n *\n * This plugin should only be active in development/preview mode.\n * It's safe to include in production builds — it does nothing unless\n * the page detects it's inside an iframe.\n *\n * @example\n * ```typescript\n * // vite.config.ts\n * import { dcsEditorPlugin } from '@duffcloudservices/cms/plugins'\n *\n * export default defineConfig({\n * plugins: [\n * dcsEditorPlugin()\n * ]\n * })\n * ```\n */\n\nimport type { Plugin } from 'vite'\n\nexport interface DcsEditorPluginOptions {\n /** Enable debug logging */\n debug?: boolean\n}\n\n/**\n * Vite plugin that injects the editor bridge script for portal preview integration.\n *\n * The bridge auto-initializes only when the page detects it's running inside an iframe,\n * so it's safe to include in all builds — it's a no-op in standalone browsing.\n *\n * Uses a virtual module (`/__dcs-editor-bridge.js`) served through Vite's dev server\n * so that bare module specifiers (like `@duffcloudservices/cms/editor`) are properly\n * resolved through Vite's module graph rather than hitting the browser's native ESM\n * resolver, which can't handle bare specifiers.\n */\nexport function dcsEditorPlugin(options: DcsEditorPluginOptions = {}): Plugin {\n const { debug = false } = options\n const VIRTUAL_PATH = '/__dcs-editor-bridge.js'\n const RIBBON_VIRTUAL_PATH = '/__dcs-preview-ribbon.js'\n\n // Captured during configResolved — used to gate HTML injection.\n let isDev = false\n let basePath = '/'\n\n return {\n name: 'dcs-editor-bridge',\n\n configResolved(config) {\n isDev = config.command === 'serve'\n basePath = config.base ?? '/'\n },\n\n resolveId(id) {\n if (id === VIRTUAL_PATH || id === RIBBON_VIRTUAL_PATH) {\n return id\n }\n },\n\n load(id) {\n if (id === VIRTUAL_PATH) {\n return `\nimport { initEditorBridge } from '@duffcloudservices/cms/editor'\n// The bridge only activates inside an iframe (portal preview)\nif (window.parent !== window) {\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', () => setTimeout(initEditorBridge, 200))\n } else {\n setTimeout(initEditorBridge, 200)\n }\n}\n`\n }\n\n if (id === RIBBON_VIRTUAL_PATH) {\n return `\nimport { createApp } from 'vue'\nimport PreviewRibbon from '@duffcloudservices/cms/components'\n\nfunction mountRibbon() {\n // Create a detached mount point\n const el = document.createElement('div')\n el.id = 'dcs-preview-ribbon-root'\n document.body.appendChild(el)\n\n const app = createApp(PreviewRibbon)\n app.mount(el)\n}\n\nif (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', mountRibbon)\n} else {\n mountRibbon()\n}\n`\n }\n },\n\n /**\n * Only inject the editor bridge and ribbon scripts when:\n * 1. Running in dev mode (Vite dev server), AND\n * 2. The app is served at the root path (base === '/')\n *\n * These are virtual modules resolved via absolute paths (e.g.\n * `/__dcs-editor-bridge.js`). When base !== '/', the app is served at a\n * sub-path (e.g. /handyman-bryan/) and the absolute virtual paths are NOT\n * routed to the Vite dev server by the reverse proxy — they hit the main\n * DCS server instead and get redirected to portal.duffcloudservices.com\n * (no CORS headers), causing browser console errors.\n *\n * In production builds, App.vue imports and mounts PreviewRibbon\n * directly, so virtual script injection is always redundant anyway.\n */\n transformIndexHtml: {\n order: 'pre',\n handler(html) {\n if (!isDev || basePath !== '/') return html\n\n if (debug) {\n console.log('[dcs-editor] Injecting editor bridge + preview ribbon script tags')\n }\n\n // Inject both the editor bridge and preview ribbon scripts\n const editorTag = `<script type=\"module\" src=\"${VIRTUAL_PATH}\"></script>`\n const ribbonTag = `<script type=\"module\" src=\"${RIBBON_VIRTUAL_PATH}\"></script>`\n\n // Insert before closing </body> tag\n return html.replace('</body>', `${editorTag}\\n${ribbonTag}\\n</body>`)\n },\n },\n }\n}\n","/**\n * DCS Preview Plugin for Vue\n *\n * Registers a supplied ribbon component as a global `DcsPreviewRibbon`\n * component. The ribbon handles its own visibility — it only renders on\n * `preview.duffcloudservices.com` and hides everywhere else (localhost,\n * production domains, and inside the visual page editor iframe).\n *\n * Why does the caller pass the component in? Because this file is compiled\n * by tsup (esbuild) which has no `.vue` SFC loader. Keeping the raw `.vue`\n * import out of the compiled plugins bundle avoids the build error while\n * still letting consumer code (which *does* run through Vite) resolve the\n * SFC at dev/build time.\n *\n * @example VitePress theme/index.ts\n * ```typescript\n * import { dcsPreviewPlugin } from '@duffcloudservices/cms/plugins'\n * import PreviewRibbon from '@duffcloudservices/cms/components'\n *\n * export default {\n * Layout,\n * enhanceApp({ app }) {\n * app.use(dcsPreviewPlugin(PreviewRibbon))\n * }\n * }\n * ```\n */\n\nimport { defineComponent, h, type App, type Component, type Plugin } from 'vue'\n\nexport interface DcsPreviewPluginOptions {\n /**\n * Override the version string displayed on the ribbon.\n * If omitted, the ribbon auto-detects from VITE_SITE_VERSION or the API.\n */\n version?: string | null\n}\n\n/**\n * Creates and returns the DCS Preview plugin.\n *\n * When installed, it registers the supplied ribbon component as a global\n * `DcsPreviewRibbon` component. Add `<DcsPreviewRibbon />` to your root\n * Layout, or use the `dcsEditorPlugin` Vite plugin which injects it via\n * `transformIndexHtml`.\n *\n * @param ribbonComponent - The PreviewRibbon SFC (imported by the consumer)\n * @param options - Optional configuration\n */\nexport function dcsPreviewPlugin(\n ribbonComponent: Component,\n options: DcsPreviewPluginOptions = {},\n): Plugin {\n const Wrapper = defineComponent({\n name: 'DcsPreviewRibbon',\n setup() {\n return () => h(ribbonComponent, { version: options.version ?? null })\n },\n })\n\n return {\n install(app: App) {\n app.component('DcsPreviewRibbon', Wrapper)\n\n if (options.version !== undefined) {\n app.provide('__dcs_preview_version__', options.version)\n }\n },\n }\n}\n","/**\n * DCS CDN Image Plugin for Vite\n *\n * Rewrites local static image references (e.g. `/images/staff/photo.jpg`)\n * to CDN URLs at build time using the `.dcs/cdn-image-map.json` mapping file\n * generated by the `image-migrate adopt` CLI command.\n *\n * For raster images with WebP variants, `<img>` elements are transformed into\n * responsive `<picture>` elements with `srcset` for optimised delivery.\n * SVGs receive a simple URL swap with no variant handling.\n *\n * **In development mode this plugin is a no-op** — local `/images/` paths\n * continue to work via Vite's static asset serving so hot-reload is unaffected.\n *\n * The plugin handles two in-pipeline replacement vectors:\n *\n * 1. **Module transform** (`transform` hook) — rewrites `<img>` tags and\n * string literals in Vue SFCs, TS, JS, CSS, MD, and HTML modules.\n * 2. **Chunk rendering** (`renderChunk` hook) — rewrites image paths in\n * final rendered JS/CSS chunks AFTER Vite's `define` substitution.\n * This catches data injected by `dcsContentPlugin` via `__DCS_CONTENT__`\n * (from `.dcs/content.yaml`) which bypasses the `transform` hook.\n *\n * A third vector — **post-build file processing** — is handled by the\n * companion `dcsCdnBuildEnd` hook, which must be registered separately in\n * VitePress config. VitePress generates HTML *after* both Vite builds\n * complete, so Vite plugin hooks (`closeBundle`, `transformIndexHtml`)\n * cannot catch SSR-rendered `<head>` tags or static `public/` files like\n * `service-worker.js`.\n *\n * @example\n * ```ts\n * // .vitepress/config.ts\n * import { dcsCdnImagePlugin, dcsCdnBuildEnd } from '@duffcloudservices/cms/plugins'\n *\n * export default defineConfig({\n * vite: {\n * plugins: [\n * dcsCdnImagePlugin()\n * ]\n * },\n * buildEnd: dcsCdnBuildEnd()\n * })\n * ```\n */\n\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport type { Plugin } from 'vite'\n\n// ────────────────────────────────────────────────────────────────────────────\n// Types\n// ────────────────────────────────────────────────────────────────────────────\n\nexport interface CdnImageMapVariant {\n suffix: string\n blobPath: string\n cdnUrl: string\n width: number\n height: number\n size: number\n}\n\nexport interface CdnImageMapEntry {\n localPath: string\n blobPath: string\n cdnUrl: string\n fileName: string\n contentType: string\n originalSize: number\n width?: number\n height?: number\n hash: string\n variants?: CdnImageMapVariant[]\n}\n\nexport interface CdnImageMap {\n generated: string\n site: string\n cdnBase: string\n images: CdnImageMapEntry[]\n}\n\nexport interface DcsCdnImagePluginOptions {\n /** Path to cdn-image-map.json relative to project root (default: '.dcs/cdn-image-map.json') */\n mapPath?: string\n\n /**\n * Patterns to match for replacement. Each must be a **leading-slash path prefix**\n * that appears in source code (e.g. `/images/`). The `localPath` field in the\n * mapping file is compared *without* a leading slash.\n *\n * Default: `['/images/']`\n */\n pathPrefixes?: string[]\n\n /**\n * Default `sizes` attribute for responsive `<picture>` elements.\n * Override per-context via the `data-sizes` attribute on the original `<img>`.\n *\n * Default: `'(max-width: 1024px) 100vw, 1024px'`\n */\n defaultSizes?: string\n\n /** Enable debug logging */\n debug?: boolean\n}\n\n// ────────────────────────────────────────────────────────────────────────────\n// Helpers\n// ────────────────────────────────────────────────────────────────────────────\n\nfunction escapeHtml(str: string): string {\n return str\n .replace(/&/g, '&amp;')\n .replace(/\"/g, '&quot;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n}\n\n/**\n * Build a responsive `<picture>` element for a raster image that has\n * WebP variants.\n */\nfunction buildPictureElement(\n entry: CdnImageMapEntry,\n alt: string,\n extraAttrs: string,\n sizes: string\n): string {\n const variants = entry.variants ?? []\n\n // Collect only the display-relevant variants (not thumb, not og)\n const displayVariants = variants.filter(\n (v) => v.suffix === '-sm' || v.suffix === '-md' || v.suffix === '-lg'\n )\n\n if (displayVariants.length === 0) {\n // No display variants — fall back to original CDN URL as plain <img>\n return `<img src=\"${escapeHtml(entry.cdnUrl)}\" alt=\"${escapeHtml(alt)}\"${extraAttrs} loading=\"lazy\" decoding=\"async\" />`\n }\n\n const srcset = displayVariants\n .map((v) => `${v.cdnUrl} ${v.width}w`)\n .join(', ')\n\n // Pick the -md variant as the default src, or fall through to original\n const mdVariant = variants.find((v) => v.suffix === '-md')\n const fallbackSrc = mdVariant ? mdVariant.cdnUrl : entry.cdnUrl\n\n return [\n '<picture>',\n ` <source srcset=\"${srcset}\" type=\"image/webp\" sizes=\"${escapeHtml(sizes)}\" />`,\n ` <img src=\"${escapeHtml(fallbackSrc)}\" alt=\"${escapeHtml(alt)}\"${extraAttrs} loading=\"lazy\" decoding=\"async\" />`,\n '</picture>',\n ].join('\\n')\n}\n\n// ────────────────────────────────────────────────────────────────────────────\n// Shared helpers\n// ────────────────────────────────────────────────────────────────────────────\n\n/**\n * Try to find and load the CDN image map from common locations.\n * VitePress nests docs under a subfolder, so we check parent dirs too.\n */\nfunction loadCdnImageMap(\n projectRoot: string,\n relativeMapPath: string,\n debug: boolean\n): Map<string, CdnImageMapEntry> | null {\n const possiblePaths = [\n path.resolve(projectRoot, relativeMapPath),\n path.resolve(projectRoot, '..', relativeMapPath),\n path.resolve(process.cwd(), relativeMapPath),\n ]\n\n for (const testPath of possiblePaths) {\n if (fs.existsSync(testPath)) {\n try {\n const raw = fs.readFileSync(testPath, 'utf8')\n const data: CdnImageMap = JSON.parse(raw)\n\n const map = new Map<string, CdnImageMapEntry>()\n for (const entry of data.images) {\n // Store both with and without leading slash for flexible matching\n map.set(entry.localPath, entry)\n if (!entry.localPath.startsWith('/')) {\n map.set('/' + entry.localPath, entry)\n }\n }\n\n if (debug) {\n console.log(`[dcs-cdn-image] Loaded ${data.images.length} entries from ${testPath}`)\n }\n return map\n } catch (error) {\n console.warn(`[dcs-cdn-image] Failed to parse ${testPath}:`, error)\n }\n }\n }\n\n if (debug) {\n console.log('[dcs-cdn-image] No cdn-image-map.json found at:')\n possiblePaths.forEach((p) => console.log(` - ${p}`))\n }\n return null\n}\n\n// ────────────────────────────────────────────────────────────────────────────\n// Vite Plugin\n// ────────────────────────────────────────────────────────────────────────────\n\n/**\n * Vite plugin that rewrites static `/images/` paths to CDN URLs at build time.\n */\nexport function dcsCdnImagePlugin(options: DcsCdnImagePluginOptions = {}): Plugin {\n const {\n mapPath = '.dcs/cdn-image-map.json',\n pathPrefixes = ['/images/'],\n defaultSizes = '(max-width: 1024px) 100vw, 1024px',\n debug = false,\n } = options\n\n // Lookup map built from the JSON file: key = localPath (no leading slash)\n let imageMap: Map<string, CdnImageMapEntry> | null = null\n let isProduction = false\n\n /**\n * Check whether a source code string contains any of the path prefixes\n * we care about. Quick bail-out for files that don't reference images.\n */\n function hasImageReferences(code: string): boolean {\n return pathPrefixes.some((prefix) => code.includes(prefix))\n }\n\n /**\n * Replace image path references in any string value with CDN URLs.\n * Used for code transforms and renderChunk post-processing.\n */\n function replaceImagePaths(str: string): string {\n if (!imageMap || imageMap.size === 0) return str\n let result = str\n for (const prefix of pathPrefixes) {\n // Global replace: matches prefix followed by a relative path bounded\n // by quotes, parens, or whitespace. Allows spaces in filenames.\n const regex = new RegExp(\n `([\"'\\`(])${escapeRegex(prefix)}([^\"'\\`()]+)`,\n 'g'\n )\n result = result.replace(regex, (match, quote, relPath) => {\n const localPath = prefix.replace(/^\\//, '') + relPath\n const entry = imageMap!.get(localPath) || imageMap!.get('/' + localPath)\n if (!entry) return match\n return `${quote}${entry.cdnUrl}`\n })\n }\n return result\n }\n\n /**\n * Replace standalone URL references in JS/TS string literals and Vue template\n * attributes. This handles patterns like:\n * src=\"/images/foo.jpg\"\n * { src: '/images/foo.jpg' }\n * url(/images/foo.svg)\n *\n * For `<img>` tags with raster images that have variants, the entire tag is\n * replaced with a `<picture>` element.\n */\n function transformCode(code: string): string {\n if (!imageMap || imageMap.size === 0) return code\n\n // ── Pass 1: Replace <img> tags that reference mapped raster images ──────\n // Matches: <img ... src=\"/images/foo.jpg\" ... /> or <img ... src=\"/images/foo.jpg\" ... >\n const imgTagRegex = /<img\\b([^>]*?)src=[\"'](\\/(images\\/[^\"']+))[\"']([^>]*?)\\/?>/gi\n code = code.replace(imgTagRegex, (_match, beforeSrc, _srcWithSlash, localPath, afterSrc) => {\n const entry = imageMap!.get(localPath) || imageMap!.get('/' + localPath)\n if (!entry) return _match\n\n // Extract alt from the existing attributes\n const altMatch = (beforeSrc + afterSrc).match(/alt=[\"']([^\"']*)[\"']/)\n const alt = altMatch ? altMatch[1] : ''\n\n // Collect other attributes (not src, alt, loading, decoding — we set those)\n const otherAttrs = (beforeSrc + afterSrc)\n .replace(/\\balt=[\"'][^\"']*[\"']/gi, '')\n .replace(/\\bloading=[\"'][^\"']*[\"']/gi, '')\n .replace(/\\bdecoding=[\"'][^\"']*[\"']/gi, '')\n .trim()\n\n const extraAttrs = otherAttrs ? ' ' + otherAttrs : ''\n\n // Extract custom sizes if specified\n const sizesMatch = (beforeSrc + afterSrc).match(/data-sizes=[\"']([^\"']*)[\"']/)\n const sizes = sizesMatch ? sizesMatch[1] : defaultSizes\n\n // SVGs and images without variants → simple URL swap <img>\n if (!entry.variants || entry.variants.length === 0) {\n return `<img src=\"${escapeHtml(entry.cdnUrl)}\" alt=\"${escapeHtml(alt)}\"${extraAttrs} loading=\"lazy\" decoding=\"async\" />`\n }\n\n // Raster with variants → <picture>\n return buildPictureElement(entry, alt, extraAttrs, sizes)\n })\n\n // ── Pass 2: Replace remaining string literal / CSS url() references ─────\n code = replaceImagePaths(code)\n\n return code\n }\n\n return {\n name: 'dcs-cdn-image',\n enforce: 'pre',\n\n configResolved(config) {\n isProduction = config.command === 'build'\n if (!isProduction) {\n if (debug) {\n console.log('[dcs-cdn-image] Dev mode — plugin disabled (local images served by Vite)')\n }\n return\n }\n imageMap = loadCdnImageMap(config.root, mapPath, debug)\n },\n\n transform(code, id) {\n // Only run in production builds\n if (!isProduction || !imageMap) return\n\n // Only process relevant file types\n if (!/\\.(vue|ts|tsx|js|jsx|css|scss|md|html)(\\?.*)?$/.test(id)) return\n\n // Quick bail — skip files with no image path references\n if (!hasImageReferences(code)) return\n\n const transformed = transformCode(code)\n if (transformed !== code) {\n return { code: transformed, map: null }\n }\n },\n\n /**\n * Replace image paths in final rendered JS/CSS chunks.\n *\n * This fires AFTER Vite's `define` substitution, catching paths that were\n * injected via `define` values (e.g. `__DCS_CONTENT__` set by\n * `dcsContentPlugin` from `.dcs/content.yaml`). Those paths bypass the\n * `transform` hook because `define` replacement happens at bundle time.\n */\n renderChunk(code, _chunk) {\n if (!isProduction || !imageMap) return null\n if (!hasImageReferences(code)) return null\n\n const replaced = replaceImagePaths(code)\n if (replaced !== code) {\n if (debug) {\n console.log(`[dcs-cdn-image] renderChunk: rewrote image paths in ${_chunk.fileName}`)\n }\n return { code: replaced, map: null }\n }\n return null\n },\n\n /**\n * Transform HTML output to catch references injected outside the module\n * pipeline — e.g. VitePress `head` config tags (favicons, OG images).\n *\n * Note: In VitePress, this hook fires for the `index.html` template but\n * NOT for SSR-rendered per-page HTML. Use `dcsCdnBuildEnd` for full\n * coverage of generated HTML files.\n */\n transformIndexHtml(html) {\n if (!isProduction || !imageMap) return html\n if (!hasImageReferences(html)) return html\n\n // Replace href/src/content attributes that reference mapped images\n for (const prefix of pathPrefixes) {\n const attrRegex = new RegExp(\n `((?:href|src|content)=[\"'])${escapeRegex(prefix)}([^\"']+)([\"'])`,\n 'gi'\n )\n html = html.replace(attrRegex, (match, pre, relPath, post) => {\n const localPath = prefix.replace(/^\\//, '') + relPath\n const entry = imageMap!.get(localPath) || imageMap!.get('/' + localPath)\n if (!entry) return match\n return `${pre}${entry.cdnUrl}${post}`\n })\n }\n\n return html\n },\n }\n}\n\n/**\n * Escape a string for use in a RegExp.\n */\nfunction escapeRegex(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\n// ────────────────────────────────────────────────────────────────────────────\n// VitePress buildEnd hook\n// ────────────────────────────────────────────────────────────────────────────\n\nexport interface DcsCdnBuildEndOptions {\n /** Path to cdn-image-map.json relative to project root (default: '.dcs/cdn-image-map.json') */\n mapPath?: string\n\n /**\n * Patterns to match for replacement.\n * Default: `['/images/']`\n */\n pathPrefixes?: string[]\n\n /** Enable debug logging */\n debug?: boolean\n\n /**\n * File extensions to process in the output directory.\n * Default: `['.html', '.js']`\n */\n extensions?: string[]\n}\n\n/**\n * VitePress `buildEnd` hook factory that post-processes generated HTML and\n * static files in the output directory to replace remaining `/images/` paths\n * with CDN URLs.\n *\n * VitePress generates HTML **after** both Vite builds complete, so Vite\n * plugin hooks (`closeBundle`, `transformIndexHtml`) cannot catch\n * SSR-rendered `<head>` tags (favicons, OG images). This hook runs after all\n * HTML files are written to disk.\n *\n * Also rewrites static files (e.g. `service-worker.js`) copied from\n * `public/` that are not part of Vite's module pipeline.\n *\n * @example\n * ```ts\n * // .vitepress/config.ts\n * import { dcsCdnBuildEnd } from '@duffcloudservices/cms/plugins'\n *\n * export default defineConfig({\n * buildEnd: dcsCdnBuildEnd({ debug: true })\n * })\n * ```\n */\nexport function dcsCdnBuildEnd(options: DcsCdnBuildEndOptions = {}) {\n const {\n mapPath = '.dcs/cdn-image-map.json',\n pathPrefixes = ['/images/'],\n debug = false,\n extensions = ['.html', '.js'],\n } = options\n\n return async (siteConfig: { root: string; outDir: string }) => {\n const imageMap = loadCdnImageMap(siteConfig.root, mapPath, debug)\n if (!imageMap) {\n if (debug) {\n console.log('[dcs-cdn-image] buildEnd: no image map found')\n }\n return\n }\n\n const outDir = siteConfig.outDir\n if (!fs.existsSync(outDir)) return\n\n let filesProcessed = 0\n let refsReplaced = 0\n\n function walkDir(dir: string) {\n const entries = fs.readdirSync(dir, { withFileTypes: true })\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name)\n if (entry.isDirectory()) {\n walkDir(fullPath)\n } else if (extensions.some((ext) => entry.name.endsWith(ext))) {\n processFile(fullPath)\n }\n }\n }\n\n function processFile(filePath: string) {\n let content = fs.readFileSync(filePath, 'utf8')\n if (!pathPrefixes.some((p) => content.includes(p))) return\n\n let changed = false\n\n if (filePath.endsWith('.html')) {\n // HTML: replace href/src/content attribute values\n for (const prefix of pathPrefixes) {\n const attrRegex = new RegExp(\n `((?:href|src|content)=[\"'])${escapeRegex(prefix)}([^\"']+)([\"'])`,\n 'gi'\n )\n content = content.replace(attrRegex, (match, pre, relPath, post) => {\n const localPath = prefix.replace(/^\\//, '') + relPath\n const mapEntry = imageMap!.get(localPath) || imageMap!.get('/' + localPath)\n if (!mapEntry) return match\n changed = true\n refsReplaced++\n return `${pre}${mapEntry.cdnUrl}${post}`\n })\n }\n } else {\n // JS/other: replace quoted string paths\n for (const prefix of pathPrefixes) {\n const regex = new RegExp(\n `([\"'\\`(])${escapeRegex(prefix)}([^\"'\\`()]+)`,\n 'g'\n )\n content = content.replace(regex, (match, quote, relPath) => {\n const localPath = prefix.replace(/^\\//, '') + relPath\n const entry = imageMap!.get(localPath) || imageMap!.get('/' + localPath)\n if (!entry) return match\n changed = true\n refsReplaced++\n return `${quote}${entry.cdnUrl}`\n })\n }\n }\n\n if (changed) {\n fs.writeFileSync(filePath, content, 'utf8')\n filesProcessed++\n }\n }\n\n walkDir(outDir)\n\n if (debug) {\n console.log(\n `[dcs-cdn-image] buildEnd: post-processed ${filesProcessed} files, replaced ${refsReplaced} references`\n )\n }\n }\n}","/**\n * markdown-it plugin that transforms standard `![alt](url)` image syntax\n * into responsive `<picture>` elements when the URL matches the DCS CDN\n * asset pattern.\n *\n * Non-CDN images are rendered with the default image renderer (plain `<img>`).\n *\n * @example\n * ```ts\n * // .vitepress/config.ts\n * import { responsiveImagePlugin } from '@duffcloudservices/cms/plugins'\n *\n * export default defineConfig({\n * markdown: {\n * config: (md) => {\n * md.use(responsiveImagePlugin)\n * },\n * },\n * })\n * ```\n *\n * Input markdown:\n * ```md\n * ![Physical therapy session](https://files.duffcloudservices.com/kept/assets/blog/abc-123.jpg)\n * ```\n *\n * Rendered HTML:\n * ```html\n * <picture>\n * <source srcset=\"...abc-123-sm.webp 640w, ...abc-123-md.webp 1024w, ...abc-123-lg.webp 1920w\"\n * type=\"image/webp\"\n * sizes=\"(max-width: 1024px) 100vw, 1024px\" />\n * <img src=\"...abc-123-md.webp\" alt=\"Physical therapy session\" loading=\"lazy\" decoding=\"async\" />\n * </picture>\n * ```\n */\n\nimport type MarkdownIt from 'markdown-it'\n\n/**\n * Matches DCS CDN asset URLs: base path / UUID . extension.\n *\n * Aligned with `@duffcloudservices/cms-core` `responsive-image.ts`: the\n * `(?:content\\/)?` group covers the content-container shape\n * `https://files.duffcloudservices.com/content/{slug}/assets/...` in addition\n * to the branding-container shape `.../{slug}/assets/...`. The group is\n * non-capturing, so the captured base path / UUID / extension are unchanged.\n */\nconst CDN_PATTERN = /^(https?:\\/\\/files\\.[^/]+\\/(?:content\\/)?[^/]+\\/assets\\/(?:[^/]+\\/)*)([a-f0-9-]+)\\.(\\w+)$/\n\n/**\n * Escapes HTML special characters for safe attribute embedding.\n * Falls back to a simple replace chain when `md.utils.escapeHtml` is unavailable.\n */\nfunction escapeHtml(str: string): string {\n return str\n .replace(/&/g, '&amp;')\n .replace(/\"/g, '&quot;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n}\n\nexport function responsiveImagePlugin(md: MarkdownIt): void {\n const defaultImageRenderer = md.renderer.rules.image\n\n md.renderer.rules.image = (tokens, idx, options, env, self) => {\n const token = tokens[idx]\n const src = token.attrGet('src') ?? ''\n const alt = token.content ?? ''\n\n const match = src.match(CDN_PATTERN)\n if (!match) {\n // Not a CDN image — render normally\n if (defaultImageRenderer) {\n return defaultImageRenderer(tokens, idx, options, env, self)\n }\n return self.renderToken(tokens, idx, options)\n }\n\n const [, basePath, uuid] = match\n\n const srcset = [\n `${basePath}${uuid}-sm.webp 640w`,\n `${basePath}${uuid}-md.webp 1024w`,\n `${basePath}${uuid}-lg.webp 1920w`,\n ].join(', ')\n\n const escapedAlt = escapeHtml(alt)\n\n // Self-heal: this plugin emits a STATIC HTML string at build time (no Vue\n // runtime), so the fallback must be an inline onerror. A fit-variant\n // (`-md`/`-lg`) may legitimately be absent (internal/imaging variants.go\n // skips variants by DIMENSION). On the first error, swap the `<img>` to the\n // ORIGINAL url AND strip the sibling `<source>` elements — a `<picture>`\n // does NOT re-resolve after a `<source>` 404s, so the variant set must be\n // removed for the original to display. (`this.onerror=null` prevents loops.)\n const escapedOriginal = escapeHtml(src)\n const onError =\n `this.onerror=null;this.src='${escapedOriginal}';` +\n `this.closest('picture')?.querySelectorAll('source').forEach(s=>s.remove())`\n\n return [\n '<picture>',\n ` <source srcset=\"${srcset}\" type=\"image/webp\" sizes=\"(max-width: 1024px) 100vw, 1024px\" />`,\n ` <img src=\"${basePath}${uuid}-md.webp\" alt=\"${escapedAlt}\" loading=\"lazy\" decoding=\"async\" onerror=\"${onError}\" />`,\n '</picture>',\n ].join('\\n')\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/plugins/serveDefineInject.ts","../../src/plugins/dcsContentPlugin.ts","../../src/plugins/dcsSeoPlugin.ts","../../src/plugins/dcsEditorPlugin.ts","../../src/plugins/dcsPreviewPlugin.ts","../../src/plugins/dcsCdnImagePlugin.ts","../../src/plugins/responsiveImagePlugin.ts"],"names":["path","fs","yaml","escapeHtml"],"mappings":";;;;;;;AAiCO,SAAS,cAAA,CAAe,aAAqB,OAAA,EAA2B;AAC7E,EAAA,OAAO;AAAA,IACLA,KAAA,CAAK,OAAA,CAAQ,WAAA,EAAa,OAAO,CAAA;AAAA,IACjCA,KAAA,CAAK,OAAA,CAAQ,WAAA,EAAa,IAAA,EAAM,OAAO,CAAA;AAAA,IACvCA,KAAA,CAAK,OAAA,CAAQ,OAAA,CAAQ,GAAA,IAAO,OAAO;AAAA,GACrC;AACF;AAGO,SAAS,cAAA,CAAe,aAAqB,OAAA,EAAqC;AACvF,EAAA,OAAO,cAAA,CAAe,WAAA,EAAa,OAAO,CAAA,CAAE,IAAA,CAAK,CAAC,CAAA,KAAMC,GAAA,CAAG,UAAA,CAAW,CAAC,CAAC,CAAA;AAC1E;AAOO,SAAS,gBAAA,CACd,WAAA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CAAqB,MAAA,EAAQ,GAAA,EAAK,OAAA,EAAS,KAAK,IAAI,CAAA;AAAA,MAC7D;AACA,MAAA,OAAO,IAAA,CAAK,WAAA,CAAY,MAAA,EAAQ,GAAA,EAAK,OAAO,CAAA;AAAA,IAC9C;AAEA,IAAA,MAAM,GAAG,QAAA,EAAU,IAAI,CAAA,GAAI,KAAA;AAE3B,IAAA,MAAM,MAAA,GAAS;AAAA,MACb,CAAA,EAAG,QAAQ,CAAA,EAAG,IAAI,CAAA,aAAA,CAAA;AAAA,MAClB,CAAA,EAAG,QAAQ,CAAA,EAAG,IAAI,CAAA,cAAA,CAAA;AAAA,MAClB,CAAA,EAAG,QAAQ,CAAA,EAAG,IAAI,CAAA,cAAA;AAAA,KACpB,CAAE,KAAK,IAAI,CAAA;AAEX,IAAA,MAAM,UAAA,GAAaA,YAAW,GAAG,CAAA;AASjC,IAAA,MAAM,eAAA,GAAkBA,YAAW,GAAG,CAAA;AACtC,IAAA,MAAM,OAAA,GACJ,+BAA+B,eAAe,CAAA,4EAAA,CAAA;AAGhD,IAAA,OAAO;AAAA,MACL,WAAA;AAAA,MACA,qBAAqB,MAAM,CAAA,gEAAA,CAAA;AAAA,MAC3B,eAAe,QAAQ,CAAA,EAAG,IAAI,CAAA,eAAA,EAAkB,UAAU,8CAA8C,OAAO,CAAA,IAAA,CAAA;AAAA,MAC/G;AAAA,KACF,CAAE,KAAK,IAAI,CAAA;AAAA,EACb,CAAA;AACF","file":"index.js","sourcesContent":["/**\n * Shared serve-mode helpers for the DCS content + SEO Vite plugins.\n *\n * In a production build the plugins bake the `.dcs/*.yaml` payload into a Vite\n * `define` literal (`define: { __DCS_X__: JSON.stringify(data) }`) so the SSG /\n * SPA bundle inlines it exactly as before.\n *\n * In dev (`vite` / `vitepress dev`, i.e. the portal preview) baking a literal\n * is wrong: the value is frozen at server-start and only a `server.restart()`\n * would refresh it — and that restart is exactly what triggers VitePress's\n * MiniSearch rebuild and the duplicate-heading \"server restart failed\" crash.\n *\n * Instead, in serve mode the plugins:\n * 1. redirect the `__DCS_X__` define to a browser global\n * (`define: { __DCS_X__: 'globalThis.__DCS_X__' }`), and\n * 2. inject an inline classic `<script>` at the top of `<head>` on every HTML\n * request that assigns the FRESH on-disk YAML to that global.\n *\n * Because `transformIndexHtml` re-runs on every dev HTML request, a plain\n * iframe reload (the portal's `?_hc` hard reload) reflects the latest on-disk\n * content with NO `server.restart()` and NO module-graph surgery. The consumer\n * is untouched: it still reads the bare `__DCS_X__` identifier, which the define\n * rewrites to `globalThis.__DCS_X__`.\n */\n\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport yaml from 'js-yaml'\n\n/**\n * The three `.dcs` search locations the plugins have always used. VitePress\n * projects have the `docs/` folder as root, so the parent is checked too.\n */\nexport function dcsSearchPaths(projectRoot: string, relPath: string): string[] {\n return [\n path.resolve(projectRoot, relPath),\n path.resolve(projectRoot, '..', relPath),\n path.resolve(process.cwd(), relPath),\n ]\n}\n\n/** First existing `.dcs` file from the standard search, or `undefined`. */\nexport function resolveDcsFile(projectRoot: string, relPath: string): string | undefined {\n return dcsSearchPaths(projectRoot, relPath).find((p) => fs.existsSync(p))\n}\n\n/**\n * Read + parse a `.dcs` YAML file FRESH from disk on every call (no caching).\n * Returns the parsed value, or `undefined` when the file is missing or\n * unparseable. Never throws — a dev HTML request must never 500 on bad YAML.\n */\nexport function readDcsYamlFresh<T = unknown>(\n projectRoot: string,\n relPath: string,\n label: string,\n debug = false\n): T | undefined {\n const found = resolveDcsFile(projectRoot, relPath)\n if (!found) {\n if (debug) console.log(`[${label}] serve: no ${relPath} found; global left unset`)\n return undefined\n }\n try {\n return yaml.load(fs.readFileSync(found, 'utf8')) as T\n } catch (error) {\n console.warn(`[${label}] serve: failed to parse ${relPath}:`, error)\n return undefined\n }\n}\n\n/**\n * Build a safe inline `<script>` body that assigns a JSON-serialisable value to\n * a browser global. Every `<` is escaped to its `<` unicode form so an\n * embedded `</script>` (or `<!--`) inside the content data can never break out\n * of the inline script.\n */\nexport function buildGlobalAssignScript(globalName: string, value: unknown): string {\n const json = JSON.stringify(value ?? null).replace(/</g, '\\\\u003c')\n return `globalThis.${globalName} = ${json};`\n}\n","/**\n * DCS Content Plugin for Vite\n *\n * Reads `.dcs/content.yaml` at build time and injects content\n * as `__DCS_CONTENT__` global variable for use by useTextContent.\n *\n * @example\n * ```typescript\n * // vite.config.ts\n * import { dcsContentPlugin } from '@duffcloudservices/cms/plugins'\n *\n * export default defineConfig({\n * plugins: [\n * dcsContentPlugin({ debug: true })\n * ]\n * })\n * ```\n *\n * For VitePress:\n * ```typescript\n * // .vitepress/config.ts\n * import { defineConfig } from 'vitepress'\n * import { dcsContentPlugin } from '@duffcloudservices/cms/plugins'\n *\n * export default defineConfig({\n * vite: {\n * plugins: [\n * dcsContentPlugin()\n * ]\n * }\n * })\n * ```\n */\n\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport yaml from 'js-yaml'\nimport type { Plugin, ResolvedConfig, HtmlTagDescriptor } from 'vite'\nimport type { DcsContentFile } from '../types/content'\nimport { readDcsYamlFresh, buildGlobalAssignScript } from './serveDefineInject'\n\nexport interface DcsContentPluginOptions {\n /** Path to content.yaml relative to project root (default: '.dcs/content.yaml') */\n contentPath?: string\n /** Enable debug logging */\n debug?: boolean\n}\n\n/**\n * Vite plugin that injects .dcs/content.yaml at build time.\n *\n * @param options - Plugin configuration\n * @returns Vite plugin\n */\nexport function dcsContentPlugin(options: DcsContentPluginOptions = {}): Plugin {\n const { contentPath = '.dcs/content.yaml', debug = false } = options\n\n let resolvedConfig: ResolvedConfig\n // Captured during configResolved — gates the serve-only inline HTML inject.\n let isDev = false\n\n return {\n name: 'dcs-content',\n\n configResolved(config) {\n resolvedConfig = config\n isDev = config.command === 'serve'\n },\n\n config(config, env) {\n // ── Dev / preview (serve) ──────────────────────────────────────────────\n // Don't bake content into the bundle. Redirect the `__DCS_CONTENT__`\n // define to a browser global that `transformIndexHtml` (below) refreshes\n // from disk on every HTML request — so a plain iframe reload reflects the\n // latest on-disk content with NO server.restart() and NO module-graph\n // surgery. The consumer is untouched: it still reads the bare\n // `__DCS_CONTENT__` identifier, which this define rewrites to\n // `globalThis.__DCS_CONTENT__`.\n if (env.command === 'serve') {\n return {\n define: {\n __DCS_CONTENT__: 'globalThis.__DCS_CONTENT__',\n },\n }\n }\n\n // ── Production build ───────────────────────────────────────────────────\n // Unchanged: read content.yaml now and bake it into the bundle as a\n // JSON literal so the SSG / SPA output inlines content exactly as before.\n const projectRoot = config.root || process.cwd()\n\n // Try to find content.yaml in multiple locations\n // VitePress projects have the docs folder as root, so check parent too\n const possiblePaths = [\n path.resolve(projectRoot, contentPath),\n path.resolve(projectRoot, '..', contentPath),\n path.resolve(process.cwd(), contentPath),\n ]\n\n let foundPath: string | undefined\n for (const testPath of possiblePaths) {\n if (fs.existsSync(testPath)) {\n foundPath = testPath\n break\n }\n }\n\n if (!foundPath) {\n if (debug) {\n console.log('[dcs-content] No content.yaml found at:')\n possiblePaths.forEach((p) => console.log(` - ${p}`))\n console.log('[dcs-content] Using defaults only')\n }\n return {\n define: {\n __DCS_CONTENT__: 'undefined',\n },\n }\n }\n\n try {\n const fileContent = fs.readFileSync(foundPath, 'utf8')\n const content = yaml.load(fileContent) as DcsContentFile\n\n if (debug) {\n console.log(`[dcs-content] Loaded ${foundPath}`)\n console.log(`[dcs-content] Version: ${content.version}`)\n console.log(`[dcs-content] Pages: ${Object.keys(content.pages ?? {}).join(', ') || '(none)'}`)\n console.log(`[dcs-content] Global keys: ${Object.keys(content.global ?? {}).length}`)\n }\n\n return {\n define: {\n __DCS_CONTENT__: JSON.stringify(content),\n },\n }\n } catch (error) {\n console.warn('[dcs-content] Failed to parse content.yaml:', error)\n return {\n define: {\n __DCS_CONTENT__: 'undefined',\n },\n }\n }\n },\n\n /**\n * Dev-only: inject the FRESH on-disk `content.yaml` as an inline\n * `globalThis.__DCS_CONTENT__ = {…}` classic script at the top of `<head>`.\n *\n * Runs on every dev HTML request, so the portal's `?_hc` hard reload (or any\n * full page reload) re-reads the YAML with no restart. A classic `<script>`\n * in `<head>` executes during HTML parsing, before the deferred module app\n * entry, so the global is set before the consumer's `useTextContent` setup\n * reads it. Gated on `isDev` so it never runs in `vite`/`vitepress build`\n * (the build path keeps the baked `define` literal).\n */\n transformIndexHtml: {\n order: 'pre',\n handler(html) {\n if (!isDev) return html\n\n const projectRoot = resolvedConfig?.root || process.cwd()\n const content = readDcsYamlFresh<DcsContentFile>(\n projectRoot,\n contentPath,\n 'dcs-content',\n debug\n )\n // No file (or unparseable) ⇒ leave the global unset; the consumer's\n // `typeof globalThis.__DCS_CONTENT__` check falls back to defaults.\n if (content === undefined) return html\n\n if (debug) {\n console.log('[dcs-content] serve: injecting fresh __DCS_CONTENT__ into <head>')\n }\n\n const tags: HtmlTagDescriptor[] = [\n {\n tag: 'script',\n children: buildGlobalAssignScript('__DCS_CONTENT__', content),\n injectTo: 'head-prepend',\n },\n ]\n return { html, tags }\n },\n },\n\n // Watch for changes in development.\n //\n // Downgraded from `server.restart()` to a debounced client `full-reload`:\n // freshness already comes from `transformIndexHtml` re-reading the YAML on\n // every HTML request, so all we need on change is to nudge the browser to\n // reload. A `server.restart()` would rebuild VitePress's dev MiniSearch\n // index and can throw \"server restart failed\" on a duplicate heading id —\n // exactly the fragility this fix removes. A `full-reload` does neither.\n configureServer(server) {\n const projectRoot = resolvedConfig?.root || process.cwd()\n\n const watchPaths = [\n path.resolve(projectRoot, contentPath),\n path.resolve(projectRoot, '..', contentPath),\n ].map((p) => path.normalize(p))\n\n watchPaths.forEach((watchPath) => {\n if (fs.existsSync(watchPath)) {\n server.watcher.add(watchPath)\n }\n })\n\n let reloadTimer: ReturnType<typeof setTimeout> | undefined\n server.watcher.on('change', (changedPath) => {\n if (!watchPaths.includes(path.normalize(changedPath))) return\n if (reloadTimer) clearTimeout(reloadTimer)\n reloadTimer = setTimeout(() => {\n if (debug) {\n console.log('[dcs-content] content.yaml changed, sending full-reload')\n }\n server.ws.send({ type: 'full-reload' })\n }, 100)\n })\n },\n }\n}\n","/**\n * DCS SEO Plugin for Vite\n *\n * Two responsibilities, both driven by `.dcs/seo.yaml`:\n *\n * 1. **Build-time define** (always on): reads `.dcs/seo.yaml` and injects it as\n * the `__DCS_SEO__` global for the runtime `useSEO` composable.\n *\n * 2. **Static `<head>` emitter** (opt-in via `emitStaticHtml: true`, default\n * OFF): after the bundle is written, reads the SPA's built `index.html`,\n * and for every route in `.dcs/pages.yaml` writes a per-route\n * `dist/<path>/index.html` whose `<head>` carries the resolved title, meta,\n * canonical, Open Graph, Twitter, and JSON-LD tags. This gives a Vue SPA\n * per-route static SEO **without** vite-ssg.\n *\n * VitePress sites already bake SEO via their own config, so they leave this\n * option OFF and are completely unaffected.\n *\n * @example Runtime define only (default — safe for VitePress)\n * ```typescript\n * // vite.config.ts\n * import { dcsSeoPlugin } from '@duffcloudservices/cms/plugins'\n *\n * export default defineConfig({\n * plugins: [dcsSeoPlugin({ debug: true })]\n * })\n * ```\n *\n * @example Vue SPA with per-route static <head> emission\n * ```typescript\n * // vite.config.ts\n * import { dcsSeoPlugin } from '@duffcloudservices/cms/plugins'\n *\n * export default defineConfig({\n * plugins: [\n * dcsSeoPlugin({\n * emitStaticHtml: true, // turn the emitter ON\n * pagesPath: '.dcs/pages.yaml', // route manifest (default)\n * noindex: ['account', 'projects'], // robots: noindex,nofollow\n * exclude: ['/preview'], // skip these routes entirely\n * })\n * ]\n * })\n * ```\n */\n\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport yaml from 'js-yaml'\nimport type { Plugin, ResolvedConfig, HtmlTagDescriptor } from 'vite'\nimport type { SeoConfiguration } from '../types/seo'\nimport { readDcsYamlFresh, buildGlobalAssignScript } from './serveDefineInject'\nimport { buildHeadTags } from '../seo/headTags'\nimport { spliceHeadHtml } from '../seo/spliceHeadHtml'\nimport { loadPagesManifest, type PageRouteEntry } from '../seo/pagesManifest'\nimport {\n buildSitemapXml,\n buildRobotsTxt,\n buildLlmsTxt,\n matchesExcludedGlob,\n isHandAuthoredRobotsAcceptable,\n type DcsRobotsOptions,\n} from '../seo/sitemap'\nimport {\n breadcrumbTrailFromRoute,\n findReviewItemsForPage,\n type ContentConfig,\n type ReviewSource,\n type BlogMeta,\n type FaqSource,\n} from '../seo/schemaGraph'\n\nexport interface DcsSeoPluginOptions {\n /** Path to seo.yaml relative to project root (default: '.dcs/seo.yaml') */\n seoPath?: string\n /** Enable debug logging */\n debug?: boolean\n\n /**\n * Opt-in: emit per-route static `<head>` (meta + JSON-LD) into the built\n * `dist/` at the end of the build. Default `false` — VitePress sites and any\n * site that bakes its own SEO are unaffected when this is off.\n */\n emitStaticHtml?: boolean\n\n /**\n * Path to the route manifest relative to project root, used only when\n * `emitStaticHtml` is true. Default `'.dcs/pages.yaml'`.\n */\n pagesPath?: string\n\n /**\n * Path to `content.yaml` relative to project root, used only when\n * `emitStaticHtml` is true. Threads REAL reviews into the honest\n * Review/aggregateRating on the per-route LocalBusiness node. Default\n * `'.dcs/content.yaml'`. Missing/unparseable ⇒ no reviews emitted.\n */\n contentPath?: string\n\n /**\n * Routes to skip entirely (no per-route HTML written). Matched against the\n * route `path` (e.g. `'/preview'`) OR the route `slug` (e.g. `'account'`).\n */\n exclude?: string[]\n\n /**\n * Routes that should receive `robots: noindex, nofollow`. Matched against the\n * route `path` OR `slug`. The home route (`/`) still overwrites\n * `dist/index.html`.\n */\n noindex?: string[]\n\n /**\n * Opt-in: emit the site-wide static files `dist/sitemap.xml`,\n * `dist/robots.txt`, and `dist/llms.txt` after the per-route HTML loop.\n *\n * Defaults to whatever `emitStaticHtml` is — so every site already calling\n * `dcsSeoPlugin({ emitStaticHtml: true })` gets sitemap/robots/llms for free\n * with zero per-site edits. Set explicitly to `false` to keep emitting\n * per-route HTML without the site files. The whole block is wrapped in the\n * same try/catch + existsSync guards, so it can never break a build.\n */\n emitSiteFiles?: boolean\n\n /**\n * Canonical production origin, e.g. `https://ironoakcontractors.com`. Used as\n * the sitemap/llms base and the absolute `Sitemap:` line in robots.txt. When\n * absent, falls back to `seo.yaml`'s `global.siteUrl`; if neither is known and\n * no per-page canonicals exist, the sitemap + llms.txt no-op (robots still\n * emits). Never guessed.\n */\n siteUrl?: string\n\n /** robots.txt override hooks (disallow/allow/extra/aiBots/force). */\n robots?: DcsRobotsOptions\n\n /**\n * Preview / staging gate. When `true`, robots.txt becomes `Disallow: /` (no\n * `Sitemap:` line) and neither sitemap.xml nor llms.txt is emitted (privacy).\n * Detected ONLY via this explicit option — never guessed.\n */\n preview?: boolean\n\n /** Emit `dist/llms.txt` (default `true`; always off in preview mode). */\n llms?: boolean\n}\n\n/** Resolve the SPA output directory from Vite config (absolute path). */\nfunction resolveOutDir(config: ResolvedConfig): string {\n const out = config.build?.outDir || 'dist'\n return path.isAbsolute(out) ? out : path.resolve(config.root || process.cwd(), out)\n}\n\n/**\n * Load + parse seo.yaml from the usual `.dcs` locations.\n * Returns `{ config, foundPath }` or `null` (missing/unparseable).\n */\nfunction loadSeoConfig(\n projectRoot: string,\n seoPath: string,\n debug: boolean\n): { config: SeoConfiguration; foundPath: string } | null {\n const possiblePaths = [\n path.resolve(projectRoot, seoPath),\n path.resolve(projectRoot, '..', seoPath),\n path.resolve(process.cwd(), seoPath),\n ]\n\n let foundPath: string | undefined\n for (const testPath of possiblePaths) {\n if (fs.existsSync(testPath)) {\n foundPath = testPath\n break\n }\n }\n\n if (!foundPath) {\n if (debug) {\n console.log('[dcs-seo] No seo.yaml found at:')\n possiblePaths.forEach((p) => console.log(` - ${p}`))\n console.log('[dcs-seo] Using defaults only')\n }\n return null\n }\n\n try {\n const fileContent = fs.readFileSync(foundPath, 'utf8')\n const config = yaml.load(fileContent) as SeoConfiguration\n return { config, foundPath }\n } catch (error) {\n console.warn('[dcs-seo] Failed to parse seo.yaml:', error)\n return null\n }\n}\n\n/**\n * Load + parse `.dcs/content.yaml` from the usual `.dcs` locations. Returns the\n * parsed config or `undefined` (missing/unparseable). Used to thread REAL\n * reviews into the honest Review/aggregateRating builder. Never throws.\n */\nfunction loadContentConfig(\n projectRoot: string,\n contentRelPath: string,\n debug: boolean\n): ContentConfig | undefined {\n const possiblePaths = [\n path.resolve(projectRoot, contentRelPath),\n path.resolve(projectRoot, '..', contentRelPath),\n path.resolve(process.cwd(), contentRelPath),\n ]\n const foundPath = possiblePaths.find((p) => fs.existsSync(p))\n if (!foundPath) {\n if (debug) console.log(`[dcs-seo] No content.yaml found (reviews disabled)`)\n return undefined\n }\n try {\n const parsed = yaml.load(fs.readFileSync(foundPath, 'utf8'))\n if (!parsed || typeof parsed !== 'object') return undefined\n return parsed as ContentConfig\n } catch (error) {\n console.warn('[dcs-seo] Failed to parse content.yaml (reviews disabled):', error)\n return undefined\n }\n}\n\n/**\n * Normalise a route path to the on-disk output file:\n * '/' -> '<outDir>/index.html'\n * '/services' -> '<outDir>/services/index.html'\n * '/blog/my-post' -> '<outDir>/blog/my-post/index.html'\n * '/services/' -> '<outDir>/services/index.html'\n */\nfunction routeToOutputFile(outDir: string, routePath: string): string {\n const trimmed = routePath.replace(/^\\/+/, '').replace(/\\/+$/, '')\n if (trimmed === '') return path.join(outDir, 'index.html')\n return path.join(outDir, ...trimmed.split('/'), 'index.html')\n}\n\n/** Extract the optional top-level `excluded:` glob list from pages.yaml. */\nfunction loadExcludedGlobs(projectRoot: string, pagesPath: string): string[] {\n const possiblePaths = [\n path.resolve(projectRoot, pagesPath),\n path.resolve(projectRoot, '..', pagesPath),\n path.resolve(process.cwd(), pagesPath),\n ]\n const found = possiblePaths.find((p) => fs.existsSync(p))\n if (!found) return []\n try {\n const raw = yaml.load(fs.readFileSync(found, 'utf8')) as { excluded?: unknown } | null\n const excluded = raw?.excluded\n if (!Array.isArray(excluded)) return []\n return excluded.filter((e): e is string => typeof e === 'string')\n } catch {\n return []\n }\n}\n\n/**\n * Derive a single site-wide lastmod from seo.yaml `lastUpdated` (preferred) or\n * pages.yaml `lastUpdated`. No fabricated per-page dates.\n */\nfunction deriveLastmod(\n seoConfig: SeoConfiguration | undefined,\n projectRoot: string,\n pagesPath: string\n): string | undefined {\n const fromSeo = seoConfig?.lastUpdated\n if (typeof fromSeo === 'string' && fromSeo.length > 0) return fromSeo\n\n const possiblePaths = [\n path.resolve(projectRoot, pagesPath),\n path.resolve(projectRoot, '..', pagesPath),\n path.resolve(process.cwd(), pagesPath),\n ]\n const found = possiblePaths.find((p) => fs.existsSync(p))\n if (!found) return undefined\n try {\n const raw = yaml.load(fs.readFileSync(found, 'utf8')) as { lastUpdated?: unknown } | null\n const fromPages = raw?.lastUpdated\n if (typeof fromPages === 'string' && fromPages.length > 0) return fromPages\n } catch {\n /* ignore */\n }\n return undefined\n}\n\n/**\n * Core site-file emitter, separated from Vite so it is unit-testable.\n *\n * Writes the site-wide static files into `outDir`, reusing the SAME routes +\n * seoConfig already loaded by the per-route HTML loop (no second manifest read):\n * - `sitemap.xml` (skipped in preview, or when no absolute base is derivable)\n * - `robots.txt` (always; preview = `Disallow: /`; don't-clobber unless force)\n * - `llms.txt` (skipped in preview, or when nothing indexable)\n *\n * Returns the list of relative filenames written. Pure aside from `fs` writes —\n * deterministic + idempotent. Never throws (the caller also wraps in try/catch).\n */\nexport function emitSiteFiles(params: {\n outDir: string\n projectRoot: string\n pagesPath: string\n routes: PageRouteEntry[]\n seoConfig: SeoConfiguration | undefined\n siteUrl?: string\n exclude?: string[]\n noindex?: string[]\n preview?: boolean\n robots?: DcsRobotsOptions\n llms?: boolean\n debug?: boolean\n}): string[] {\n const {\n outDir,\n projectRoot,\n pagesPath,\n routes,\n seoConfig,\n siteUrl,\n exclude = [],\n noindex = [],\n preview = false,\n robots = {},\n llms = true,\n debug = false,\n } = params\n\n const written: string[] = []\n\n const effectiveSiteUrl = siteUrl || seoConfig?.global?.siteUrl\n const excludedGlobs = loadExcludedGlobs(projectRoot, pagesPath)\n const lastmod = deriveLastmod(seoConfig, projectRoot, pagesPath)\n\n // ── sitemap.xml (not in preview) ──────────────────────────────────────────\n let wroteSitemap = false\n if (!preview) {\n const xml = buildSitemapXml({\n routes,\n siteUrl: effectiveSiteUrl,\n seoConfig,\n exclude,\n noindex,\n excludedGlobs,\n lastmod,\n })\n if (xml) {\n fs.writeFileSync(path.join(outDir, 'sitemap.xml'), xml, 'utf8')\n wroteSitemap = true\n written.push('sitemap.xml')\n if (debug) console.log('[dcs-seo] wrote sitemap.xml')\n } else if (debug) {\n console.log('[dcs-seo] no absolute <loc> derivable; sitemap.xml not written')\n }\n }\n\n // ── robots.txt (always, unless robots.enabled is false) ───────────────────\n if (robots.enabled ?? true) {\n const robotsPath = path.join(outDir, 'robots.txt')\n // Factory-as-single-source (validated override): a hand-authored\n // public/robots.txt Vite copied into dist is KEPT only when it meets the\n // factory floor (a real `User-agent: *` group + every AI-bot tier). A stub\n // (`Sitemap:`-only, like just-posh) or an SPA-shell HTML page fails the\n // floor and is overwritten so AI discovery is guaranteed on every site.\n // `force` always overwrites; an absent file is always written.\n const existing =\n fs.existsSync(robotsPath) && !robots.force ? fs.readFileSync(robotsPath, 'utf8') : null\n const keepHandAuthored = existing !== null && isHandAuthoredRobotsAcceptable(existing)\n if (keepHandAuthored) {\n if (debug)\n console.log('[dcs-seo] dist/robots.txt is hand-authored and meets the floor; leaving it')\n } else {\n const txt = buildRobotsTxt({\n siteUrl: effectiveSiteUrl,\n preview,\n robots,\n hasSitemap: wroteSitemap,\n })\n fs.writeFileSync(robotsPath, txt, 'utf8')\n written.push('robots.txt')\n if (debug) {\n console.log(\n existing !== null\n ? '[dcs-seo] dist/robots.txt failed the factory floor; overwrote with emitted robots'\n : '[dcs-seo] wrote robots.txt'\n )\n }\n }\n }\n\n // ── llms.txt (not in preview) ─────────────────────────────────────────────\n if (llms && !preview) {\n const txt = buildLlmsTxt({\n routes,\n siteUrl: effectiveSiteUrl,\n seoConfig,\n exclude,\n noindex,\n excludedGlobs,\n })\n if (txt) {\n fs.writeFileSync(path.join(outDir, 'llms.txt'), txt, 'utf8')\n written.push('llms.txt')\n if (debug) console.log('[dcs-seo] wrote llms.txt')\n } else if (debug) {\n console.log('[dcs-seo] nothing indexable; llms.txt not written')\n }\n }\n\n return written\n}\n\n/**\n * Pick a structured FAQ array (`[{ q, a }]`) for a page from content.yaml, if\n * one exists under a `faq` key (page-scoped, then global). Returns `undefined`\n * when there is no structured Q&A — a `<FaqPage />` component is NOT a source,\n * so its pages correctly yield nothing (honesty).\n */\nfunction pickPageFaq(\n content: ContentConfig | undefined,\n pageSlug: string\n): FaqSource[] | undefined {\n if (!content) return undefined\n const fromBlock = (block: Record<string, unknown> | undefined): FaqSource[] | undefined => {\n if (!block) return undefined\n const v = block['faq']\n return Array.isArray(v) ? (v as FaqSource[]) : undefined\n }\n return fromBlock(content.pages?.[pageSlug]) ?? fromBlock(content.global)\n}\n\n/**\n * Core emitter, separated from Vite so it is unit-testable.\n *\n * For each route: build the head tags from the shared resolver, splice them\n * into the shell HTML, and write `dist/<path>/index.html`. Returns the number\n * of files written. Pure aside from `fs` writes — deterministic + idempotent.\n */\nexport function emitStaticSeoHtml(params: {\n outDir: string\n shellHtml: string\n routes: PageRouteEntry[]\n seoConfig: SeoConfiguration | undefined\n /**\n * Parsed `.dcs/content.yaml` — threads REAL review items (honesty-gated) into\n * the per-route LocalBusiness node. Optional; omit ⇒ no Review/aggregateRating.\n */\n contentConfig?: ContentConfig\n exclude?: string[]\n noindex?: string[]\n /** `pages.yaml` top-level `excluded:` globs — routes matching are NOT emitted. */\n excludedGlobs?: string[]\n debug?: boolean\n}): number {\n const {\n outDir,\n shellHtml,\n routes,\n seoConfig,\n contentConfig,\n exclude = [],\n noindex = [],\n excludedGlobs = [],\n debug = false,\n } = params\n\n const excludeSet = new Set(exclude)\n const noindexSet = new Set(noindex)\n\n // Route → human title map (for breadcrumb hop labels), from the manifest.\n const siteUrl = seoConfig?.global?.siteUrl ?? ''\n const routeTitles: Record<string, string> = { '/': 'Home' }\n for (const r of routes) {\n if (r.title && r.path) routeTitles[r.path.replace(/\\/+$/, '') || '/'] = r.title\n }\n\n let written = 0\n for (const route of routes) {\n if (excludeSet.has(route.path) || (route.slug && excludeSet.has(route.slug))) {\n if (debug) console.log(`[dcs-seo] skip (excluded): ${route.path}`)\n continue\n }\n\n // Honor pages.yaml top-level `excluded:` globs (e.g. `/dev-*`, `/_*`): an\n // excluded route must NOT get a per-route index.html, or it becomes a\n // crawlable/indexable page despite being intentionally hidden — a privacy\n // and crawl-budget leak. Same glob semantics as the sitemap path.\n if (matchesExcludedGlob(route.path, excludedGlobs)) {\n if (debug) console.log(`[dcs-seo] skip (excluded glob): ${route.path}`)\n continue\n }\n\n const forceNoindex =\n noindexSet.has(route.path) || (route.slug && noindexSet.has(route.slug))\n\n // Breadcrumb trail from route depth (home ⇒ none); titles from the manifest.\n const breadcrumbTrail = siteUrl\n ? breadcrumbTrailFromRoute(route.path, siteUrl, routeTitles)\n : undefined\n\n // REAL reviews for this page from content.yaml (honesty-gated downstream).\n const reviews: ReviewSource[] | undefined = contentConfig\n ? findReviewItemsForPage(contentConfig, route.slug)\n : undefined\n\n // BlogPosting for a blog post route — only when seo.yaml has NOT already\n // hand-authored one (buildHeadTags skips ours if it has). A blog post is a\n // route nested under `/blog/` (depth ≥ 2) with a manifest title.\n const isBlogPost = /^\\/blog\\/.+/.test(route.path) && !!route.title\n const blogMeta: BlogMeta | undefined = isBlogPost\n ? { headline: route.title, url: breadcrumbTrail?.[breadcrumbTrail.length - 1]?.item }\n : undefined\n\n // FAQ from a structured `.dcs/faq.yaml`-style block on the content page, if\n // present (honesty-gated). Component-only FAQ pages carry no such data.\n const faq: FaqSource[] | undefined = pickPageFaq(contentConfig, route.slug)\n\n const tags = buildHeadTags(route.slug, route.path, seoConfig, {\n includeKeywords: true,\n fallbackTitle: route.title,\n robots: forceNoindex ? 'noindex, nofollow' : undefined,\n emitGraph: true,\n breadcrumbTrail,\n reviews,\n blogMeta,\n faq,\n })\n\n const html = spliceHeadHtml(shellHtml, tags)\n const outFile = routeToOutputFile(outDir, route.path)\n\n fs.mkdirSync(path.dirname(outFile), { recursive: true })\n fs.writeFileSync(outFile, html, 'utf8')\n written++\n\n if (debug) {\n console.log(\n `[dcs-seo] wrote ${path.relative(outDir, outFile)} (title=\"${tags.title}\"${\n forceNoindex ? ', noindex' : ''\n })`\n )\n }\n }\n\n return written\n}\n\n/**\n * Vite plugin that injects .dcs/seo.yaml at build time and, optionally, emits\n * per-route static `<head>` HTML for SPA SEO.\n *\n * @param options - Plugin configuration\n * @returns Vite plugin\n */\nexport function dcsSeoPlugin(options: DcsSeoPluginOptions = {}): Plugin {\n const {\n seoPath = '.dcs/seo.yaml',\n debug = false,\n emitStaticHtml = false,\n pagesPath = '.dcs/pages.yaml',\n contentPath = '.dcs/content.yaml',\n exclude = [],\n noindex = [],\n // Site files default ON whenever per-route HTML emission is on, so the\n // sites already using emitStaticHtml gain sitemap/robots/llms with no edit.\n emitSiteFiles: emitSiteFilesOpt = emitStaticHtml,\n siteUrl,\n robots = {},\n preview = false,\n llms = true,\n } = options\n\n let resolvedConfig: ResolvedConfig\n // Captured during configResolved — gates the serve-only inline HTML inject.\n let isDev = false\n\n return {\n name: 'dcs-seo',\n\n configResolved(config) {\n resolvedConfig = config\n isDev = config.command === 'serve'\n },\n\n config(config, env) {\n // ── Dev / preview (serve) ──────────────────────────────────────────────\n // Don't bake seo.yaml into the bundle. Redirect the `__DCS_SEO__` define\n // to a browser global that `transformIndexHtml` (below) refreshes from\n // disk on every HTML request — live preview with NO server.restart().\n // The consumer is untouched: it still reads the bare `__DCS_SEO__`\n // identifier, which this define rewrites to `globalThis.__DCS_SEO__`.\n // (VitePress treats `useSEO` as a no-op and bakes SEO via\n // transformPageData, so this only affects the runtime `useSEO` SPA path.)\n if (env.command === 'serve') {\n return {\n define: {\n __DCS_SEO__: 'globalThis.__DCS_SEO__',\n },\n }\n }\n\n // ── Production build ───────────────────────────────────────────────────\n // Unchanged: read seo.yaml now and bake it into the bundle as a literal.\n const projectRoot = config.root || process.cwd()\n\n const loaded = loadSeoConfig(projectRoot, seoPath, debug)\n if (!loaded) {\n return {\n define: {\n __DCS_SEO__: 'undefined',\n },\n }\n }\n\n if (debug) {\n console.log(`[dcs-seo] Loaded ${loaded.foundPath}`)\n console.log(`[dcs-seo] Version: ${loaded.config.version}`)\n console.log(`[dcs-seo] Site Name: ${loaded.config.global?.siteName || '(not set)'}`)\n console.log(\n `[dcs-seo] Pages: ${Object.keys(loaded.config.pages ?? {}).join(', ') || '(none)'}`\n )\n }\n\n return {\n define: {\n __DCS_SEO__: JSON.stringify(loaded.config),\n },\n }\n },\n\n /**\n * Build-time static `<head>` emitter (opt-in via `emitStaticHtml`).\n *\n * Runs after the bundle is written so the built `index.html` shell exists\n * on disk. For an SPA, Vite emits a single `index.html`; we fan it out to\n * per-route files with route-specific `<head>` content.\n *\n * Fully defensive: any missing/unparseable input logs a warning and\n * no-ops. Never throws (so it can never break a production build).\n */\n writeBundle() {\n if (!emitStaticHtml) {\n // The whole emit path is gated on emitStaticHtml. If the operator\n // explicitly asked for site files (`emitSiteFiles: true`) while\n // emitStaticHtml is off, that request is silently inert — warn so it's\n // not mistaken for \"robots/sitemap were emitted\".\n if (options.emitSiteFiles === true) {\n console.warn(\n '[dcs-seo] emitSiteFiles:true is ignored because emitStaticHtml is false; ' +\n 'set emitStaticHtml:true to emit sitemap.xml/robots.txt/llms.txt'\n )\n }\n return\n }\n\n try {\n const projectRoot = resolvedConfig?.root || process.cwd()\n const outDir = resolveOutDir(resolvedConfig)\n\n if (!fs.existsSync(outDir)) {\n console.warn(`[dcs-seo] emitStaticHtml: outDir not found (${outDir}); skipping`)\n return\n }\n\n const shellPath = path.join(outDir, 'index.html')\n if (!fs.existsSync(shellPath)) {\n console.warn(\n `[dcs-seo] emitStaticHtml: no index.html in ${outDir}; nothing to emit`\n )\n return\n }\n\n const routes = loadPagesManifest(projectRoot, pagesPath, debug)\n if (!routes) {\n console.warn(\n `[dcs-seo] emitStaticHtml: ${pagesPath} missing or empty; skipping per-route emission`\n )\n return\n }\n\n const loaded = loadSeoConfig(projectRoot, seoPath, debug)\n if (!loaded) {\n // seo.yaml is optional for emission — routes still get baked with\n // global/runtime defaults (which here means just the shell title and\n // a derived canonical-less head). Warn so the operator knows.\n console.warn(\n `[dcs-seo] emitStaticHtml: ${seoPath} missing or unparseable; emitting with defaults only`\n )\n }\n\n const shellHtml = fs.readFileSync(shellPath, 'utf8')\n\n // pages.yaml top-level `excluded:` globs gate BOTH the per-route HTML\n // emission below and the sitemap/llms set inside emitSiteFiles, so an\n // excluded route is never written as a crawlable index.html.\n const excludedGlobs = loadExcludedGlobs(projectRoot, pagesPath)\n // Optional: load content.yaml so REAL reviews can feed the honest\n // Review/aggregateRating on the per-route LocalBusiness node. Absent or\n // unparseable ⇒ undefined ⇒ no reviews emitted (no synthesis).\n const contentConfig = loadContentConfig(projectRoot, contentPath, debug)\n\n const written = emitStaticSeoHtml({\n outDir,\n shellHtml,\n routes,\n seoConfig: loaded?.config,\n contentConfig,\n exclude,\n noindex,\n excludedGlobs,\n debug,\n })\n\n if (debug) {\n console.log(`[dcs-seo] emitStaticHtml: wrote ${written} per-route HTML file(s)`)\n }\n\n // ── site-wide static files (sitemap.xml, robots.txt, llms.txt) ──────\n // Emitted AFTER the per-route HTML loop so canonicals/routes are\n // resolved and the shell exists. Reuses the already-loaded routes +\n // seoConfig (no second manifest read). Same outDir/existsSync guard +\n // the outer try/catch — so it can never break a production build.\n if (emitSiteFilesOpt) {\n const siteFiles = emitSiteFiles({\n outDir,\n projectRoot,\n pagesPath,\n routes,\n seoConfig: loaded?.config,\n siteUrl,\n exclude,\n noindex,\n preview,\n robots,\n llms,\n debug,\n })\n if (debug) {\n console.log(\n `[dcs-seo] emitSiteFiles: wrote ${siteFiles.length} site file(s): ${\n siteFiles.join(', ') || '(none)'\n }`\n )\n }\n }\n } catch (error) {\n // Never break the build on SEO emission failure.\n console.warn('[dcs-seo] emitStaticHtml failed; build output left unchanged:', error)\n }\n },\n\n /**\n * Dev-only: inject the FRESH on-disk `seo.yaml` as an inline\n * `globalThis.__DCS_SEO__ = {…}` classic script at the top of `<head>`,\n * mirroring dcsContentPlugin. Lets the runtime `useSEO` SPA path reflect\n * on-disk SEO edits on the portal's `?_hc` hard reload with no restart.\n * Gated on `isDev` so it never runs in `vite`/`vitepress build` (the build\n * path keeps the baked `define` literal + the `writeBundle` emitter).\n */\n transformIndexHtml: {\n order: 'pre',\n handler(html) {\n if (!isDev) return html\n\n const projectRoot = resolvedConfig?.root || process.cwd()\n const config = readDcsYamlFresh<SeoConfiguration>(projectRoot, seoPath, 'dcs-seo', debug)\n // No file (or unparseable) ⇒ leave the global unset; the consumer's\n // `typeof globalThis.__DCS_SEO__` check falls back to defaults.\n if (config === undefined) return html\n\n if (debug) {\n console.log('[dcs-seo] serve: injecting fresh __DCS_SEO__ into <head>')\n }\n\n const tags: HtmlTagDescriptor[] = [\n {\n tag: 'script',\n children: buildGlobalAssignScript('__DCS_SEO__', config),\n injectTo: 'head-prepend',\n },\n ]\n return { html, tags }\n },\n },\n\n // Watch for changes in development.\n //\n // Downgraded from `server.restart()` to a debounced client `full-reload`:\n // freshness already comes from `transformIndexHtml` re-reading the YAML on\n // every HTML request, so all we need on change is a browser reload. A\n // `server.restart()` would rebuild VitePress's dev MiniSearch index and can\n // throw \"server restart failed\" on a duplicate heading id — the fragility\n // this fix removes. A `full-reload` does neither.\n configureServer(server) {\n const projectRoot = resolvedConfig?.root || process.cwd()\n\n const watchPaths = [\n path.resolve(projectRoot, seoPath),\n path.resolve(projectRoot, '..', seoPath),\n ].map((p) => path.normalize(p))\n\n watchPaths.forEach((watchPath) => {\n if (fs.existsSync(watchPath)) {\n server.watcher.add(watchPath)\n }\n })\n\n let reloadTimer: ReturnType<typeof setTimeout> | undefined\n server.watcher.on('change', (changedPath) => {\n if (!watchPaths.includes(path.normalize(changedPath))) return\n if (reloadTimer) clearTimeout(reloadTimer)\n reloadTimer = setTimeout(() => {\n if (debug) {\n console.log('[dcs-seo] seo.yaml changed, sending full-reload')\n }\n server.ws.send({ type: 'full-reload' })\n }, 100)\n })\n },\n }\n}\n","/**\n * DCS Editor Plugin for Vite\n *\n * Injects the editor bridge script into customer sites when running\n * in portal preview mode (inside the visual editor iframe).\n *\n * The bridge enables:\n * - Inline text editing via contenteditable\n * - Section hover highlights and AI ✨ buttons\n * - postMessage communication with the portal\n *\n * This plugin should only be active in development/preview mode.\n * It's safe to include in production builds — it does nothing unless\n * the page detects it's inside an iframe.\n *\n * @example\n * ```typescript\n * // vite.config.ts\n * import { dcsEditorPlugin } from '@duffcloudservices/cms/plugins'\n *\n * export default defineConfig({\n * plugins: [\n * dcsEditorPlugin()\n * ]\n * })\n * ```\n */\n\nimport type { Plugin } from 'vite'\n\nexport interface DcsEditorPluginOptions {\n /** Enable debug logging */\n debug?: boolean\n}\n\n/**\n * Vite plugin that injects the editor bridge script for portal preview integration.\n *\n * The bridge auto-initializes only when the page detects it's running inside an iframe,\n * so it's safe to include in all builds — it's a no-op in standalone browsing.\n *\n * Uses a virtual module (`/__dcs-editor-bridge.js`) served through Vite's dev server\n * so that bare module specifiers (like `@duffcloudservices/cms/editor`) are properly\n * resolved through Vite's module graph rather than hitting the browser's native ESM\n * resolver, which can't handle bare specifiers.\n */\nexport function dcsEditorPlugin(options: DcsEditorPluginOptions = {}): Plugin {\n const { debug = false } = options\n const VIRTUAL_PATH = '/__dcs-editor-bridge.js'\n const RIBBON_VIRTUAL_PATH = '/__dcs-preview-ribbon.js'\n\n // Captured during configResolved — used to gate HTML injection.\n let isDev = false\n let basePath = '/'\n let isPreview = false\n\n return {\n name: 'dcs-editor-bridge',\n\n // Preview only: stop Vite running an unreachable HMR WebSocket server.\n // Freshness comes from the cms content/seo plugins (fresh transformIndexHtml\n // re-read) + the portal's ?_hc hard reload, not HMR. NOTE: this alone does\n // NOT silence the browser — Vite still injects @vite/client and calls\n // connect(); the client-side stub in transformIndexHtml is what removes the\n // console errors. A normal local `vite dev` (no DCS_PREVIEW) keeps full HMR.\n config(_config, env) {\n if (env.command === 'serve' && process.env.DCS_PREVIEW === 'true') {\n return { server: { hmr: false } }\n }\n },\n\n configResolved(config) {\n isDev = config.command === 'serve'\n basePath = config.base ?? '/'\n isPreview = process.env.DCS_PREVIEW === 'true'\n },\n\n resolveId(id) {\n if (id === VIRTUAL_PATH || id === RIBBON_VIRTUAL_PATH) {\n return id\n }\n },\n\n load(id) {\n if (id === VIRTUAL_PATH) {\n return `\nimport { initEditorBridge } from '@duffcloudservices/cms/editor'\n// The bridge only activates inside an iframe (portal preview)\nif (window.parent !== window) {\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', () => setTimeout(initEditorBridge, 200))\n } else {\n setTimeout(initEditorBridge, 200)\n }\n}\n`\n }\n\n if (id === RIBBON_VIRTUAL_PATH) {\n return `\nimport { createApp } from 'vue'\nimport PreviewRibbon from '@duffcloudservices/cms/components'\n\nfunction mountRibbon() {\n // Create a detached mount point\n const el = document.createElement('div')\n el.id = 'dcs-preview-ribbon-root'\n document.body.appendChild(el)\n\n const app = createApp(PreviewRibbon)\n app.mount(el)\n}\n\nif (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', mountRibbon)\n} else {\n mountRibbon()\n}\n`\n }\n },\n\n /**\n * Only inject the editor bridge and ribbon scripts when:\n * 1. Running in dev mode (Vite dev server), AND\n * 2. The app is served at the root path (base === '/')\n *\n * These are virtual modules resolved via absolute paths (e.g.\n * `/__dcs-editor-bridge.js`). When base !== '/', the app is served at a\n * sub-path (e.g. /handyman-bryan/) and the absolute virtual paths are NOT\n * routed to the Vite dev server by the reverse proxy — they hit the main\n * DCS server instead and get redirected to portal.duffcloudservices.com\n * (no CORS headers), causing browser console errors.\n *\n * In production builds, App.vue imports and mounts PreviewRibbon\n * directly, so virtual script injection is always redundant anyway.\n */\n transformIndexHtml: {\n order: 'pre',\n handler(html) {\n if (!isDev || basePath !== '/') return html\n\n if (debug) {\n console.log('[dcs-editor] Injecting editor bridge + preview ribbon script tags')\n }\n\n // Inject both the editor bridge and preview ribbon scripts\n const editorTag = `<script type=\"module\" src=\"${VIRTUAL_PATH}\"></script>`\n const ribbonTag = `<script type=\"module\" src=\"${RIBBON_VIRTUAL_PATH}\"></script>`\n const bodyHtml = html.replace('</body>', `${editorTag}\\n${ribbonTag}\\n</body>`)\n\n if (!isPreview) return bodyHtml\n\n // Preview only: neutralise Vite's HMR WebSocket. Vite always injects\n // @vite/client and unconditionally calls transport.connect(); behind the\n // preview proxy chain there is no reachable HMR WS, so it logs\n // WebSocket connection to 'wss://<portal>/?token=…' failed\n // WebSocket connection to 'wss://localhost:<port>/?token=…' failed\n // [vite] failed to connect to websocket\n // server.hmr:false does NOT stop this (the client is still injected). A\n // classic <script> in <head> runs during parse, BEFORE the deferred\n // @vite/client module, so returning an inert socket for the 'vite-hmr'\n // subprotocol silences the attempt with zero effect on app/runtime\n // WebSockets. No-op outside preview / in production builds.\n const wsStub =\n `(function(){try{var N=window.WebSocket;if(!N)return;` +\n `function hmr(p){return p==='vite-hmr'||(Array.isArray(p)&&p.indexOf('vite-hmr')!==-1)}` +\n `function Inert(){this.readyState=0}` +\n `Inert.prototype.send=function(){};Inert.prototype.close=function(){};` +\n `Inert.prototype.addEventListener=function(){};Inert.prototype.removeEventListener=function(){};` +\n `var W=function(u,p){if(hmr(p))return new Inert();return new N(u,p)};` +\n `W.prototype=N.prototype;W.CONNECTING=N.CONNECTING;W.OPEN=N.OPEN;W.CLOSING=N.CLOSING;W.CLOSED=N.CLOSED;` +\n `window.WebSocket=W}catch(e){}})()`\n\n return {\n html: bodyHtml,\n tags: [{ tag: 'script', children: wsStub, injectTo: 'head-prepend' }],\n }\n },\n },\n }\n}\n","/**\n * DCS Preview Plugin for Vue\n *\n * Registers a supplied ribbon component as a global `DcsPreviewRibbon`\n * component. The ribbon handles its own visibility — it only renders on\n * `preview.duffcloudservices.com` and hides everywhere else (localhost,\n * production domains, and inside the visual page editor iframe).\n *\n * Why does the caller pass the component in? Because this file is compiled\n * by tsup (esbuild) which has no `.vue` SFC loader. Keeping the raw `.vue`\n * import out of the compiled plugins bundle avoids the build error while\n * still letting consumer code (which *does* run through Vite) resolve the\n * SFC at dev/build time.\n *\n * @example VitePress theme/index.ts\n * ```typescript\n * import { dcsPreviewPlugin } from '@duffcloudservices/cms/plugins'\n * import PreviewRibbon from '@duffcloudservices/cms/components'\n *\n * export default {\n * Layout,\n * enhanceApp({ app }) {\n * app.use(dcsPreviewPlugin(PreviewRibbon))\n * }\n * }\n * ```\n */\n\nimport { defineComponent, h, type App, type Component, type Plugin } from 'vue'\n\nexport interface DcsPreviewPluginOptions {\n /**\n * Override the version string displayed on the ribbon.\n * If omitted, the ribbon auto-detects from VITE_SITE_VERSION or the API.\n */\n version?: string | null\n}\n\n/**\n * Creates and returns the DCS Preview plugin.\n *\n * When installed, it registers the supplied ribbon component as a global\n * `DcsPreviewRibbon` component. Add `<DcsPreviewRibbon />` to your root\n * Layout, or use the `dcsEditorPlugin` Vite plugin which injects it via\n * `transformIndexHtml`.\n *\n * @param ribbonComponent - The PreviewRibbon SFC (imported by the consumer)\n * @param options - Optional configuration\n */\nexport function dcsPreviewPlugin(\n ribbonComponent: Component,\n options: DcsPreviewPluginOptions = {},\n): Plugin {\n const Wrapper = defineComponent({\n name: 'DcsPreviewRibbon',\n setup() {\n return () => h(ribbonComponent, { version: options.version ?? null })\n },\n })\n\n return {\n install(app: App) {\n app.component('DcsPreviewRibbon', Wrapper)\n\n if (options.version !== undefined) {\n app.provide('__dcs_preview_version__', options.version)\n }\n },\n }\n}\n","/**\n * DCS CDN Image Plugin for Vite\n *\n * Rewrites local static image references (e.g. `/images/staff/photo.jpg`)\n * to CDN URLs at build time using the `.dcs/cdn-image-map.json` mapping file\n * generated by the `image-migrate adopt` CLI command.\n *\n * For raster images with WebP variants, `<img>` elements are transformed into\n * responsive `<picture>` elements with `srcset` for optimised delivery.\n * SVGs receive a simple URL swap with no variant handling.\n *\n * **In development mode this plugin is a no-op** — local `/images/` paths\n * continue to work via Vite's static asset serving so hot-reload is unaffected.\n *\n * The plugin handles two in-pipeline replacement vectors:\n *\n * 1. **Module transform** (`transform` hook) — rewrites `<img>` tags and\n * string literals in Vue SFCs, TS, JS, CSS, MD, and HTML modules.\n * 2. **Chunk rendering** (`renderChunk` hook) — rewrites image paths in\n * final rendered JS/CSS chunks AFTER Vite's `define` substitution.\n * This catches data injected by `dcsContentPlugin` via `__DCS_CONTENT__`\n * (from `.dcs/content.yaml`) which bypasses the `transform` hook.\n *\n * A third vector — **post-build file processing** — is handled by the\n * companion `dcsCdnBuildEnd` hook, which must be registered separately in\n * VitePress config. VitePress generates HTML *after* both Vite builds\n * complete, so Vite plugin hooks (`closeBundle`, `transformIndexHtml`)\n * cannot catch SSR-rendered `<head>` tags or static `public/` files like\n * `service-worker.js`.\n *\n * @example\n * ```ts\n * // .vitepress/config.ts\n * import { dcsCdnImagePlugin, dcsCdnBuildEnd } from '@duffcloudservices/cms/plugins'\n *\n * export default defineConfig({\n * vite: {\n * plugins: [\n * dcsCdnImagePlugin()\n * ]\n * },\n * buildEnd: dcsCdnBuildEnd()\n * })\n * ```\n */\n\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport type { Plugin } from 'vite'\n\n// ────────────────────────────────────────────────────────────────────────────\n// Types\n// ────────────────────────────────────────────────────────────────────────────\n\nexport interface CdnImageMapVariant {\n suffix: string\n blobPath: string\n cdnUrl: string\n width: number\n height: number\n size: number\n}\n\nexport interface CdnImageMapEntry {\n localPath: string\n blobPath: string\n cdnUrl: string\n fileName: string\n contentType: string\n originalSize: number\n width?: number\n height?: number\n hash: string\n variants?: CdnImageMapVariant[]\n}\n\nexport interface CdnImageMap {\n generated: string\n site: string\n cdnBase: string\n images: CdnImageMapEntry[]\n}\n\nexport interface DcsCdnImagePluginOptions {\n /** Path to cdn-image-map.json relative to project root (default: '.dcs/cdn-image-map.json') */\n mapPath?: string\n\n /**\n * Patterns to match for replacement. Each must be a **leading-slash path prefix**\n * that appears in source code (e.g. `/images/`). The `localPath` field in the\n * mapping file is compared *without* a leading slash.\n *\n * Default: `['/images/']`\n */\n pathPrefixes?: string[]\n\n /**\n * Default `sizes` attribute for responsive `<picture>` elements.\n * Override per-context via the `data-sizes` attribute on the original `<img>`.\n *\n * Default: `'(max-width: 1024px) 100vw, 1024px'`\n */\n defaultSizes?: string\n\n /** Enable debug logging */\n debug?: boolean\n}\n\n// ────────────────────────────────────────────────────────────────────────────\n// Helpers\n// ────────────────────────────────────────────────────────────────────────────\n\nfunction escapeHtml(str: string): string {\n return str\n .replace(/&/g, '&amp;')\n .replace(/\"/g, '&quot;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n}\n\n/**\n * Build a responsive `<picture>` element for a raster image that has\n * WebP variants.\n */\nfunction buildPictureElement(\n entry: CdnImageMapEntry,\n alt: string,\n extraAttrs: string,\n sizes: string\n): string {\n const variants = entry.variants ?? []\n\n // Collect only the display-relevant variants (not thumb, not og)\n const displayVariants = variants.filter(\n (v) => v.suffix === '-sm' || v.suffix === '-md' || v.suffix === '-lg'\n )\n\n if (displayVariants.length === 0) {\n // No display variants — fall back to original CDN URL as plain <img>\n return `<img src=\"${escapeHtml(entry.cdnUrl)}\" alt=\"${escapeHtml(alt)}\"${extraAttrs} loading=\"lazy\" decoding=\"async\" />`\n }\n\n const srcset = displayVariants\n .map((v) => `${v.cdnUrl} ${v.width}w`)\n .join(', ')\n\n // Pick the -md variant as the default src, or fall through to original\n const mdVariant = variants.find((v) => v.suffix === '-md')\n const fallbackSrc = mdVariant ? mdVariant.cdnUrl : entry.cdnUrl\n\n return [\n '<picture>',\n ` <source srcset=\"${srcset}\" type=\"image/webp\" sizes=\"${escapeHtml(sizes)}\" />`,\n ` <img src=\"${escapeHtml(fallbackSrc)}\" alt=\"${escapeHtml(alt)}\"${extraAttrs} loading=\"lazy\" decoding=\"async\" />`,\n '</picture>',\n ].join('\\n')\n}\n\n// ────────────────────────────────────────────────────────────────────────────\n// Shared helpers\n// ────────────────────────────────────────────────────────────────────────────\n\n/**\n * Try to find and load the CDN image map from common locations.\n * VitePress nests docs under a subfolder, so we check parent dirs too.\n */\nfunction loadCdnImageMap(\n projectRoot: string,\n relativeMapPath: string,\n debug: boolean\n): Map<string, CdnImageMapEntry> | null {\n const possiblePaths = [\n path.resolve(projectRoot, relativeMapPath),\n path.resolve(projectRoot, '..', relativeMapPath),\n path.resolve(process.cwd(), relativeMapPath),\n ]\n\n for (const testPath of possiblePaths) {\n if (fs.existsSync(testPath)) {\n try {\n const raw = fs.readFileSync(testPath, 'utf8')\n const data: CdnImageMap = JSON.parse(raw)\n\n const map = new Map<string, CdnImageMapEntry>()\n for (const entry of data.images) {\n // Store both with and without leading slash for flexible matching\n map.set(entry.localPath, entry)\n if (!entry.localPath.startsWith('/')) {\n map.set('/' + entry.localPath, entry)\n }\n }\n\n if (debug) {\n console.log(`[dcs-cdn-image] Loaded ${data.images.length} entries from ${testPath}`)\n }\n return map\n } catch (error) {\n console.warn(`[dcs-cdn-image] Failed to parse ${testPath}:`, error)\n }\n }\n }\n\n if (debug) {\n console.log('[dcs-cdn-image] No cdn-image-map.json found at:')\n possiblePaths.forEach((p) => console.log(` - ${p}`))\n }\n return null\n}\n\n// ────────────────────────────────────────────────────────────────────────────\n// Vite Plugin\n// ────────────────────────────────────────────────────────────────────────────\n\n/**\n * Vite plugin that rewrites static `/images/` paths to CDN URLs at build time.\n */\nexport function dcsCdnImagePlugin(options: DcsCdnImagePluginOptions = {}): Plugin {\n const {\n mapPath = '.dcs/cdn-image-map.json',\n pathPrefixes = ['/images/'],\n defaultSizes = '(max-width: 1024px) 100vw, 1024px',\n debug = false,\n } = options\n\n // Lookup map built from the JSON file: key = localPath (no leading slash)\n let imageMap: Map<string, CdnImageMapEntry> | null = null\n let isProduction = false\n\n /**\n * Check whether a source code string contains any of the path prefixes\n * we care about. Quick bail-out for files that don't reference images.\n */\n function hasImageReferences(code: string): boolean {\n return pathPrefixes.some((prefix) => code.includes(prefix))\n }\n\n /**\n * Replace image path references in any string value with CDN URLs.\n * Used for code transforms and renderChunk post-processing.\n */\n function replaceImagePaths(str: string): string {\n if (!imageMap || imageMap.size === 0) return str\n let result = str\n for (const prefix of pathPrefixes) {\n // Global replace: matches prefix followed by a relative path bounded\n // by quotes, parens, or whitespace. Allows spaces in filenames.\n const regex = new RegExp(\n `([\"'\\`(])${escapeRegex(prefix)}([^\"'\\`()]+)`,\n 'g'\n )\n result = result.replace(regex, (match, quote, relPath) => {\n const localPath = prefix.replace(/^\\//, '') + relPath\n const entry = imageMap!.get(localPath) || imageMap!.get('/' + localPath)\n if (!entry) return match\n return `${quote}${entry.cdnUrl}`\n })\n }\n return result\n }\n\n /**\n * Replace standalone URL references in JS/TS string literals and Vue template\n * attributes. This handles patterns like:\n * src=\"/images/foo.jpg\"\n * { src: '/images/foo.jpg' }\n * url(/images/foo.svg)\n *\n * For `<img>` tags with raster images that have variants, the entire tag is\n * replaced with a `<picture>` element.\n */\n function transformCode(code: string): string {\n if (!imageMap || imageMap.size === 0) return code\n\n // ── Pass 1: Replace <img> tags that reference mapped raster images ──────\n // Matches: <img ... src=\"/images/foo.jpg\" ... /> or <img ... src=\"/images/foo.jpg\" ... >\n const imgTagRegex = /<img\\b([^>]*?)src=[\"'](\\/(images\\/[^\"']+))[\"']([^>]*?)\\/?>/gi\n code = code.replace(imgTagRegex, (_match, beforeSrc, _srcWithSlash, localPath, afterSrc) => {\n const entry = imageMap!.get(localPath) || imageMap!.get('/' + localPath)\n if (!entry) return _match\n\n // Extract alt from the existing attributes\n const altMatch = (beforeSrc + afterSrc).match(/alt=[\"']([^\"']*)[\"']/)\n const alt = altMatch ? altMatch[1] : ''\n\n // Collect other attributes (not src, alt, loading, decoding — we set those)\n const otherAttrs = (beforeSrc + afterSrc)\n .replace(/\\balt=[\"'][^\"']*[\"']/gi, '')\n .replace(/\\bloading=[\"'][^\"']*[\"']/gi, '')\n .replace(/\\bdecoding=[\"'][^\"']*[\"']/gi, '')\n .trim()\n\n const extraAttrs = otherAttrs ? ' ' + otherAttrs : ''\n\n // Extract custom sizes if specified\n const sizesMatch = (beforeSrc + afterSrc).match(/data-sizes=[\"']([^\"']*)[\"']/)\n const sizes = sizesMatch ? sizesMatch[1] : defaultSizes\n\n // SVGs and images without variants → simple URL swap <img>\n if (!entry.variants || entry.variants.length === 0) {\n return `<img src=\"${escapeHtml(entry.cdnUrl)}\" alt=\"${escapeHtml(alt)}\"${extraAttrs} loading=\"lazy\" decoding=\"async\" />`\n }\n\n // Raster with variants → <picture>\n return buildPictureElement(entry, alt, extraAttrs, sizes)\n })\n\n // ── Pass 2: Replace remaining string literal / CSS url() references ─────\n code = replaceImagePaths(code)\n\n return code\n }\n\n return {\n name: 'dcs-cdn-image',\n enforce: 'pre',\n\n configResolved(config) {\n isProduction = config.command === 'build'\n if (!isProduction) {\n if (debug) {\n console.log('[dcs-cdn-image] Dev mode — plugin disabled (local images served by Vite)')\n }\n return\n }\n imageMap = loadCdnImageMap(config.root, mapPath, debug)\n },\n\n transform(code, id) {\n // Only run in production builds\n if (!isProduction || !imageMap) return\n\n // Only process relevant file types\n if (!/\\.(vue|ts|tsx|js|jsx|css|scss|md|html)(\\?.*)?$/.test(id)) return\n\n // Quick bail — skip files with no image path references\n if (!hasImageReferences(code)) return\n\n const transformed = transformCode(code)\n if (transformed !== code) {\n return { code: transformed, map: null }\n }\n },\n\n /**\n * Replace image paths in final rendered JS/CSS chunks.\n *\n * This fires AFTER Vite's `define` substitution, catching paths that were\n * injected via `define` values (e.g. `__DCS_CONTENT__` set by\n * `dcsContentPlugin` from `.dcs/content.yaml`). Those paths bypass the\n * `transform` hook because `define` replacement happens at bundle time.\n */\n renderChunk(code, _chunk) {\n if (!isProduction || !imageMap) return null\n if (!hasImageReferences(code)) return null\n\n const replaced = replaceImagePaths(code)\n if (replaced !== code) {\n if (debug) {\n console.log(`[dcs-cdn-image] renderChunk: rewrote image paths in ${_chunk.fileName}`)\n }\n return { code: replaced, map: null }\n }\n return null\n },\n\n /**\n * Transform HTML output to catch references injected outside the module\n * pipeline — e.g. VitePress `head` config tags (favicons, OG images).\n *\n * Note: In VitePress, this hook fires for the `index.html` template but\n * NOT for SSR-rendered per-page HTML. Use `dcsCdnBuildEnd` for full\n * coverage of generated HTML files.\n */\n transformIndexHtml(html) {\n if (!isProduction || !imageMap) return html\n if (!hasImageReferences(html)) return html\n\n // Replace href/src/content attributes that reference mapped images\n for (const prefix of pathPrefixes) {\n const attrRegex = new RegExp(\n `((?:href|src|content)=[\"'])${escapeRegex(prefix)}([^\"']+)([\"'])`,\n 'gi'\n )\n html = html.replace(attrRegex, (match, pre, relPath, post) => {\n const localPath = prefix.replace(/^\\//, '') + relPath\n const entry = imageMap!.get(localPath) || imageMap!.get('/' + localPath)\n if (!entry) return match\n return `${pre}${entry.cdnUrl}${post}`\n })\n }\n\n return html\n },\n }\n}\n\n/**\n * Escape a string for use in a RegExp.\n */\nfunction escapeRegex(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\n// ────────────────────────────────────────────────────────────────────────────\n// VitePress buildEnd hook\n// ────────────────────────────────────────────────────────────────────────────\n\nexport interface DcsCdnBuildEndOptions {\n /** Path to cdn-image-map.json relative to project root (default: '.dcs/cdn-image-map.json') */\n mapPath?: string\n\n /**\n * Patterns to match for replacement.\n * Default: `['/images/']`\n */\n pathPrefixes?: string[]\n\n /** Enable debug logging */\n debug?: boolean\n\n /**\n * File extensions to process in the output directory.\n * Default: `['.html', '.js']`\n */\n extensions?: string[]\n}\n\n/**\n * VitePress `buildEnd` hook factory that post-processes generated HTML and\n * static files in the output directory to replace remaining `/images/` paths\n * with CDN URLs.\n *\n * VitePress generates HTML **after** both Vite builds complete, so Vite\n * plugin hooks (`closeBundle`, `transformIndexHtml`) cannot catch\n * SSR-rendered `<head>` tags (favicons, OG images). This hook runs after all\n * HTML files are written to disk.\n *\n * Also rewrites static files (e.g. `service-worker.js`) copied from\n * `public/` that are not part of Vite's module pipeline.\n *\n * @example\n * ```ts\n * // .vitepress/config.ts\n * import { dcsCdnBuildEnd } from '@duffcloudservices/cms/plugins'\n *\n * export default defineConfig({\n * buildEnd: dcsCdnBuildEnd({ debug: true })\n * })\n * ```\n */\nexport function dcsCdnBuildEnd(options: DcsCdnBuildEndOptions = {}) {\n const {\n mapPath = '.dcs/cdn-image-map.json',\n pathPrefixes = ['/images/'],\n debug = false,\n extensions = ['.html', '.js'],\n } = options\n\n return async (siteConfig: { root: string; outDir: string }) => {\n const imageMap = loadCdnImageMap(siteConfig.root, mapPath, debug)\n if (!imageMap) {\n if (debug) {\n console.log('[dcs-cdn-image] buildEnd: no image map found')\n }\n return\n }\n\n const outDir = siteConfig.outDir\n if (!fs.existsSync(outDir)) return\n\n let filesProcessed = 0\n let refsReplaced = 0\n\n function walkDir(dir: string) {\n const entries = fs.readdirSync(dir, { withFileTypes: true })\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name)\n if (entry.isDirectory()) {\n walkDir(fullPath)\n } else if (extensions.some((ext) => entry.name.endsWith(ext))) {\n processFile(fullPath)\n }\n }\n }\n\n function processFile(filePath: string) {\n let content = fs.readFileSync(filePath, 'utf8')\n if (!pathPrefixes.some((p) => content.includes(p))) return\n\n let changed = false\n\n if (filePath.endsWith('.html')) {\n // HTML: replace href/src/content attribute values\n for (const prefix of pathPrefixes) {\n const attrRegex = new RegExp(\n `((?:href|src|content)=[\"'])${escapeRegex(prefix)}([^\"']+)([\"'])`,\n 'gi'\n )\n content = content.replace(attrRegex, (match, pre, relPath, post) => {\n const localPath = prefix.replace(/^\\//, '') + relPath\n const mapEntry = imageMap!.get(localPath) || imageMap!.get('/' + localPath)\n if (!mapEntry) return match\n changed = true\n refsReplaced++\n return `${pre}${mapEntry.cdnUrl}${post}`\n })\n }\n } else {\n // JS/other: replace quoted string paths\n for (const prefix of pathPrefixes) {\n const regex = new RegExp(\n `([\"'\\`(])${escapeRegex(prefix)}([^\"'\\`()]+)`,\n 'g'\n )\n content = content.replace(regex, (match, quote, relPath) => {\n const localPath = prefix.replace(/^\\//, '') + relPath\n const entry = imageMap!.get(localPath) || imageMap!.get('/' + localPath)\n if (!entry) return match\n changed = true\n refsReplaced++\n return `${quote}${entry.cdnUrl}`\n })\n }\n }\n\n if (changed) {\n fs.writeFileSync(filePath, content, 'utf8')\n filesProcessed++\n }\n }\n\n walkDir(outDir)\n\n if (debug) {\n console.log(\n `[dcs-cdn-image] buildEnd: post-processed ${filesProcessed} files, replaced ${refsReplaced} references`\n )\n }\n }\n}","/**\n * markdown-it plugin that transforms standard `![alt](url)` image syntax\n * into responsive `<picture>` elements when the URL matches the DCS CDN\n * asset pattern.\n *\n * Non-CDN images are rendered with the default image renderer (plain `<img>`).\n *\n * @example\n * ```ts\n * // .vitepress/config.ts\n * import { responsiveImagePlugin } from '@duffcloudservices/cms/plugins'\n *\n * export default defineConfig({\n * markdown: {\n * config: (md) => {\n * md.use(responsiveImagePlugin)\n * },\n * },\n * })\n * ```\n *\n * Input markdown:\n * ```md\n * ![Physical therapy session](https://files.duffcloudservices.com/kept/assets/blog/abc-123.jpg)\n * ```\n *\n * Rendered HTML:\n * ```html\n * <picture>\n * <source srcset=\"...abc-123-sm.webp 640w, ...abc-123-md.webp 1024w, ...abc-123-lg.webp 1920w\"\n * type=\"image/webp\"\n * sizes=\"(max-width: 1024px) 100vw, 1024px\" />\n * <img src=\"...abc-123-md.webp\" alt=\"Physical therapy session\" loading=\"lazy\" decoding=\"async\" />\n * </picture>\n * ```\n */\n\nimport type MarkdownIt from 'markdown-it'\n\n/**\n * Matches DCS CDN asset URLs: base path / UUID . extension.\n *\n * Aligned with `@duffcloudservices/cms-core` `responsive-image.ts`: the\n * `(?:content\\/)?` group covers the content-container shape\n * `https://files.duffcloudservices.com/content/{slug}/assets/...` in addition\n * to the branding-container shape `.../{slug}/assets/...`. The group is\n * non-capturing, so the captured base path / UUID / extension are unchanged.\n */\nconst CDN_PATTERN = /^(https?:\\/\\/files\\.[^/]+\\/(?:content\\/)?[^/]+\\/assets\\/(?:[^/]+\\/)*)([a-f0-9-]+)\\.(\\w+)$/\n\n/**\n * Escapes HTML special characters for safe attribute embedding.\n * Falls back to a simple replace chain when `md.utils.escapeHtml` is unavailable.\n */\nfunction escapeHtml(str: string): string {\n return str\n .replace(/&/g, '&amp;')\n .replace(/\"/g, '&quot;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n}\n\nexport function responsiveImagePlugin(md: MarkdownIt): void {\n const defaultImageRenderer = md.renderer.rules.image\n\n md.renderer.rules.image = (tokens, idx, options, env, self) => {\n const token = tokens[idx]\n const src = token.attrGet('src') ?? ''\n const alt = token.content ?? ''\n\n const match = src.match(CDN_PATTERN)\n if (!match) {\n // Not a CDN image — render normally\n if (defaultImageRenderer) {\n return defaultImageRenderer(tokens, idx, options, env, self)\n }\n return self.renderToken(tokens, idx, options)\n }\n\n const [, basePath, uuid] = match\n\n const srcset = [\n `${basePath}${uuid}-sm.webp 640w`,\n `${basePath}${uuid}-md.webp 1024w`,\n `${basePath}${uuid}-lg.webp 1920w`,\n ].join(', ')\n\n const escapedAlt = escapeHtml(alt)\n\n // Self-heal: this plugin emits a STATIC HTML string at build time (no Vue\n // runtime), so the fallback must be an inline onerror. A fit-variant\n // (`-md`/`-lg`) may legitimately be absent (internal/imaging variants.go\n // skips variants by DIMENSION). On the first error, swap the `<img>` to the\n // ORIGINAL url AND strip the sibling `<source>` elements — a `<picture>`\n // does NOT re-resolve after a `<source>` 404s, so the variant set must be\n // removed for the original to display. (`this.onerror=null` prevents loops.)\n const escapedOriginal = escapeHtml(src)\n const onError =\n `this.onerror=null;this.src='${escapedOriginal}';` +\n `this.closest('picture')?.querySelectorAll('source').forEach(s=>s.remove())`\n\n return [\n '<picture>',\n ` <source srcset=\"${srcset}\" type=\"image/webp\" sizes=\"(max-width: 1024px) 100vw, 1024px\" />`,\n ` <img src=\"${basePath}${uuid}-md.webp\" alt=\"${escapedAlt}\" loading=\"lazy\" decoding=\"async\" onerror=\"${onError}\" />`,\n '</picture>',\n ].join('\\n')\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duffcloudservices/cms",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Vue 3 composables and Vite plugins for DCS CMS integration",
5
5
  "type": "module",
6
6
  "exports": {