@duffcloudservices/cms 0.13.15 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-P6HQW635.js → chunk-56RSSOAM.js} +3 -3
- package/dist/{chunk-P6HQW635.js.map → chunk-56RSSOAM.js.map} +1 -1
- package/dist/{chunk-JWXI5HAZ.js → chunk-CJATCOZJ.js} +198 -33
- package/dist/chunk-CJATCOZJ.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/{installSeoHead-DPVmX-eY.d.ts → installSeoHead-CcNfcxNF.d.ts} +1 -1
- package/dist/plugins/index.d.ts +160 -4
- package/dist/plugins/index.js +644 -81
- package/dist/plugins/index.js.map +1 -1
- package/dist/seo/index.d.ts +4 -4
- package/dist/seo/index.js +2 -2
- package/dist/{vitepressTransform-BJrpGbVT.d.ts → vitepressTransform-CQXBpYEC.d.ts} +198 -20
- package/package.json +1 -1
- package/dist/chunk-JWXI5HAZ.js.map +0 -1
package/dist/plugins/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { buildSitemapXml, isHandAuthoredRobotsAcceptable, buildRobotsTxt, buildLlmsTxt, routeExclusionReason, breadcrumbTrailFromRoute, findReviewItemsForPage, findBusinessLicense, buildHeadTags, spliceHeadHtml, routeToOutputFile, loadPagesManifest, hoistCharsetMeta, checkCharsetBudget, findPostalAddressGaps, formatPostalAddressGapReport, isBodyPrerenderEnabled, resolveHonestyMode, assertHeadHonestyExecuted, findHeadHonestyViolations, assertHeadHonesty, isRouteEmitted, findDuplicateNormalizedPaths, formatDuplicateNormalizedPaths, prerenderBodies, CharsetBudgetError, formatCharsetHeadroomWarning, dedupeUrls, collectEmittedUrlsFromFiles, classifyUrl, auditSameOriginAssets, checkRemoteAssets, auditCheckedTotal, EmittedUrlNotRunError, formatEmittedUrlAudit, formatEmittedUrlReport, EmittedUrlError } from '../chunk-
|
|
2
|
-
export { buildVitePressSeoHead, createSeoTransformPageData, defaultRelativePathToRoute } from '../chunk-
|
|
3
|
-
import
|
|
1
|
+
import { buildSitemapXml, isHandAuthoredRobotsAcceptable, findAiTrainingRobotsConflicts, RobotsAiTrainingConflictError, appendAiTrainingOptOut, buildRobotsTxt, buildLlmsTxt, routeExclusionReason, breadcrumbTrailFromRoute, findReviewItemsForPage, findBusinessLicense, buildHeadTags, spliceHeadHtml, routeToOutputFile, loadPagesManifest, hoistCharsetMeta, checkCharsetBudget, findPostalAddressGaps, formatPostalAddressGapReport, isBodyPrerenderEnabled, resolveHonestyMode, assertHeadHonestyExecuted, findHeadHonestyViolations, assertHeadHonesty, isRouteEmitted, findDuplicateNormalizedPaths, formatDuplicateNormalizedPaths, prerenderBodies, CharsetBudgetError, formatCharsetHeadroomWarning, dedupeUrls, collectEmittedUrlsFromFiles, classifyUrl, auditSameOriginAssets, checkRemoteAssets, auditCheckedTotal, EmittedUrlNotRunError, formatEmittedUrlAudit, formatEmittedUrlReport, EmittedUrlError } from '../chunk-CJATCOZJ.js';
|
|
2
|
+
export { buildVitePressSeoHead, createSeoTransformPageData, defaultRelativePathToRoute } from '../chunk-CJATCOZJ.js';
|
|
3
|
+
import fs8 from 'fs';
|
|
4
4
|
import path7 from 'path';
|
|
5
|
-
import
|
|
5
|
+
import yaml5 from 'js-yaml';
|
|
6
6
|
import crypto from 'crypto';
|
|
7
7
|
import http from 'http';
|
|
8
|
+
import { execFileSync } from 'child_process';
|
|
9
|
+
import { builtinModules } from 'module';
|
|
8
10
|
import { defineComponent, h } from 'vue';
|
|
9
11
|
import { isVectorImageUrl } from '@duffcloudservices/cms-core';
|
|
10
12
|
|
|
@@ -16,7 +18,7 @@ function dcsSearchPaths(projectRoot, relPath) {
|
|
|
16
18
|
];
|
|
17
19
|
}
|
|
18
20
|
function resolveDcsFile(projectRoot, relPath) {
|
|
19
|
-
return dcsSearchPaths(projectRoot, relPath).find((p) =>
|
|
21
|
+
return dcsSearchPaths(projectRoot, relPath).find((p) => fs8.existsSync(p));
|
|
20
22
|
}
|
|
21
23
|
function readDcsYamlFresh(projectRoot, relPath, label, debug = false) {
|
|
22
24
|
const found = resolveDcsFile(projectRoot, relPath);
|
|
@@ -25,7 +27,7 @@ function readDcsYamlFresh(projectRoot, relPath, label, debug = false) {
|
|
|
25
27
|
return void 0;
|
|
26
28
|
}
|
|
27
29
|
try {
|
|
28
|
-
return
|
|
30
|
+
return yaml5.load(fs8.readFileSync(found, "utf8"));
|
|
29
31
|
} catch (error) {
|
|
30
32
|
console.warn(`[${label}] serve: failed to parse ${relPath}:`, error);
|
|
31
33
|
return void 0;
|
|
@@ -103,8 +105,8 @@ function readSiteYaml(projectRoot) {
|
|
|
103
105
|
];
|
|
104
106
|
for (const candidate of candidates) {
|
|
105
107
|
try {
|
|
106
|
-
if (!
|
|
107
|
-
const parsed =
|
|
108
|
+
if (!fs8.existsSync(candidate)) continue;
|
|
109
|
+
const parsed = yaml5.load(fs8.readFileSync(candidate, "utf8"));
|
|
108
110
|
const slug = parsed && typeof parsed.site_slug === "string" ? parsed.site_slug.trim() : "";
|
|
109
111
|
if (parsed && slug) return { slug, fields: parsed };
|
|
110
112
|
} catch {
|
|
@@ -172,7 +174,7 @@ function dcsContentPlugin(options = {}) {
|
|
|
172
174
|
];
|
|
173
175
|
let foundPath;
|
|
174
176
|
for (const testPath of possiblePaths) {
|
|
175
|
-
if (
|
|
177
|
+
if (fs8.existsSync(testPath)) {
|
|
176
178
|
foundPath = testPath;
|
|
177
179
|
break;
|
|
178
180
|
}
|
|
@@ -191,8 +193,8 @@ function dcsContentPlugin(options = {}) {
|
|
|
191
193
|
};
|
|
192
194
|
}
|
|
193
195
|
try {
|
|
194
|
-
const fileContent =
|
|
195
|
-
const content =
|
|
196
|
+
const fileContent = fs8.readFileSync(foundPath, "utf8");
|
|
197
|
+
const content = yaml5.load(fileContent);
|
|
196
198
|
if (debug) {
|
|
197
199
|
console.log(`[dcs-content] Loaded ${foundPath}`);
|
|
198
200
|
console.log(`[dcs-content] Version: ${content.version}`);
|
|
@@ -286,7 +288,7 @@ function dcsContentPlugin(options = {}) {
|
|
|
286
288
|
path7.resolve(projectRoot, "..", contentPath)
|
|
287
289
|
].map((p) => path7.normalize(p));
|
|
288
290
|
watchPaths.forEach((watchPath) => {
|
|
289
|
-
if (
|
|
291
|
+
if (fs8.existsSync(watchPath)) {
|
|
290
292
|
server.watcher.add(watchPath);
|
|
291
293
|
}
|
|
292
294
|
});
|
|
@@ -338,15 +340,15 @@ function dcsResponsiveImageLint(options = {}) {
|
|
|
338
340
|
return async (siteConfig) => {
|
|
339
341
|
const report = { filesScanned: 0, violations: [] };
|
|
340
342
|
const outDir = siteConfig.outDir;
|
|
341
|
-
if (!outDir || !
|
|
343
|
+
if (!outDir || !fs8.existsSync(outDir)) return report;
|
|
342
344
|
const walk = (dir) => {
|
|
343
|
-
for (const entry of
|
|
345
|
+
for (const entry of fs8.readdirSync(dir, { withFileTypes: true })) {
|
|
344
346
|
const full = path7.join(dir, entry.name);
|
|
345
347
|
if (entry.isDirectory()) {
|
|
346
348
|
walk(full);
|
|
347
349
|
} else if (extensions.some((ext) => entry.name.endsWith(ext))) {
|
|
348
350
|
report.filesScanned++;
|
|
349
|
-
const html =
|
|
351
|
+
const html = fs8.readFileSync(full, "utf8");
|
|
350
352
|
if (!html.includes("/assets/")) continue;
|
|
351
353
|
const rel = path7.relative(outDir, full);
|
|
352
354
|
for (const v of findFullSizeCdnImages(html)) {
|
|
@@ -416,7 +418,7 @@ function resolveManifestPath(options) {
|
|
|
416
418
|
function realpathNearest(p) {
|
|
417
419
|
let cur = path7.resolve(p);
|
|
418
420
|
const tail = [];
|
|
419
|
-
while (!
|
|
421
|
+
while (!fs8.existsSync(cur)) {
|
|
420
422
|
const parent = path7.dirname(cur);
|
|
421
423
|
if (parent === cur) break;
|
|
422
424
|
tail.unshift(path7.basename(cur));
|
|
@@ -424,7 +426,7 @@ function realpathNearest(p) {
|
|
|
424
426
|
}
|
|
425
427
|
let real = cur;
|
|
426
428
|
try {
|
|
427
|
-
real =
|
|
429
|
+
real = fs8.realpathSync.native(cur);
|
|
428
430
|
} catch {
|
|
429
431
|
}
|
|
430
432
|
return path7.join(real, ...tail);
|
|
@@ -441,21 +443,21 @@ function clearDirIndexManifest(manifestPath = process.env[DIR_INDEX_MANIFEST_ENV
|
|
|
441
443
|
if (!manifestPath) return void 0;
|
|
442
444
|
const file = path7.resolve(manifestPath);
|
|
443
445
|
try {
|
|
444
|
-
const st =
|
|
446
|
+
const st = fs8.lstatSync(file);
|
|
445
447
|
if (!st.isFile() && !st.isSymbolicLink()) return void 0;
|
|
446
448
|
} catch {
|
|
447
449
|
return void 0;
|
|
448
450
|
}
|
|
449
|
-
|
|
451
|
+
fs8.unlinkSync(file);
|
|
450
452
|
return file;
|
|
451
453
|
}
|
|
452
454
|
var sha256 = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex");
|
|
453
455
|
function writeManifest(file, manifest) {
|
|
454
|
-
|
|
456
|
+
fs8.mkdirSync(path7.dirname(file), { recursive: true });
|
|
455
457
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
456
|
-
|
|
458
|
+
fs8.writeFileSync(tmp, `${JSON.stringify(manifest, null, 2)}
|
|
457
459
|
`);
|
|
458
|
-
|
|
460
|
+
fs8.renameSync(tmp, file);
|
|
459
461
|
}
|
|
460
462
|
function emitDirectoryIndexes(siteConfig, options = {}) {
|
|
461
463
|
const outDir = siteConfig.outDir;
|
|
@@ -466,7 +468,7 @@ function emitDirectoryIndexes(siteConfig, options = {}) {
|
|
|
466
468
|
`[dcs-dir-index] ${DIR_INDEX_MANIFEST_ENV}=${manifestPath} is inside outDir ${outDir}; the manifest must not ship with the site. Point it outside the build output.`
|
|
467
469
|
);
|
|
468
470
|
}
|
|
469
|
-
|
|
471
|
+
fs8.rmSync(manifestPath, { force: true });
|
|
470
472
|
}
|
|
471
473
|
if (siteConfig.cleanUrls !== true) {
|
|
472
474
|
if (!manifestPath) return { written: 0, identical: 0, twins: [] };
|
|
@@ -484,13 +486,13 @@ function emitDirectoryIndexes(siteConfig, options = {}) {
|
|
|
484
486
|
const dstRel = `${stem}/index.html`;
|
|
485
487
|
const src = path7.join(outDir, srcRel);
|
|
486
488
|
const dst = path7.join(outDir, dstRel);
|
|
487
|
-
if (!
|
|
489
|
+
if (!fs8.existsSync(src) || !fs8.statSync(src).isFile()) {
|
|
488
490
|
missing.push(`${page} -> ${srcRel}`);
|
|
489
491
|
continue;
|
|
490
492
|
}
|
|
491
|
-
const bytes =
|
|
492
|
-
if (
|
|
493
|
-
const existing =
|
|
493
|
+
const bytes = fs8.readFileSync(src);
|
|
494
|
+
if (fs8.existsSync(dst)) {
|
|
495
|
+
const existing = fs8.statSync(dst).isFile() ? fs8.readFileSync(dst) : null;
|
|
494
496
|
if (existing && existing.equals(bytes)) {
|
|
495
497
|
identicalRel.push(dstRel);
|
|
496
498
|
entries.push({ twin: dstRel, source: srcRel, sha256: sha256(bytes) });
|
|
@@ -519,8 +521,8 @@ function emitDirectoryIndexes(siteConfig, options = {}) {
|
|
|
519
521
|
${problems.join("\n")}`);
|
|
520
522
|
}
|
|
521
523
|
for (const t of toWrite) {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
+
fs8.mkdirSync(path7.dirname(t.dst), { recursive: true });
|
|
525
|
+
fs8.writeFileSync(t.dst, t.bytes);
|
|
524
526
|
entries.push({ twin: t.rel, source: t.srcRel, sha256: sha256(t.bytes) });
|
|
525
527
|
}
|
|
526
528
|
const twins = [...toWrite.map((t) => t.rel), ...identicalRel].sort();
|
|
@@ -625,7 +627,7 @@ async function startStaticServer(outDir) {
|
|
|
625
627
|
}
|
|
626
628
|
let filePath = resolved;
|
|
627
629
|
try {
|
|
628
|
-
const stat =
|
|
630
|
+
const stat = fs8.statSync(filePath);
|
|
629
631
|
if (stat.isDirectory()) filePath = path7.join(filePath, "index.html");
|
|
630
632
|
} catch {
|
|
631
633
|
if (path7.extname(pathname)) {
|
|
@@ -635,7 +637,7 @@ async function startStaticServer(outDir) {
|
|
|
635
637
|
}
|
|
636
638
|
filePath = path7.join(outDir, "index.html");
|
|
637
639
|
}
|
|
638
|
-
|
|
640
|
+
fs8.readFile(filePath, (err, buf) => {
|
|
639
641
|
if (err) {
|
|
640
642
|
res.writeHead(404);
|
|
641
643
|
res.end();
|
|
@@ -794,6 +796,551 @@ async function createPlaywrightRenderer(options) {
|
|
|
794
796
|
}
|
|
795
797
|
};
|
|
796
798
|
}
|
|
799
|
+
var IDENTICAL_LASTMOD_ROUTE_LIMIT = 3;
|
|
800
|
+
var CONTENT_WALK_LIMIT = 300;
|
|
801
|
+
var DEFAULT_LASTMOD_EXCLUDE = [
|
|
802
|
+
// App shell, routing, entry points
|
|
803
|
+
"App.vue",
|
|
804
|
+
"main.{ts,js,mts,mjs}",
|
|
805
|
+
"**/router/**",
|
|
806
|
+
// Layouts (VitePress theme Layout.vue, any layouts/ dir) and theme/config shell
|
|
807
|
+
"Layout.vue",
|
|
808
|
+
"**/layouts/**",
|
|
809
|
+
"**/.vitepress/config.*",
|
|
810
|
+
"**/.vitepress/theme/index.*",
|
|
811
|
+
// Site-wide header / footer / nav / banner chrome
|
|
812
|
+
"{App,Site,Main,Global,Top,Page,The,Mobile,}{Header,Footer,Nav,NavBar,Navbar,Navigation,NavMenu,Banner,AnnouncementBanner}.vue",
|
|
813
|
+
// Non-content code
|
|
814
|
+
"**/composables/**",
|
|
815
|
+
"**/stores/**",
|
|
816
|
+
"**/lib/**",
|
|
817
|
+
"**/utils/**",
|
|
818
|
+
"**/components/ui/**",
|
|
819
|
+
// Styles and tests
|
|
820
|
+
"*.{css,scss,sass,less,styl,pcss,postcss}",
|
|
821
|
+
"*.{test,spec}.*",
|
|
822
|
+
"**/__tests__/**",
|
|
823
|
+
// DCS metadata: seo/pages/site are head + registry, content is dated per route
|
|
824
|
+
"**/.dcs/{seo,pages,site,content}.yaml",
|
|
825
|
+
"**/node_modules/**"
|
|
826
|
+
];
|
|
827
|
+
var defaultGit = (args, cwd) => execFileSync("git", args, {
|
|
828
|
+
cwd,
|
|
829
|
+
encoding: "utf8",
|
|
830
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
831
|
+
timeout: 6e4,
|
|
832
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
833
|
+
windowsHide: true
|
|
834
|
+
});
|
|
835
|
+
function toPascal(value) {
|
|
836
|
+
return value.split(/[^A-Za-z0-9]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
837
|
+
}
|
|
838
|
+
function defaultRouteSourceCandidates(route) {
|
|
839
|
+
const rel = route.path.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
840
|
+
const isHome = rel === "";
|
|
841
|
+
const names = /* @__PURE__ */ new Set();
|
|
842
|
+
const slugName = toPascal(route.slug || "");
|
|
843
|
+
if (slugName) names.add(slugName);
|
|
844
|
+
const lastSegment = rel.split("/").pop() ?? "";
|
|
845
|
+
const segName = toPascal(lastSegment);
|
|
846
|
+
if (segName) names.add(segName);
|
|
847
|
+
if (isHome) names.add("Home");
|
|
848
|
+
const out = [];
|
|
849
|
+
for (const name of names) {
|
|
850
|
+
out.push(`src/views/${name}View.vue`, `src/views/${name}.vue`, `src/pages/${name}.vue`, `src/pages/${name}View.vue`);
|
|
851
|
+
}
|
|
852
|
+
if (isHome) {
|
|
853
|
+
out.push("index.md", "docs/index.md");
|
|
854
|
+
} else {
|
|
855
|
+
out.push(`${rel}.md`, `${rel}/index.md`, `docs/${rel}.md`, `docs/${rel}/index.md`);
|
|
856
|
+
}
|
|
857
|
+
return out;
|
|
858
|
+
}
|
|
859
|
+
function isFile(abs) {
|
|
860
|
+
try {
|
|
861
|
+
return fs8.statSync(abs).isFile();
|
|
862
|
+
} catch {
|
|
863
|
+
return false;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
function routeEntries(route, projectRoot, sourcesForRoute) {
|
|
867
|
+
const custom = sourcesForRoute?.(route);
|
|
868
|
+
if (custom) {
|
|
869
|
+
return [...new Set(custom.filter((c) => typeof c === "string" && c).map((c) => path7.resolve(projectRoot, c)))].filter(isFile);
|
|
870
|
+
}
|
|
871
|
+
const first = defaultRouteSourceCandidates(route).map((c) => path7.resolve(projectRoot, c)).find(isFile);
|
|
872
|
+
return first ? [first] : [];
|
|
873
|
+
}
|
|
874
|
+
function escapeRe(s) {
|
|
875
|
+
return s.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
876
|
+
}
|
|
877
|
+
function lastmodGlobToRegExp(glob) {
|
|
878
|
+
const convert = (g) => {
|
|
879
|
+
let re = "";
|
|
880
|
+
for (let i = 0; i < g.length; i++) {
|
|
881
|
+
const c = g[i];
|
|
882
|
+
if (c === "*") {
|
|
883
|
+
if (g[i + 1] === "*") {
|
|
884
|
+
if (g[i + 2] === "/") {
|
|
885
|
+
re += "(?:.*/)?";
|
|
886
|
+
i += 2;
|
|
887
|
+
} else {
|
|
888
|
+
re += ".*";
|
|
889
|
+
i += 1;
|
|
890
|
+
}
|
|
891
|
+
} else {
|
|
892
|
+
re += "[^/]*";
|
|
893
|
+
}
|
|
894
|
+
} else if (c === "?") {
|
|
895
|
+
re += "[^/]";
|
|
896
|
+
} else if (c === "{") {
|
|
897
|
+
const end = g.indexOf("}", i);
|
|
898
|
+
if (end > i) {
|
|
899
|
+
re += "(?:" + g.slice(i + 1, end).split(",").map(convert).join("|") + ")";
|
|
900
|
+
i = end;
|
|
901
|
+
} else {
|
|
902
|
+
re += "\\{";
|
|
903
|
+
}
|
|
904
|
+
} else {
|
|
905
|
+
re += escapeRe(c);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
return re;
|
|
909
|
+
};
|
|
910
|
+
return new RegExp("^" + convert(glob) + "$");
|
|
911
|
+
}
|
|
912
|
+
function toPosix(p) {
|
|
913
|
+
return p.split(path7.sep).join("/");
|
|
914
|
+
}
|
|
915
|
+
function makeExcluder(projectRoot, extra, alsoExcludeAbs) {
|
|
916
|
+
const plain = [...DEFAULT_LASTMOD_EXCLUDE, ...extra.filter((g) => !g.startsWith("!"))].map((g) => ({
|
|
917
|
+
re: lastmodGlobToRegExp(g),
|
|
918
|
+
base: !g.includes("/")
|
|
919
|
+
}));
|
|
920
|
+
const reinclude = extra.filter((g) => g.startsWith("!")).map((g) => ({ re: lastmodGlobToRegExp(g.slice(1)), base: !g.slice(1).includes("/") }));
|
|
921
|
+
const fixed = new Set(alsoExcludeAbs.map((a) => path7.resolve(a).toLowerCase()));
|
|
922
|
+
const test = (rules, rel) => rules.some((r) => r.re.test(r.base ? rel.split("/").pop() ?? rel : rel));
|
|
923
|
+
return (abs) => {
|
|
924
|
+
if (fixed.has(path7.resolve(abs).toLowerCase())) return true;
|
|
925
|
+
const rel = toPosix(path7.relative(projectRoot, abs));
|
|
926
|
+
if (!test(plain, rel)) return false;
|
|
927
|
+
return !test(reinclude, rel);
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
function expandGlob(absPattern) {
|
|
931
|
+
const posix = toPosix(absPattern);
|
|
932
|
+
const firstWild = posix.search(/[*?{]/);
|
|
933
|
+
if (firstWild < 0) return isFile(absPattern) ? [path7.resolve(absPattern)] : [];
|
|
934
|
+
const baseDir = posix.slice(0, posix.lastIndexOf("/", firstWild));
|
|
935
|
+
const re = lastmodGlobToRegExp(posix);
|
|
936
|
+
const out = [];
|
|
937
|
+
const walk = (dir, depth) => {
|
|
938
|
+
if (depth > 12) return;
|
|
939
|
+
let entries;
|
|
940
|
+
try {
|
|
941
|
+
entries = fs8.readdirSync(dir, { withFileTypes: true });
|
|
942
|
+
} catch {
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
for (const e of entries) {
|
|
946
|
+
if (e.name === "node_modules" || e.name === ".git") continue;
|
|
947
|
+
const full = path7.join(dir, e.name);
|
|
948
|
+
if (e.isDirectory()) walk(full, depth + 1);
|
|
949
|
+
else if (e.isFile() && re.test(toPosix(full))) out.push(path7.resolve(full));
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
walk(baseDir || "/", 0);
|
|
953
|
+
return out;
|
|
954
|
+
}
|
|
955
|
+
var CODE_EXT = /\.(vue|[cm]?[jt]sx?|md)$/i;
|
|
956
|
+
var RESOLVE_EXTENSIONS = ["", ".ts", ".js", ".mts", ".mjs", ".tsx", ".jsx", ".vue", ".json", "/index.ts", "/index.js", "/index.vue"];
|
|
957
|
+
var BUILTINS = new Set(builtinModules);
|
|
958
|
+
var VITEPRESS_BUILTIN_TAGS = /* @__PURE__ */ new Set(["Badge", "Content", "ClientOnly"]);
|
|
959
|
+
var VITEPRESS_BUILTIN_LAYOUTS = /* @__PURE__ */ new Set(["doc", "home", "page", "false"]);
|
|
960
|
+
function stripComments(src) {
|
|
961
|
+
return src.replace(/\/\*[\s\S]*?\*\//g, "").replace(/^\s*\/\/.*$/gm, "");
|
|
962
|
+
}
|
|
963
|
+
function findSrcDir(file) {
|
|
964
|
+
let dir = path7.dirname(file);
|
|
965
|
+
for (let i = 0; i < 12; i++) {
|
|
966
|
+
if (fs8.existsSync(path7.join(dir, ".vitepress"))) return dir;
|
|
967
|
+
const up = path7.dirname(dir);
|
|
968
|
+
if (up === dir) return void 0;
|
|
969
|
+
dir = up;
|
|
970
|
+
}
|
|
971
|
+
return void 0;
|
|
972
|
+
}
|
|
973
|
+
function hasPackage(specifier, fromFile) {
|
|
974
|
+
const parts = specifier.split("/");
|
|
975
|
+
const pkg = specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
|
|
976
|
+
let dir = path7.dirname(fromFile);
|
|
977
|
+
for (let i = 0; i < 40; i++) {
|
|
978
|
+
if (fs8.existsSync(path7.join(dir, "node_modules", pkg))) return true;
|
|
979
|
+
const up = path7.dirname(dir);
|
|
980
|
+
if (up === dir) return false;
|
|
981
|
+
dir = up;
|
|
982
|
+
}
|
|
983
|
+
return false;
|
|
984
|
+
}
|
|
985
|
+
function resolveWithExtensions(base) {
|
|
986
|
+
for (const ext of RESOLVE_EXTENSIONS) {
|
|
987
|
+
const c = base + ext;
|
|
988
|
+
if (isFile(c)) return path7.resolve(c);
|
|
989
|
+
}
|
|
990
|
+
return void 0;
|
|
991
|
+
}
|
|
992
|
+
function resolveImport(specifierRaw, fromFile, projectRoot) {
|
|
993
|
+
const specifier = specifierRaw.replace(/[?#].*$/, "");
|
|
994
|
+
if (!specifier) return { kind: "unresolved" };
|
|
995
|
+
if (specifier.startsWith("node:") || BUILTINS.has(specifier)) return { kind: "package" };
|
|
996
|
+
if (specifier.startsWith("virtual:") || specifier.startsWith("\0")) return { kind: "unresolved" };
|
|
997
|
+
let base;
|
|
998
|
+
if (specifier.startsWith(".")) base = path7.resolve(path7.dirname(fromFile), specifier);
|
|
999
|
+
else if (specifier.startsWith("@/") || specifier.startsWith("~/")) base = path7.join(projectRoot, "src", specifier.slice(2));
|
|
1000
|
+
else if (specifier.startsWith("@theme/")) {
|
|
1001
|
+
const srcDir = findSrcDir(fromFile);
|
|
1002
|
+
if (srcDir) base = path7.join(srcDir, ".vitepress", "theme", specifier.slice("@theme/".length));
|
|
1003
|
+
} else if (specifier.startsWith("/")) {
|
|
1004
|
+
const srcDir = findSrcDir(fromFile);
|
|
1005
|
+
const hit2 = resolveWithExtensions(path7.join(projectRoot, specifier)) ?? (srcDir ? resolveWithExtensions(path7.join(srcDir, specifier)) : void 0);
|
|
1006
|
+
return hit2 ? { kind: "file", file: hit2 } : { kind: "unresolved" };
|
|
1007
|
+
} else {
|
|
1008
|
+
return hasPackage(specifier, fromFile) ? { kind: "package" } : { kind: "unresolved" };
|
|
1009
|
+
}
|
|
1010
|
+
if (!base) return { kind: "unresolved" };
|
|
1011
|
+
const hit = resolveWithExtensions(base);
|
|
1012
|
+
return hit ? { kind: "file", file: hit } : { kind: "unresolved" };
|
|
1013
|
+
}
|
|
1014
|
+
function themeRegistry(srcDir, cache) {
|
|
1015
|
+
const hit = cache.get(srcDir);
|
|
1016
|
+
if (hit) return hit;
|
|
1017
|
+
const reg = /* @__PURE__ */ new Map();
|
|
1018
|
+
const themeDir = path7.join(srcDir, ".vitepress", "theme");
|
|
1019
|
+
const indexFile = ["index.ts", "index.js", "index.mts", "index.mjs"].map((f) => path7.join(themeDir, f)).find(isFile);
|
|
1020
|
+
if (indexFile) {
|
|
1021
|
+
const src = stripComments(fs8.readFileSync(indexFile, "utf8"));
|
|
1022
|
+
const idents = /* @__PURE__ */ new Map();
|
|
1023
|
+
for (const m of src.matchAll(/^\s*import\s+(\w+)\s+from\s+['"]([^'"]+)['"]/gm)) idents.set(m[1], m[2]);
|
|
1024
|
+
for (const m of src.matchAll(/\.component\(\s*['"]([\w-]+)['"]\s*,\s*(\w+)\s*\)/g)) {
|
|
1025
|
+
const spec = idents.get(m[2]);
|
|
1026
|
+
if (!spec) continue;
|
|
1027
|
+
const r = resolveImport(spec, indexFile, srcDir);
|
|
1028
|
+
if (r.kind === "file") {
|
|
1029
|
+
reg.set(m[1], r.file);
|
|
1030
|
+
reg.set(toPascal(m[1]), r.file);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
cache.set(srcDir, reg);
|
|
1035
|
+
return reg;
|
|
1036
|
+
}
|
|
1037
|
+
function dataLoaderInputs(src, loaderFile) {
|
|
1038
|
+
const srcDir = findSrcDir(loaderFile) ?? path7.dirname(loaderFile);
|
|
1039
|
+
const literals = (s) => [...s.matchAll(/['"]([^'"]+)['"]/g)].map((m) => m[1]);
|
|
1040
|
+
const out = [];
|
|
1041
|
+
let found = false;
|
|
1042
|
+
for (const m of src.matchAll(/createContentLoader\(\s*(\[[^\]]*\]|['"][^'"]+['"])/g)) {
|
|
1043
|
+
found = true;
|
|
1044
|
+
for (const g of literals(m[1])) out.push(...expandGlob(path7.resolve(srcDir, g)));
|
|
1045
|
+
}
|
|
1046
|
+
for (const m of src.matchAll(/\bwatch\s*:\s*(\[[^\]]*\]|['"][^'"]+['"])/g)) {
|
|
1047
|
+
found = true;
|
|
1048
|
+
for (const g of literals(m[1])) {
|
|
1049
|
+
const base = g.startsWith(".") ? path7.dirname(loaderFile) : srcDir;
|
|
1050
|
+
out.push(...expandGlob(path7.resolve(base, g)));
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
return found ? out : null;
|
|
1054
|
+
}
|
|
1055
|
+
function walkContentModules(entries, projectRoot, isExcluded, registryCache, fileCache) {
|
|
1056
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1057
|
+
const queue = [];
|
|
1058
|
+
for (const e of entries) {
|
|
1059
|
+
if (!seen.has(e)) {
|
|
1060
|
+
seen.add(e);
|
|
1061
|
+
queue.push(e);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
while (queue.length > 0) {
|
|
1065
|
+
const file = queue.shift();
|
|
1066
|
+
let info = fileCache.get(file);
|
|
1067
|
+
if (!info) {
|
|
1068
|
+
info = scanFile(file, projectRoot, registryCache);
|
|
1069
|
+
fileCache.set(file, info);
|
|
1070
|
+
}
|
|
1071
|
+
if (info.bad) return { files: [...seen], omitted: info.bad };
|
|
1072
|
+
for (const dep of info.deps) {
|
|
1073
|
+
if (seen.has(dep) || isExcluded(dep)) continue;
|
|
1074
|
+
seen.add(dep);
|
|
1075
|
+
queue.push(dep);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
return { files: [...seen] };
|
|
1079
|
+
}
|
|
1080
|
+
function scanFile(file, projectRoot, registryCache) {
|
|
1081
|
+
if (!CODE_EXT.test(file)) return { deps: [] };
|
|
1082
|
+
let raw;
|
|
1083
|
+
try {
|
|
1084
|
+
raw = fs8.readFileSync(file, "utf8");
|
|
1085
|
+
} catch {
|
|
1086
|
+
return { deps: [], bad: "unresolved-import" };
|
|
1087
|
+
}
|
|
1088
|
+
const isMd = /\.md$/i.test(file);
|
|
1089
|
+
if (isMd) {
|
|
1090
|
+
const fm = raw.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
1091
|
+
const layout = fm?.[1].match(/^layout\s*:\s*(.*?)\s*$/m)?.[1].replace(/^['"]|['"]$/g, "");
|
|
1092
|
+
if (layout && !VITEPRESS_BUILTIN_LAYOUTS.has(layout)) return { deps: [], bad: "custom-layout" };
|
|
1093
|
+
}
|
|
1094
|
+
const body = isMd ? raw.replace(/^(```|~~~)[\s\S]*?^\1/gm, "") : raw;
|
|
1095
|
+
const code = isMd ? [...body.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script>/gi)].map((m) => m[1]).join("\n") : body;
|
|
1096
|
+
const src = stripComments(code);
|
|
1097
|
+
const deps = /* @__PURE__ */ new Set();
|
|
1098
|
+
if (/\.data\.[cm]?[jt]s$/i.test(file)) {
|
|
1099
|
+
const inputs = dataLoaderInputs(src, file);
|
|
1100
|
+
if (inputs === null) return { deps: [], bad: "data-loader" };
|
|
1101
|
+
for (const f of inputs) deps.add(f);
|
|
1102
|
+
}
|
|
1103
|
+
for (const m of src.matchAll(/(?:\bfrom\s*|\bimport\s*\(\s*|^\s*import\s+)['"]([^'"]+)['"]/gm)) {
|
|
1104
|
+
const r = resolveImport(m[1], file, projectRoot);
|
|
1105
|
+
if (r.kind === "unresolved") return { deps: [], bad: "unresolved-import" };
|
|
1106
|
+
if (r.kind === "file" && r.file !== path7.resolve(file)) deps.add(r.file);
|
|
1107
|
+
}
|
|
1108
|
+
for (const m of src.matchAll(/import\.meta\.glob(?:<[^>]*>)?\(\s*(\[[^\]]*\]|['"][^'"]+['"])/g)) {
|
|
1109
|
+
for (const lit of [...m[1].matchAll(/['"]([^'"]+)['"]/g)].map((x) => x[1])) {
|
|
1110
|
+
if (lit.startsWith("!")) continue;
|
|
1111
|
+
const abs = lit.startsWith("/") ? path7.join(projectRoot, lit) : path7.resolve(path7.dirname(file), lit);
|
|
1112
|
+
for (const f of expandGlob(abs)) deps.add(f);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
const srcDir = findSrcDir(file);
|
|
1116
|
+
if (srcDir) {
|
|
1117
|
+
const reg = themeRegistry(srcDir, registryCache);
|
|
1118
|
+
const markup = isMd ? body.replace(/<script\b[\s\S]*?<\/script>/gi, "").replace(/`[^`\n]*`/g, "") : raw.match(/<template\b[\s\S]*<\/template>/i)?.[0] ?? "";
|
|
1119
|
+
const tags = /* @__PURE__ */ new Set();
|
|
1120
|
+
for (const m of markup.matchAll(/<([A-Z][A-Za-z0-9]*)\b/g)) tags.add(m[1]);
|
|
1121
|
+
for (const m of markup.matchAll(/<([a-z][a-z0-9]*(?:-[a-z0-9]+)+)\b/g)) tags.add(toPascal(m[1]));
|
|
1122
|
+
for (const tag of tags) {
|
|
1123
|
+
const target = reg.get(tag);
|
|
1124
|
+
if (target) deps.add(target);
|
|
1125
|
+
else if (isMd && !VITEPRESS_BUILTIN_TAGS.has(tag)) return { deps: [], bad: "unresolved-component" };
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
return { deps: [...deps] };
|
|
1129
|
+
}
|
|
1130
|
+
var ZERO_BLOB = /^0+$/;
|
|
1131
|
+
function findContentFile(projectRoot, contentPath) {
|
|
1132
|
+
const rel = contentPath ?? ".dcs/content.yaml";
|
|
1133
|
+
if (path7.isAbsolute(rel)) return isFile(rel) ? path7.resolve(rel) : void 0;
|
|
1134
|
+
return [path7.resolve(projectRoot, rel), path7.resolve(projectRoot, "..", rel), path7.resolve(process.cwd(), rel)].find(isFile);
|
|
1135
|
+
}
|
|
1136
|
+
function referencedGlobalKeys(files, globalKeys) {
|
|
1137
|
+
if (globalKeys.length === 0) return [];
|
|
1138
|
+
const text = files.filter((f) => CODE_EXT.test(f)).map((f) => {
|
|
1139
|
+
try {
|
|
1140
|
+
return fs8.readFileSync(f, "utf8");
|
|
1141
|
+
} catch {
|
|
1142
|
+
return "";
|
|
1143
|
+
}
|
|
1144
|
+
}).join("\n");
|
|
1145
|
+
return globalKeys.filter((k) => text.includes(`'${k}'`) || text.includes(`"${k}"`) || text.includes(`\`${k}\``));
|
|
1146
|
+
}
|
|
1147
|
+
function deriveRouteLastmods(options) {
|
|
1148
|
+
const {
|
|
1149
|
+
routes,
|
|
1150
|
+
projectRoot,
|
|
1151
|
+
sourcesForRoute,
|
|
1152
|
+
contentPath,
|
|
1153
|
+
exclude = [],
|
|
1154
|
+
contentWalkLimit = CONTENT_WALK_LIMIT,
|
|
1155
|
+
git = defaultGit,
|
|
1156
|
+
debug = false
|
|
1157
|
+
} = options;
|
|
1158
|
+
const omitted = /* @__PURE__ */ new Map();
|
|
1159
|
+
const sources = /* @__PURE__ */ new Map();
|
|
1160
|
+
const empty = (withheld) => {
|
|
1161
|
+
if (debug) console.log(`[dcs-seo] git-derived <lastmod> withheld: ${withheld}`);
|
|
1162
|
+
return { lastmods: /* @__PURE__ */ new Map(), withheld, omitted, sources };
|
|
1163
|
+
};
|
|
1164
|
+
let shallow;
|
|
1165
|
+
try {
|
|
1166
|
+
shallow = git(["rev-parse", "--is-shallow-repository"], projectRoot).trim();
|
|
1167
|
+
} catch {
|
|
1168
|
+
return empty("git-unavailable");
|
|
1169
|
+
}
|
|
1170
|
+
if (shallow === "true") return empty("shallow");
|
|
1171
|
+
if (shallow !== "false") return empty("git-unavailable");
|
|
1172
|
+
let top;
|
|
1173
|
+
try {
|
|
1174
|
+
top = path7.resolve(git(["rev-parse", "--show-toplevel"], projectRoot).trim());
|
|
1175
|
+
} catch {
|
|
1176
|
+
return empty("git-unavailable");
|
|
1177
|
+
}
|
|
1178
|
+
const relTop = (abs) => toPosix(path7.relative(top, abs));
|
|
1179
|
+
const contentFile = findContentFile(projectRoot, contentPath);
|
|
1180
|
+
const isExcluded = makeExcluder(projectRoot, exclude, contentFile ? [contentFile] : []);
|
|
1181
|
+
const registryCache = /* @__PURE__ */ new Map();
|
|
1182
|
+
const fileCache = /* @__PURE__ */ new Map();
|
|
1183
|
+
const routeFiles = /* @__PURE__ */ new Map();
|
|
1184
|
+
for (const route of routes) {
|
|
1185
|
+
if (routeFiles.has(route.path) || omitted.has(route.path)) continue;
|
|
1186
|
+
const entries = routeEntries(route, projectRoot, sourcesForRoute);
|
|
1187
|
+
if (entries.length === 0) {
|
|
1188
|
+
omitted.set(route.path, "no-source");
|
|
1189
|
+
continue;
|
|
1190
|
+
}
|
|
1191
|
+
const walked = walkContentModules(entries, projectRoot, isExcluded, registryCache, fileCache);
|
|
1192
|
+
if (walked.omitted) {
|
|
1193
|
+
omitted.set(route.path, walked.omitted);
|
|
1194
|
+
continue;
|
|
1195
|
+
}
|
|
1196
|
+
routeFiles.set(route.path, walked.files);
|
|
1197
|
+
}
|
|
1198
|
+
const allFiles = [...new Set([...routeFiles.values()].flat())];
|
|
1199
|
+
const material = contentFile ? [...allFiles, contentFile] : allFiles;
|
|
1200
|
+
const tracked = /* @__PURE__ */ new Set();
|
|
1201
|
+
const dirty = /* @__PURE__ */ new Set();
|
|
1202
|
+
const newest = /* @__PURE__ */ new Map();
|
|
1203
|
+
if (material.length > 0) {
|
|
1204
|
+
const rels = [...new Set(material.map(relTop))];
|
|
1205
|
+
try {
|
|
1206
|
+
for (const line of git(["-c", "core.quotepath=off", "ls-files"], top).split("\n")) {
|
|
1207
|
+
if (line.trim()) tracked.add(line.trim());
|
|
1208
|
+
}
|
|
1209
|
+
for (const line of git(["-c", "core.quotepath=off", "status", "--porcelain=v1", "--untracked-files=all"], top).split("\n")) {
|
|
1210
|
+
if (line.length <= 3) continue;
|
|
1211
|
+
for (const part of line.slice(3).trim().split(" -> ")) dirty.add(part.replace(/^"|"$/g, ""));
|
|
1212
|
+
}
|
|
1213
|
+
const dated = rels.filter((r) => tracked.has(r));
|
|
1214
|
+
for (let i = 0; i < dated.length; i += 150) {
|
|
1215
|
+
const out = git(
|
|
1216
|
+
["-c", "core.quotepath=off", "log", "--format=%x01%cI", "--name-only", "--cc", "--", ...dated.slice(i, i + 150)],
|
|
1217
|
+
top
|
|
1218
|
+
);
|
|
1219
|
+
let date = null;
|
|
1220
|
+
for (const line of out.split("\n")) {
|
|
1221
|
+
const t = line.trim();
|
|
1222
|
+
if (t.startsWith("")) {
|
|
1223
|
+
date = t.slice(1);
|
|
1224
|
+
continue;
|
|
1225
|
+
}
|
|
1226
|
+
if (!t || !date) continue;
|
|
1227
|
+
const known = newest.get(t);
|
|
1228
|
+
if (!known || Date.parse(date) > Date.parse(known)) newest.set(t, date);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
} catch {
|
|
1232
|
+
return empty("git-unavailable");
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
const isClean = (abs) => tracked.has(relTop(abs)) && !dirty.has(relTop(abs));
|
|
1236
|
+
let contentEntries = [];
|
|
1237
|
+
let contentCapped = false;
|
|
1238
|
+
let contentOk = true;
|
|
1239
|
+
const blobCache = /* @__PURE__ */ new Map();
|
|
1240
|
+
let globalKeys = [];
|
|
1241
|
+
if (contentFile) {
|
|
1242
|
+
if (!isClean(contentFile)) {
|
|
1243
|
+
contentOk = false;
|
|
1244
|
+
} else {
|
|
1245
|
+
try {
|
|
1246
|
+
const out = git(
|
|
1247
|
+
["log", "--first-parent", "-m", `-n${contentWalkLimit + 1}`, "--format=%x01%cI", "--raw", "--no-abbrev", "--", relTop(contentFile)],
|
|
1248
|
+
top
|
|
1249
|
+
);
|
|
1250
|
+
let date = null;
|
|
1251
|
+
for (const line of out.split("\n")) {
|
|
1252
|
+
const t = line.trim();
|
|
1253
|
+
if (t.startsWith("")) {
|
|
1254
|
+
date = t.slice(1);
|
|
1255
|
+
continue;
|
|
1256
|
+
}
|
|
1257
|
+
const m = t.match(/^:\d+ \d+ ([0-9a-f]+) ([0-9a-f]+) /);
|
|
1258
|
+
if (m && date) contentEntries.push({ date, oldBlob: m[1], newBlob: m[2] });
|
|
1259
|
+
}
|
|
1260
|
+
} catch {
|
|
1261
|
+
return empty("git-unavailable");
|
|
1262
|
+
}
|
|
1263
|
+
if (contentEntries.length > contentWalkLimit) {
|
|
1264
|
+
contentCapped = true;
|
|
1265
|
+
contentEntries = contentEntries.slice(0, contentWalkLimit);
|
|
1266
|
+
}
|
|
1267
|
+
try {
|
|
1268
|
+
const head = yaml5.load(fs8.readFileSync(contentFile, "utf8"));
|
|
1269
|
+
globalKeys = Object.keys(head?.global ?? {});
|
|
1270
|
+
} catch {
|
|
1271
|
+
contentOk = false;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
const loadBlob = (blob) => {
|
|
1276
|
+
if (ZERO_BLOB.test(blob)) return null;
|
|
1277
|
+
if (blobCache.has(blob)) return blobCache.get(blob) ?? null;
|
|
1278
|
+
let doc = null;
|
|
1279
|
+
try {
|
|
1280
|
+
doc = yaml5.load(git(["cat-file", "-p", blob], top)) ?? null;
|
|
1281
|
+
} catch {
|
|
1282
|
+
doc = null;
|
|
1283
|
+
}
|
|
1284
|
+
blobCache.set(blob, doc);
|
|
1285
|
+
return doc;
|
|
1286
|
+
};
|
|
1287
|
+
const subtreeKey = (doc, slug, keys) => {
|
|
1288
|
+
const pages = doc?.pages ?? {};
|
|
1289
|
+
const global = doc?.global ?? {};
|
|
1290
|
+
return JSON.stringify({ page: pages[slug] ?? null, global: keys.map((k) => [k, global[k] ?? null]) });
|
|
1291
|
+
};
|
|
1292
|
+
const lastmods = /* @__PURE__ */ new Map();
|
|
1293
|
+
for (const route of routes) {
|
|
1294
|
+
const files = routeFiles.get(route.path);
|
|
1295
|
+
if (!files || lastmods.has(route.path)) continue;
|
|
1296
|
+
if (!files.every(isClean)) {
|
|
1297
|
+
omitted.set(route.path, "untracked-source");
|
|
1298
|
+
continue;
|
|
1299
|
+
}
|
|
1300
|
+
let best = null;
|
|
1301
|
+
let undated = false;
|
|
1302
|
+
for (const f of files) {
|
|
1303
|
+
const d = newest.get(relTop(f));
|
|
1304
|
+
if (!d) {
|
|
1305
|
+
undated = true;
|
|
1306
|
+
break;
|
|
1307
|
+
}
|
|
1308
|
+
if (best === null || Date.parse(d) > Date.parse(best)) best = d;
|
|
1309
|
+
}
|
|
1310
|
+
if (undated || best === null) {
|
|
1311
|
+
omitted.set(route.path, "undated-source");
|
|
1312
|
+
continue;
|
|
1313
|
+
}
|
|
1314
|
+
if (contentFile) {
|
|
1315
|
+
if (!contentOk) {
|
|
1316
|
+
omitted.set(route.path, "content-untracked");
|
|
1317
|
+
continue;
|
|
1318
|
+
}
|
|
1319
|
+
const keys = referencedGlobalKeys(files, globalKeys);
|
|
1320
|
+
let contentDate = null;
|
|
1321
|
+
for (const e of contentEntries) {
|
|
1322
|
+
if (subtreeKey(loadBlob(e.newBlob), route.slug, keys) !== subtreeKey(loadBlob(e.oldBlob), route.slug, keys)) {
|
|
1323
|
+
contentDate = e.date;
|
|
1324
|
+
break;
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
if (contentDate === null && contentCapped) {
|
|
1328
|
+
omitted.set(route.path, "content-walk-cap");
|
|
1329
|
+
continue;
|
|
1330
|
+
}
|
|
1331
|
+
if (contentDate && Date.parse(contentDate) > Date.parse(best)) best = contentDate;
|
|
1332
|
+
}
|
|
1333
|
+
lastmods.set(route.path, best);
|
|
1334
|
+
sources.set(route.path, contentFile ? [...files, contentFile] : files);
|
|
1335
|
+
}
|
|
1336
|
+
if (lastmods.size >= IDENTICAL_LASTMOD_ROUTE_LIMIT && new Set(lastmods.values()).size === 1) {
|
|
1337
|
+
return empty("identical-dates");
|
|
1338
|
+
}
|
|
1339
|
+
if (debug) {
|
|
1340
|
+
for (const [p, why] of omitted) console.log(`[dcs-seo] <lastmod> omitted for ${p}: ${why}`);
|
|
1341
|
+
}
|
|
1342
|
+
return { lastmods, omitted, sources };
|
|
1343
|
+
}
|
|
797
1344
|
|
|
798
1345
|
// src/plugins/dcsSeoPlugin.ts
|
|
799
1346
|
function readHonestyBlock(value) {
|
|
@@ -818,7 +1365,7 @@ function loadSeoConfig(projectRoot, seoPath, debug) {
|
|
|
818
1365
|
];
|
|
819
1366
|
let foundPath;
|
|
820
1367
|
for (const testPath of possiblePaths) {
|
|
821
|
-
if (
|
|
1368
|
+
if (fs8.existsSync(testPath)) {
|
|
822
1369
|
foundPath = testPath;
|
|
823
1370
|
break;
|
|
824
1371
|
}
|
|
@@ -832,8 +1379,8 @@ function loadSeoConfig(projectRoot, seoPath, debug) {
|
|
|
832
1379
|
return null;
|
|
833
1380
|
}
|
|
834
1381
|
try {
|
|
835
|
-
const fileContent =
|
|
836
|
-
const config2 =
|
|
1382
|
+
const fileContent = fs8.readFileSync(foundPath, "utf8");
|
|
1383
|
+
const config2 = yaml5.load(fileContent);
|
|
837
1384
|
return { config: config2, foundPath };
|
|
838
1385
|
} catch (error) {
|
|
839
1386
|
console.warn("[dcs-seo] Failed to parse seo.yaml:", error);
|
|
@@ -846,13 +1393,13 @@ function loadContentConfig(projectRoot, contentRelPath, debug) {
|
|
|
846
1393
|
path7.resolve(projectRoot, "..", contentRelPath),
|
|
847
1394
|
path7.resolve(process.cwd(), contentRelPath)
|
|
848
1395
|
];
|
|
849
|
-
const foundPath = possiblePaths.find((p) =>
|
|
1396
|
+
const foundPath = possiblePaths.find((p) => fs8.existsSync(p));
|
|
850
1397
|
if (!foundPath) {
|
|
851
1398
|
if (debug) console.log(`[dcs-seo] No content.yaml found (reviews disabled)`);
|
|
852
1399
|
return void 0;
|
|
853
1400
|
}
|
|
854
1401
|
try {
|
|
855
|
-
const parsed =
|
|
1402
|
+
const parsed = yaml5.load(fs8.readFileSync(foundPath, "utf8"));
|
|
856
1403
|
if (!parsed || typeof parsed !== "object") return void 0;
|
|
857
1404
|
return parsed;
|
|
858
1405
|
} catch (error) {
|
|
@@ -866,10 +1413,10 @@ function loadExcludedGlobs(projectRoot, pagesPath) {
|
|
|
866
1413
|
path7.resolve(projectRoot, "..", pagesPath),
|
|
867
1414
|
path7.resolve(process.cwd(), pagesPath)
|
|
868
1415
|
];
|
|
869
|
-
const found = possiblePaths.find((p) =>
|
|
1416
|
+
const found = possiblePaths.find((p) => fs8.existsSync(p));
|
|
870
1417
|
if (!found) return [];
|
|
871
1418
|
try {
|
|
872
|
-
const raw =
|
|
1419
|
+
const raw = yaml5.load(fs8.readFileSync(found, "utf8"));
|
|
873
1420
|
const excluded = raw?.excluded;
|
|
874
1421
|
if (!Array.isArray(excluded)) return [];
|
|
875
1422
|
return excluded.filter((e) => typeof e === "string");
|
|
@@ -919,24 +1466,6 @@ function assertNoOrphanNoindexEntries(noindex, routes) {
|
|
|
919
1466
|
if (orphans.length === 0) return;
|
|
920
1467
|
throw new NoindexOrphanError(orphans, [...collectNoindexMatchKeys(routes)].sort());
|
|
921
1468
|
}
|
|
922
|
-
function deriveLastmod(seoConfig, projectRoot, pagesPath) {
|
|
923
|
-
const fromSeo = seoConfig?.lastUpdated;
|
|
924
|
-
if (typeof fromSeo === "string" && fromSeo.length > 0) return fromSeo;
|
|
925
|
-
const possiblePaths = [
|
|
926
|
-
path7.resolve(projectRoot, pagesPath),
|
|
927
|
-
path7.resolve(projectRoot, "..", pagesPath),
|
|
928
|
-
path7.resolve(process.cwd(), pagesPath)
|
|
929
|
-
];
|
|
930
|
-
const found = possiblePaths.find((p) => fs7.existsSync(p));
|
|
931
|
-
if (!found) return void 0;
|
|
932
|
-
try {
|
|
933
|
-
const raw = yaml4.load(fs7.readFileSync(found, "utf8"));
|
|
934
|
-
const fromPages = raw?.lastUpdated;
|
|
935
|
-
if (typeof fromPages === "string" && fromPages.length > 0) return fromPages;
|
|
936
|
-
} catch {
|
|
937
|
-
}
|
|
938
|
-
return void 0;
|
|
939
|
-
}
|
|
940
1469
|
function emitSiteFiles(params) {
|
|
941
1470
|
const {
|
|
942
1471
|
outDir,
|
|
@@ -950,12 +1479,25 @@ function emitSiteFiles(params) {
|
|
|
950
1479
|
preview = false,
|
|
951
1480
|
robots = {},
|
|
952
1481
|
llms = true,
|
|
1482
|
+
gitLastmod,
|
|
1483
|
+
lastmodSources,
|
|
1484
|
+
contentPath,
|
|
1485
|
+
git,
|
|
953
1486
|
debug = false
|
|
954
1487
|
} = params;
|
|
955
1488
|
const written = [];
|
|
956
1489
|
const effectiveSiteUrl = siteUrl || seoConfig?.global?.siteUrl;
|
|
957
1490
|
const excludedGlobs = loadExcludedGlobs(projectRoot, pagesPath);
|
|
958
|
-
const
|
|
1491
|
+
const gitOptIn = gitLastmod ?? seoConfig?.sitemap?.lastmodFromGit === true;
|
|
1492
|
+
const routeLastmods = !preview && gitOptIn ? deriveRouteLastmods({
|
|
1493
|
+
routes,
|
|
1494
|
+
projectRoot,
|
|
1495
|
+
sourcesForRoute: lastmodSources,
|
|
1496
|
+
contentPath,
|
|
1497
|
+
exclude: Array.isArray(seoConfig?.sitemap?.lastmodExclude) ? seoConfig.sitemap.lastmodExclude.filter((g) => typeof g === "string") : [],
|
|
1498
|
+
git,
|
|
1499
|
+
debug
|
|
1500
|
+
}).lastmods : void 0;
|
|
959
1501
|
let wroteSitemap = false;
|
|
960
1502
|
if (!preview) {
|
|
961
1503
|
const xml = buildSitemapXml({
|
|
@@ -965,10 +1507,10 @@ function emitSiteFiles(params) {
|
|
|
965
1507
|
exclude,
|
|
966
1508
|
noindex,
|
|
967
1509
|
excludedGlobs,
|
|
968
|
-
|
|
1510
|
+
routeLastmods
|
|
969
1511
|
});
|
|
970
1512
|
if (xml) {
|
|
971
|
-
|
|
1513
|
+
fs8.writeFileSync(path7.join(outDir, "sitemap.xml"), xml, "utf8");
|
|
972
1514
|
wroteSitemap = true;
|
|
973
1515
|
written.push("sitemap.xml");
|
|
974
1516
|
if (debug) console.log("[dcs-seo] wrote sitemap.xml");
|
|
@@ -976,21 +1518,36 @@ function emitSiteFiles(params) {
|
|
|
976
1518
|
console.log("[dcs-seo] no absolute <loc> derivable; sitemap.xml not written");
|
|
977
1519
|
}
|
|
978
1520
|
}
|
|
1521
|
+
const seoAiTraining = seoConfig?.robots?.aiTraining;
|
|
1522
|
+
const effectiveRobots = {
|
|
1523
|
+
...robots,
|
|
1524
|
+
aiTraining: robots.aiTraining ?? (typeof seoAiTraining === "boolean" ? seoAiTraining : true)
|
|
1525
|
+
};
|
|
979
1526
|
if (robots.enabled ?? true) {
|
|
980
1527
|
const robotsPath = path7.join(outDir, "robots.txt");
|
|
981
|
-
const existing =
|
|
1528
|
+
const existing = fs8.existsSync(robotsPath) && !robots.force ? fs8.readFileSync(robotsPath, "utf8") : null;
|
|
982
1529
|
const keepHandAuthored = existing !== null && isHandAuthoredRobotsAcceptable(existing);
|
|
983
1530
|
if (keepHandAuthored) {
|
|
984
|
-
if (
|
|
1531
|
+
if (effectiveRobots.aiTraining === false && !preview) {
|
|
1532
|
+
const conflicts = findAiTrainingRobotsConflicts(existing);
|
|
1533
|
+
if (conflicts.length > 0) throw new RobotsAiTrainingConflictError(robotsPath, conflicts);
|
|
1534
|
+
const { text, added } = appendAiTrainingOptOut(existing);
|
|
1535
|
+
if (added.length > 0) {
|
|
1536
|
+
fs8.writeFileSync(robotsPath, text, "utf8");
|
|
1537
|
+
written.push("robots.txt");
|
|
1538
|
+
}
|
|
1539
|
+
if (debug) console.log(`[dcs-seo] dist/robots.txt is hand-authored; appended AI training opt-out for ${added.join(", ") || "(none)"}`);
|
|
1540
|
+
} else if (debug) {
|
|
985
1541
|
console.log("[dcs-seo] dist/robots.txt is hand-authored and meets the floor; leaving it");
|
|
1542
|
+
}
|
|
986
1543
|
} else {
|
|
987
1544
|
const txt = buildRobotsTxt({
|
|
988
1545
|
siteUrl: effectiveSiteUrl,
|
|
989
1546
|
preview,
|
|
990
|
-
robots,
|
|
1547
|
+
robots: effectiveRobots,
|
|
991
1548
|
hasSitemap: wroteSitemap
|
|
992
1549
|
});
|
|
993
|
-
|
|
1550
|
+
fs8.writeFileSync(robotsPath, txt, "utf8");
|
|
994
1551
|
written.push("robots.txt");
|
|
995
1552
|
if (debug) {
|
|
996
1553
|
console.log(
|
|
@@ -1009,7 +1566,7 @@ function emitSiteFiles(params) {
|
|
|
1009
1566
|
excludedGlobs
|
|
1010
1567
|
});
|
|
1011
1568
|
if (txt) {
|
|
1012
|
-
|
|
1569
|
+
fs8.writeFileSync(path7.join(outDir, "llms.txt"), txt, "utf8");
|
|
1013
1570
|
written.push("llms.txt");
|
|
1014
1571
|
if (debug) console.log("[dcs-seo] wrote llms.txt");
|
|
1015
1572
|
} else if (debug) {
|
|
@@ -1076,8 +1633,8 @@ function emitStaticSeoHtml(params) {
|
|
|
1076
1633
|
});
|
|
1077
1634
|
const html = spliceHeadHtml(shellHtml, tags);
|
|
1078
1635
|
const outFile = routeToOutputFile(outDir, route.path);
|
|
1079
|
-
|
|
1080
|
-
|
|
1636
|
+
fs8.mkdirSync(path7.dirname(outFile), { recursive: true });
|
|
1637
|
+
fs8.writeFileSync(outFile, html, "utf8");
|
|
1081
1638
|
written++;
|
|
1082
1639
|
if (debug) {
|
|
1083
1640
|
console.log(
|
|
@@ -1235,7 +1792,7 @@ function runCharsetBudget(params) {
|
|
|
1235
1792
|
const file = routeToOutputFile(outDir, route.path);
|
|
1236
1793
|
let html;
|
|
1237
1794
|
try {
|
|
1238
|
-
html =
|
|
1795
|
+
html = fs8.readFileSync(file, "utf8");
|
|
1239
1796
|
} catch {
|
|
1240
1797
|
continue;
|
|
1241
1798
|
}
|
|
@@ -1284,6 +1841,8 @@ function dcsSeoPlugin(options = {}) {
|
|
|
1284
1841
|
// release/** SWA preview build never body-prerenders; an explicit option wins.
|
|
1285
1842
|
preview = process.env.DCS_PREVIEW === "true",
|
|
1286
1843
|
llms = true,
|
|
1844
|
+
gitLastmod,
|
|
1845
|
+
lastmodSources,
|
|
1287
1846
|
dirIndex = true
|
|
1288
1847
|
} = options;
|
|
1289
1848
|
let resolvedConfig;
|
|
@@ -1385,12 +1944,12 @@ function dcsSeoPlugin(options = {}) {
|
|
|
1385
1944
|
try {
|
|
1386
1945
|
const projectRoot = resolvedConfig?.root || process.cwd();
|
|
1387
1946
|
const outDir = resolveOutDir(resolvedConfig);
|
|
1388
|
-
if (!
|
|
1947
|
+
if (!fs8.existsSync(outDir)) {
|
|
1389
1948
|
console.warn(`[dcs-seo] emitStaticHtml: outDir not found (${outDir}); skipping`);
|
|
1390
1949
|
return;
|
|
1391
1950
|
}
|
|
1392
1951
|
const shellPath = path7.join(outDir, "index.html");
|
|
1393
|
-
if (!
|
|
1952
|
+
if (!fs8.existsSync(shellPath)) {
|
|
1394
1953
|
console.warn(
|
|
1395
1954
|
`[dcs-seo] emitStaticHtml: no index.html in ${outDir}; nothing to emit`
|
|
1396
1955
|
);
|
|
@@ -1409,7 +1968,7 @@ function dcsSeoPlugin(options = {}) {
|
|
|
1409
1968
|
`[dcs-seo] emitStaticHtml: ${seoPath} missing or unparseable; emitting with defaults only`
|
|
1410
1969
|
);
|
|
1411
1970
|
}
|
|
1412
|
-
const rawShellHtml =
|
|
1971
|
+
const rawShellHtml = fs8.readFileSync(shellPath, "utf8");
|
|
1413
1972
|
const shellHtml = hoistCharsetMeta(rawShellHtml);
|
|
1414
1973
|
{
|
|
1415
1974
|
const b = checkCharsetBudget(rawShellHtml);
|
|
@@ -1425,7 +1984,7 @@ function dcsSeoPlugin(options = {}) {
|
|
|
1425
1984
|
};
|
|
1426
1985
|
}
|
|
1427
1986
|
if (shellHtml !== rawShellHtml) {
|
|
1428
|
-
|
|
1987
|
+
fs8.writeFileSync(shellPath, shellHtml, "utf8");
|
|
1429
1988
|
const before = checkCharsetBudget(rawShellHtml);
|
|
1430
1989
|
const after = checkCharsetBudget(shellHtml);
|
|
1431
1990
|
console.log(
|
|
@@ -1465,6 +2024,9 @@ function dcsSeoPlugin(options = {}) {
|
|
|
1465
2024
|
preview,
|
|
1466
2025
|
robots,
|
|
1467
2026
|
llms,
|
|
2027
|
+
gitLastmod,
|
|
2028
|
+
lastmodSources,
|
|
2029
|
+
contentPath,
|
|
1468
2030
|
debug
|
|
1469
2031
|
});
|
|
1470
2032
|
if (debug) {
|
|
@@ -1539,6 +2101,7 @@ function dcsSeoPlugin(options = {}) {
|
|
|
1539
2101
|
renderForHonestyOnly
|
|
1540
2102
|
};
|
|
1541
2103
|
} catch (error) {
|
|
2104
|
+
if (error instanceof RobotsAiTrainingConflictError) throw error;
|
|
1542
2105
|
console.warn("[dcs-seo] emitStaticHtml failed; build output left unchanged:", error);
|
|
1543
2106
|
}
|
|
1544
2107
|
let headObservations = [];
|
|
@@ -1637,8 +2200,8 @@ function dcsSeoPlugin(options = {}) {
|
|
|
1637
2200
|
} finally {
|
|
1638
2201
|
if (reportPath) {
|
|
1639
2202
|
try {
|
|
1640
|
-
|
|
1641
|
-
|
|
2203
|
+
fs8.mkdirSync(path7.dirname(path7.resolve(reportPath)), { recursive: true });
|
|
2204
|
+
fs8.writeFileSync(path7.resolve(reportPath), JSON.stringify(report, null, 2), "utf8");
|
|
1642
2205
|
console.log(`[dcs-seo] honesty report written: ${path7.resolve(reportPath)}`);
|
|
1643
2206
|
} catch (err) {
|
|
1644
2207
|
console.warn("[dcs-seo] could not write honesty report:", err);
|
|
@@ -1727,7 +2290,7 @@ function dcsSeoPlugin(options = {}) {
|
|
|
1727
2290
|
path7.resolve(projectRoot, "..", seoPath)
|
|
1728
2291
|
].map((p) => path7.normalize(p));
|
|
1729
2292
|
watchPaths.forEach((watchPath) => {
|
|
1730
|
-
if (
|
|
2293
|
+
if (fs8.existsSync(watchPath)) {
|
|
1731
2294
|
server.watcher.add(watchPath);
|
|
1732
2295
|
}
|
|
1733
2296
|
});
|
|
@@ -1904,9 +2467,9 @@ function loadCdnImageMap(projectRoot, relativeMapPath, debug) {
|
|
|
1904
2467
|
path7.resolve(process.cwd(), relativeMapPath)
|
|
1905
2468
|
];
|
|
1906
2469
|
for (const testPath of possiblePaths) {
|
|
1907
|
-
if (
|
|
2470
|
+
if (fs8.existsSync(testPath)) {
|
|
1908
2471
|
try {
|
|
1909
|
-
const raw =
|
|
2472
|
+
const raw = fs8.readFileSync(testPath, "utf8");
|
|
1910
2473
|
const data = JSON.parse(raw);
|
|
1911
2474
|
const map = /* @__PURE__ */ new Map();
|
|
1912
2475
|
for (const entry of data.images) {
|
|
@@ -2070,11 +2633,11 @@ function dcsCdnBuildEnd(options = {}) {
|
|
|
2070
2633
|
return;
|
|
2071
2634
|
}
|
|
2072
2635
|
const outDir = siteConfig.outDir;
|
|
2073
|
-
if (!
|
|
2636
|
+
if (!fs8.existsSync(outDir)) return;
|
|
2074
2637
|
let filesProcessed = 0;
|
|
2075
2638
|
let refsReplaced = 0;
|
|
2076
2639
|
function walkDir(dir) {
|
|
2077
|
-
const entries =
|
|
2640
|
+
const entries = fs8.readdirSync(dir, { withFileTypes: true });
|
|
2078
2641
|
for (const entry of entries) {
|
|
2079
2642
|
const fullPath = path7.join(dir, entry.name);
|
|
2080
2643
|
if (entry.isDirectory()) {
|
|
@@ -2085,7 +2648,7 @@ function dcsCdnBuildEnd(options = {}) {
|
|
|
2085
2648
|
}
|
|
2086
2649
|
}
|
|
2087
2650
|
function processFile(filePath) {
|
|
2088
|
-
let content =
|
|
2651
|
+
let content = fs8.readFileSync(filePath, "utf8");
|
|
2089
2652
|
if (!pathPrefixes.some((p) => content.includes(p))) return;
|
|
2090
2653
|
let changed = false;
|
|
2091
2654
|
if (filePath.endsWith(".html")) {
|
|
@@ -2120,7 +2683,7 @@ function dcsCdnBuildEnd(options = {}) {
|
|
|
2120
2683
|
}
|
|
2121
2684
|
}
|
|
2122
2685
|
if (changed) {
|
|
2123
|
-
|
|
2686
|
+
fs8.writeFileSync(filePath, content, "utf8");
|
|
2124
2687
|
filesProcessed++;
|
|
2125
2688
|
}
|
|
2126
2689
|
}
|
|
@@ -2167,6 +2730,6 @@ function responsiveImagePlugin(md) {
|
|
|
2167
2730
|
};
|
|
2168
2731
|
}
|
|
2169
2732
|
|
|
2170
|
-
export { AGENT_CONFIG_ORIGINS, DCS_MOTION_TOKENS_CSS, DEFAULT_AGENT_API_BASE_URL, DEFAULT_AGENT_WIDGET_SCRIPT_URL, DIR_INDEX_INSTALLED, DIR_INDEX_MANIFEST_ENV, DIR_INDEX_MANIFEST_SCHEMA, DirIndexError, NoindexOrphanError, buildAgentWidgetLoaderScript, chainBuildEnd, clearDirIndexManifest, collectNoindexMatchKeys, dcsAgentWidgetLoaderTag, dcsCdnBuildEnd, dcsCdnImagePlugin, dcsContentPlugin, dcsDirIndexBuildEnd, dcsEditorPlugin, dcsMotionTokensStyleTag, dcsPreviewPlugin, dcsResponsiveImageLint, dcsSeoPlugin, dirIndexCandidates, emitDirectoryIndexes, emitSiteFiles, emitStaticSeoHtml, findFullSizeCdnImages, findOrphanNoindexEntries, installDirIndex, isFullSizeCdnUrl, readAgentConfigOrigin, readSiteSlug, responsiveImagePlugin };
|
|
2733
|
+
export { AGENT_CONFIG_ORIGINS, CONTENT_WALK_LIMIT, DCS_MOTION_TOKENS_CSS, DEFAULT_AGENT_API_BASE_URL, DEFAULT_AGENT_WIDGET_SCRIPT_URL, DEFAULT_LASTMOD_EXCLUDE, DIR_INDEX_INSTALLED, DIR_INDEX_MANIFEST_ENV, DIR_INDEX_MANIFEST_SCHEMA, DirIndexError, IDENTICAL_LASTMOD_ROUTE_LIMIT, NoindexOrphanError, buildAgentWidgetLoaderScript, chainBuildEnd, clearDirIndexManifest, collectNoindexMatchKeys, dcsAgentWidgetLoaderTag, dcsCdnBuildEnd, dcsCdnImagePlugin, dcsContentPlugin, dcsDirIndexBuildEnd, dcsEditorPlugin, dcsMotionTokensStyleTag, dcsPreviewPlugin, dcsResponsiveImageLint, dcsSeoPlugin, defaultRouteSourceCandidates, deriveRouteLastmods, dirIndexCandidates, emitDirectoryIndexes, emitSiteFiles, emitStaticSeoHtml, findFullSizeCdnImages, findOrphanNoindexEntries, installDirIndex, isFullSizeCdnUrl, lastmodGlobToRegExp, readAgentConfigOrigin, readSiteSlug, responsiveImagePlugin };
|
|
2171
2734
|
//# sourceMappingURL=index.js.map
|
|
2172
2735
|
//# sourceMappingURL=index.js.map
|