clean-jsdoc-theme 5.0.3 → 5.0.5

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/publish.js CHANGED
@@ -30,8 +30,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/publish.ts
31
31
  var publish_exports = {};
32
32
  __export(publish_exports, {
33
+ cleanOutputDirEnabled: () => cleanOutputDirEnabled,
33
34
  collectDocs: () => collectDocs,
35
+ collectStaticFiles: () => collectStaticFiles,
34
36
  computeRelPaths: () => computeRelPaths,
37
+ createImageCollector: () => createImageCollector,
35
38
  hasMarkdownPlugin: () => hasMarkdownPlugin,
36
39
  normalizeColors: () => normalizeColors,
37
40
  normalizeCopyPage: () => normalizeCopyPage,
@@ -41,13 +44,19 @@ __export(publish_exports, {
41
44
  normalizePageNav: () => normalizePageNav,
42
45
  normalizePlayground: () => normalizePlayground,
43
46
  normalizeSectionOrder: () => normalizeSectionOrder,
47
+ normalizeStaticFilesConfig: () => normalizeStaticFilesConfig,
44
48
  outputSourceFilesEnabled: () => outputSourceFilesEnabled,
45
49
  overlayDocs: () => overlayDocs,
46
50
  publish: () => publish,
51
+ readStaticFilesConfig: () => readStaticFilesConfig,
47
52
  resolveDocImages: () => resolveDocImages,
53
+ resolveDocletImages: () => resolveDocletImages,
48
54
  resolveFavicon: () => resolveFavicon,
49
55
  resolveFooter: () => resolveFooter,
50
- sourceLinkToCommentEnabled: () => sourceLinkToCommentEnabled
56
+ resolveTutorialImages: () => resolveTutorialImages,
57
+ sourceLinkToCommentEnabled: () => sourceLinkToCommentEnabled,
58
+ staticFileIncluded: () => staticFileIncluded,
59
+ staticFileOutputName: () => staticFileOutputName
51
60
  });
52
61
  module.exports = __toCommonJS(publish_exports);
53
62
  var import_promises2 = require("fs/promises");
@@ -72,18 +81,8 @@ async function writeOutputFiles(destination, files) {
72
81
  var JSDOC_TUTORIAL_TYPE_MARKDOWN = 2;
73
82
  function anchorPath() {
74
83
  if (typeof __filename === "string") return __filename;
75
- try {
76
- const getEsmUrl = new Function(
77
- "try { return import.meta && import.meta.url; } catch { return undefined; }"
78
- );
79
- const url = getEsmUrl();
80
- if (typeof url === "string" && url.startsWith("file://")) {
81
- return (0, import_node_url.fileURLToPath)(url);
82
- }
83
- } catch {
84
- }
85
84
  throw new Error(
86
- "clean-jsdoc-theme: could not determine the running module path (neither __filename nor import.meta.url resolved)."
85
+ "clean-jsdoc-theme: could not determine the running module path (__filename is unavailable)."
87
86
  );
88
87
  }
89
88
  function resolvePackageDir(name) {
@@ -460,6 +459,15 @@ function sourceLinkToCommentEnabled(opts) {
460
459
  if (opts?.templates?.default?.sourceLinkToComment === true) return true;
461
460
  return false;
462
461
  }
462
+ function cleanOutputDirEnabled(opts) {
463
+ try {
464
+ const env = require("jsdoc/env");
465
+ if (env?.conf?.templates?.default?.cleanOutputDir === false) return false;
466
+ } catch {
467
+ }
468
+ if (opts?.templates?.default?.cleanOutputDir === false) return false;
469
+ return true;
470
+ }
463
471
  function hasMarkdownPlugin(plugins) {
464
472
  if (!Array.isArray(plugins)) return false;
465
473
  return plugins.some((p) => typeof p === "string" && /(^|[\\/])markdown(\.js)?$/i.test(p.trim()));
@@ -696,62 +704,295 @@ async function collectDocs(dir) {
696
704
  return docs;
697
705
  }
698
706
  var DOC_IMAGE_RE = /(!\[[^\]]*\]\()([^)\s]+)((?:\s+"[^"]*")?\))/g;
699
- async function resolveDocImages(docs, docsDir) {
700
- if (docs.length === 0) return { docs, files: [], inlineSvgs: {} };
701
- const root = (0, import_node_path2.resolve)(docsDir);
707
+ var HTML_IMAGE_RE = /(<img\b[^>]*?\bsrc\s*=\s*(["']))([^"']*)(\2)/gi;
708
+ function createImageCollector(staticDirs = []) {
702
709
  const files = [];
703
- const seenServed = /* @__PURE__ */ new Set();
704
710
  const inlineSvgs = {};
711
+ const consumed = /* @__PURE__ */ new Set();
712
+ const seenServed = /* @__PURE__ */ new Set();
705
713
  const cache = /* @__PURE__ */ new Map();
706
- const resolveOne = async (rawSrc, docDir) => {
714
+ const warnedMisses = /* @__PURE__ */ new Set();
715
+ const resolve = async (rawSrc, baseDir) => {
707
716
  const src = rawSrc.trim();
708
717
  if (!src || isServableUrl(src) || src.startsWith("#") || src.startsWith("data:")) return null;
709
- const abs = src.startsWith("/") ? (0, import_node_path2.resolve)(src.slice(1)) : (0, import_node_path2.resolve)(docDir, src);
710
- if (cache.has(abs)) return cache.get(abs) ?? null;
711
- let bytes;
712
- try {
713
- bytes = await (0, import_promises2.readFile)(abs);
714
- } catch {
718
+ const primary = src.startsWith("/") ? (0, import_node_path2.resolve)(src.slice(1)) : (0, import_node_path2.resolve)(baseDir, src);
719
+ const candidates = [primary];
720
+ if (staticDirs.length > 0) {
721
+ const outName = src.replace(/^\/+/, "");
722
+ if (outName) for (const dir of staticDirs) candidates.push((0, import_node_path2.resolve)(dir, outName));
723
+ }
724
+ for (const abs of candidates) {
725
+ const cached = cache.get(abs);
726
+ if (cached !== void 0) {
727
+ if (cached) return cached;
728
+ continue;
729
+ }
730
+ let bytes;
731
+ try {
732
+ bytes = await (0, import_promises2.readFile)(abs);
733
+ } catch {
734
+ cache.set(abs, null);
735
+ continue;
736
+ }
737
+ const ext = (0, import_node_path2.extname)(abs);
738
+ const served = `_assets/${(0, import_node_path2.basename)(abs, ext) || "asset"}.${contentHash(bytes)}${ext}`;
739
+ if (!seenServed.has(served)) {
740
+ seenServed.add(served);
741
+ files.push({ path: served, contents: bytes });
742
+ }
743
+ const href = "/" + served;
744
+ if (ext.toLowerCase() === ".svg") {
745
+ inlineSvgs[href] = bytes.toString("utf8").replace(/<svg\b/, '<svg style="max-width:100%;height:auto;display:block"');
746
+ }
747
+ cache.set(abs, href);
748
+ consumed.add(abs);
749
+ return href;
750
+ }
751
+ if (!warnedMisses.has(src)) {
752
+ warnedMisses.add(src);
715
753
  console.warn(
716
- `clean-jsdoc-theme: could not read doc image '${src}' (resolved '${abs}'); leaving it as-is.`
754
+ `clean-jsdoc-theme: could not read image '${src}' (looked in: ${candidates.join(", ")}); leaving it as-is.`
717
755
  );
718
- cache.set(abs, null);
719
- return null;
720
- }
721
- const ext = (0, import_node_path2.extname)(abs);
722
- const served = `_assets/${(0, import_node_path2.basename)(abs, ext) || "asset"}.${contentHash(bytes)}${ext}`;
723
- if (!seenServed.has(served)) {
724
- seenServed.add(served);
725
- files.push({ path: served, contents: bytes });
726
756
  }
727
- const href = "/" + served;
728
- if (ext.toLowerCase() === ".svg") {
729
- inlineSvgs[href] = bytes.toString("utf8").replace(/<svg\b/, '<svg style="max-width:100%;height:auto;display:block"');
757
+ return null;
758
+ };
759
+ return { resolve, files, inlineSvgs, consumed };
760
+ }
761
+ var CODE_REGION_RE = /```[\s\S]*?```|~~~[\s\S]*?~~~|<pre[\s\S]*?<\/pre>|<code[^>]*>[\s\S]*?<\/code>|`[^`\n]+`/gi;
762
+ function codeRanges(content) {
763
+ const ranges = [];
764
+ for (const m of content.matchAll(CODE_REGION_RE)) {
765
+ if (m.index !== void 0) ranges.push([m.index, m.index + m[0].length]);
766
+ }
767
+ return ranges;
768
+ }
769
+ function indexInCode(idx, ranges) {
770
+ for (const [s, e] of ranges) if (idx >= s && idx < e) return true;
771
+ return false;
772
+ }
773
+ async function rewriteImageRefs(content, baseDir, collector) {
774
+ if (!content) return content;
775
+ const ranges = codeRanges(content);
776
+ const map = /* @__PURE__ */ new Map();
777
+ const collect = async (re, srcGroup) => {
778
+ for (const m of content.matchAll(re)) {
779
+ if (m.index !== void 0 && indexInCode(m.index, ranges)) continue;
780
+ const src = m[srcGroup];
781
+ if (map.has(src)) continue;
782
+ const href = await collector.resolve(src, baseDir);
783
+ if (href) map.set(src, href);
730
784
  }
731
- cache.set(abs, href);
732
- return href;
733
785
  };
786
+ await collect(DOC_IMAGE_RE, 2);
787
+ await collect(HTML_IMAGE_RE, 3);
788
+ if (map.size === 0) return content;
789
+ return content.replace(
790
+ DOC_IMAGE_RE,
791
+ (full, pre, src, post, offset) => !indexInCode(offset, ranges) && map.has(src) ? `${pre}${map.get(src)}${post}` : full
792
+ ).replace(
793
+ HTML_IMAGE_RE,
794
+ (full, pre, _quote, src, close, offset) => !indexInCode(offset, ranges) && map.has(src) ? `${pre}${map.get(src)}${close}` : full
795
+ );
796
+ }
797
+ async function resolveDocImages(docs, docsDir, collector = createImageCollector()) {
798
+ if (docs.length === 0) return { docs, files: collector.files, inlineSvgs: collector.inlineSvgs };
799
+ const root = (0, import_node_path2.resolve)(docsDir);
734
800
  const out = [];
735
801
  for (const doc of docs) {
736
802
  const docDir = (0, import_node_path2.dirname)((0, import_node_path2.resolve)(root, doc.path));
737
- const map = /* @__PURE__ */ new Map();
738
- for (const m of doc.content.matchAll(DOC_IMAGE_RE)) {
739
- const src = m[2];
740
- if (map.has(src)) continue;
741
- const href = await resolveOne(src, docDir);
742
- if (href) map.set(src, href);
803
+ const content = await rewriteImageRefs(doc.content, docDir, collector);
804
+ out.push(content === doc.content ? doc : { ...doc, content });
805
+ }
806
+ return { docs: out, files: collector.files, inlineSvgs: collector.inlineSvgs };
807
+ }
808
+ async function resolveTutorialImages(tree, tutorialsDir, collector) {
809
+ const base = (0, import_node_path2.resolve)(tutorialsDir);
810
+ const walk = async (node) => {
811
+ const content = await rewriteImageRefs(node.content, base, collector);
812
+ const children = [];
813
+ for (const child of node.children ?? []) children.push(await walk(child));
814
+ return { ...node, content, children };
815
+ };
816
+ const out = [];
817
+ for (const node of tree) out.push(await walk(node));
818
+ return out;
819
+ }
820
+ var DOCLET_IMAGE_SKIP_KEYS = /* @__PURE__ */ new Set([
821
+ "meta",
822
+ "comment",
823
+ "examples",
824
+ "tags",
825
+ "___id",
826
+ "___s"
827
+ ]);
828
+ async function rewriteDocletStrings(node, baseDir, collector) {
829
+ for (const [key, value] of Object.entries(node)) {
830
+ if (DOCLET_IMAGE_SKIP_KEYS.has(key)) continue;
831
+ if (typeof value === "string") {
832
+ if (value.includes("<img") || value.includes("![")) {
833
+ const rewritten = await rewriteImageRefs(value, baseDir, collector);
834
+ if (rewritten !== value) node[key] = rewritten;
835
+ }
836
+ } else if (Array.isArray(value)) {
837
+ for (let i = 0; i < value.length; i++) {
838
+ const item = value[i];
839
+ if (typeof item === "string") {
840
+ if (item.includes("<img") || item.includes("![")) {
841
+ const rewritten = await rewriteImageRefs(item, baseDir, collector);
842
+ if (rewritten !== item) value[i] = rewritten;
843
+ }
844
+ } else if (item && typeof item === "object") {
845
+ await rewriteDocletStrings(item, baseDir, collector);
846
+ }
847
+ }
848
+ } else if (value && typeof value === "object") {
849
+ await rewriteDocletStrings(value, baseDir, collector);
743
850
  }
744
- if (map.size === 0) {
745
- out.push(doc);
851
+ }
852
+ }
853
+ async function resolveDocletImages(data, collector) {
854
+ if (typeof data !== "function") return;
855
+ let doclets = [];
856
+ try {
857
+ doclets = data({}).get();
858
+ } catch {
859
+ try {
860
+ doclets = data().get();
861
+ } catch {
862
+ return;
863
+ }
864
+ }
865
+ if (!Array.isArray(doclets)) return;
866
+ for (const d of doclets) {
867
+ if (!d || typeof d !== "object") continue;
868
+ const meta = d.meta;
869
+ if (!meta || typeof meta.path !== "string" || meta.path.length === 0) continue;
870
+ await rewriteDocletStrings(d, meta.path, collector);
871
+ }
872
+ }
873
+ function normalizeStaticFilesConfig(raw) {
874
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
875
+ const o = raw;
876
+ const toStrArr = (v) => (Array.isArray(v) ? v : typeof v === "string" ? [v] : []).filter((s) => typeof s === "string" && s.trim().length > 0).map((s) => s.trim());
877
+ const include = toStrArr(o.include);
878
+ if (include.length === 0) return void 0;
879
+ const includePattern = typeof o.includePattern === "string" && o.includePattern.trim().length > 0 ? o.includePattern : void 0;
880
+ const excludePattern = typeof o.excludePattern === "string" && o.excludePattern.trim().length > 0 ? o.excludePattern : void 0;
881
+ return {
882
+ include,
883
+ exclude: toStrArr(o.exclude),
884
+ ...includePattern ? { includePattern } : {},
885
+ ...excludePattern ? { excludePattern } : {}
886
+ };
887
+ }
888
+ function readStaticFilesConfig(opts) {
889
+ try {
890
+ const env = require("jsdoc/env");
891
+ const fromEnv = normalizeStaticFilesConfig(env?.conf?.templates?.default?.staticFiles);
892
+ if (fromEnv) return fromEnv;
893
+ } catch {
894
+ }
895
+ return normalizeStaticFilesConfig(opts?.templates?.default?.staticFiles);
896
+ }
897
+ function staticFileOutputName(absFile, includeRootAbs) {
898
+ const norm = (p) => p.replace(/\\/g, "/").replace(/\/+$/, "");
899
+ const f = norm(absFile);
900
+ const root = norm(includeRootAbs);
901
+ const baseOf = (p) => p.slice(p.lastIndexOf("/") + 1);
902
+ if (f === root) return baseOf(f);
903
+ const prefix = root + "/";
904
+ return f.toLowerCase().startsWith(prefix.toLowerCase()) ? f.slice(prefix.length) : baseOf(f);
905
+ }
906
+ function staticFileIncluded(absFile, config) {
907
+ const norm = (p) => (0, import_node_path2.resolve)(p).replace(/\\/g, "/");
908
+ const fn = norm(absFile);
909
+ if (config.includePattern) {
910
+ try {
911
+ if (!new RegExp(config.includePattern).test(fn)) return false;
912
+ } catch {
913
+ }
914
+ }
915
+ if (config.excludePattern) {
916
+ try {
917
+ if (new RegExp(config.excludePattern).test(fn)) return false;
918
+ } catch {
919
+ }
920
+ }
921
+ for (const ex of config.exclude) {
922
+ const exAbs = norm(ex);
923
+ if (fn === exAbs || fn.toLowerCase().startsWith(exAbs.toLowerCase() + "/")) return false;
924
+ }
925
+ return true;
926
+ }
927
+ var STATIC_DIR_SKIP = /* @__PURE__ */ new Set(["node_modules", ".git", ".svn", ".hg"]);
928
+ async function collectStaticFiles(config, warn = (m) => console.warn(m)) {
929
+ const files = [];
930
+ const searchDirs = /* @__PURE__ */ new Set();
931
+ const seenOutput = /* @__PURE__ */ new Set();
932
+ for (const inc of config.include) {
933
+ const root = (0, import_node_path2.resolve)(inc);
934
+ let st;
935
+ try {
936
+ st = await (0, import_promises2.stat)(root);
937
+ } catch {
938
+ warn(
939
+ `clean-jsdoc-theme: staticFiles include '${inc}' (resolved '${root}') was not found; skipping it.`
940
+ );
746
941
  continue;
747
942
  }
748
- const content = doc.content.replace(
749
- DOC_IMAGE_RE,
750
- (full, pre, src, post) => map.has(src) ? `${pre}${map.get(src)}${post}` : full
751
- );
752
- out.push({ ...doc, content });
943
+ if (st.isDirectory()) {
944
+ searchDirs.add(root);
945
+ const walk = async (absDir) => {
946
+ let entries;
947
+ try {
948
+ entries = await (0, import_promises2.readdir)(absDir, { withFileTypes: true });
949
+ } catch {
950
+ return;
951
+ }
952
+ for (const entry of entries) {
953
+ if (entry.name.startsWith(".")) continue;
954
+ const abs = (0, import_node_path2.join)(absDir, entry.name);
955
+ if (entry.isDirectory()) {
956
+ if (!STATIC_DIR_SKIP.has(entry.name)) await walk(abs);
957
+ continue;
958
+ }
959
+ if (!entry.isFile()) continue;
960
+ if (!staticFileIncluded(abs, config)) continue;
961
+ const outputPath = staticFileOutputName(abs, root);
962
+ if (seenOutput.has(outputPath)) continue;
963
+ let contents;
964
+ try {
965
+ contents = await (0, import_promises2.readFile)(abs);
966
+ } catch (err) {
967
+ warn(
968
+ `clean-jsdoc-theme: could not read static file '${abs}' \u2014 ${err.message}; skipping.`
969
+ );
970
+ continue;
971
+ }
972
+ seenOutput.add(outputPath);
973
+ files.push({ outputPath, absSource: (0, import_node_path2.resolve)(abs), contents });
974
+ }
975
+ };
976
+ await walk(root);
977
+ } else if (st.isFile()) {
978
+ searchDirs.add((0, import_node_path2.dirname)(root));
979
+ if (!staticFileIncluded(root, config)) continue;
980
+ const outputPath = staticFileOutputName(root, root);
981
+ if (!seenOutput.has(outputPath)) {
982
+ try {
983
+ const contents = await (0, import_promises2.readFile)(root);
984
+ seenOutput.add(outputPath);
985
+ files.push({ outputPath, absSource: (0, import_node_path2.resolve)(root), contents });
986
+ } catch (err) {
987
+ warn(
988
+ `clean-jsdoc-theme: could not read static file '${root}' \u2014 ${err.message}; skipping.`
989
+ );
990
+ }
991
+ }
992
+ }
753
993
  }
754
- return { docs: out, files, inlineSvgs };
994
+ files.sort((a, b) => a.outputPath.localeCompare(b.outputPath));
995
+ return { files, searchDirs: [...searchDirs] };
755
996
  }
756
997
  function overlayDocs(base, locale) {
757
998
  const byPath = new Map(base.docs.map((d) => [d.path, d]));
@@ -838,6 +1079,8 @@ async function publish(data, opts, tutorials) {
838
1079
  assertMarkdownPlugin();
839
1080
  const color = Boolean(process.stdout.isTTY) && opts.nocolor !== true;
840
1081
  const docsDir = typeof opts.docs === "string" && opts.docs.trim().length > 0 ? opts.docs.trim() : void 0;
1082
+ const tutorialsDir = typeof opts.tutorials === "string" && opts.tutorials.trim().length > 0 ? opts.tutorials.trim() : void 0;
1083
+ const staticCfg = readStaticFilesConfig(opts);
841
1084
  const pkgPromise = resolvePkg(data, opts);
842
1085
  const sourcesPromise = outputSourceFilesEnabled(opts) ? collectSourceFiles(data) : Promise.resolve([]);
843
1086
  const docsPromise = docsDir ? collectDocs(docsDir) : Promise.resolve([]);
@@ -896,30 +1139,34 @@ async function publish(data, opts, tutorials) {
896
1139
  const readme = typeof opts.readme === "string" && opts.readme.length > 0 ? opts.readme : void 0;
897
1140
  const tutorialTree = normalizeTutorials(tutorials);
898
1141
  const sourceLinkToComment = sourceLinkToCommentEnabled(opts);
899
- const { sources, docs, docImageFiles, inlineSvgs } = await progress.stage(
900
- "Reading sources & docs",
1142
+ const staticFiles = staticCfg ? await progress.stage(
1143
+ "Reading static files",
1144
+ () => collectStaticFiles(staticCfg, (m) => console.warn(m))
1145
+ ) : void 0;
1146
+ const images = createImageCollector(staticFiles?.searchDirs ?? []);
1147
+ const { sources, docs } = await progress.stage("Reading sources & docs", async () => {
1148
+ const [srcs, rawDocs] = await Promise.all([sourcesPromise, docsPromise]);
1149
+ const base = docsDir ? await resolveDocImages(rawDocs, docsDir, images) : { docs: rawDocs };
1150
+ if (!buildSpec?.docsDir) return { sources: srcs, docs: base.docs };
1151
+ const localeRaw = await collectDocs(buildSpec.docsDir);
1152
+ const locale = await resolveDocImages(localeRaw, buildSpec.docsDir, images);
1153
+ const merged = overlayDocs(
1154
+ { docs: base.docs, files: [], inlineSvgs: {} },
1155
+ { docs: locale.docs, files: [], inlineSvgs: {} }
1156
+ );
1157
+ return { sources: srcs, docs: merged.docs };
1158
+ });
1159
+ const { tutorialTree: resolvedTutorials, readme: resolvedReadme } = await progress.stage(
1160
+ "Resolving prose images",
901
1161
  async () => {
902
- const [srcs, rawDocs] = await Promise.all([sourcesPromise, docsPromise]);
903
- const base = docsDir ? await resolveDocImages(rawDocs, docsDir) : { docs: rawDocs, files: [], inlineSvgs: {} };
904
- if (!buildSpec?.docsDir) {
905
- return {
906
- sources: srcs,
907
- docs: base.docs,
908
- docImageFiles: base.files,
909
- inlineSvgs: base.inlineSvgs
910
- };
911
- }
912
- const localeRaw = await collectDocs(buildSpec.docsDir);
913
- const locale = await resolveDocImages(localeRaw, buildSpec.docsDir);
914
- const merged = overlayDocs(base, locale);
915
- return {
916
- sources: srcs,
917
- docs: merged.docs,
918
- docImageFiles: merged.files,
919
- inlineSvgs: merged.inlineSvgs
920
- };
1162
+ const tree = tutorialsDir && tutorialTree.length > 0 ? await resolveTutorialImages(tutorialTree, tutorialsDir, images) : tutorialTree;
1163
+ const md = readme ? await rewriteImageRefs(readme, process.cwd(), images) : readme;
1164
+ await resolveDocletImages(data, images);
1165
+ return { tutorialTree: tree, readme: md };
921
1166
  }
922
1167
  );
1168
+ const imageFiles = images.files;
1169
+ const allInlineSvgs = images.inlineSvgs;
923
1170
  const docGroups = normalizeDocGroups(opts.docGroups);
924
1171
  const defaultDocGroup = typeof opts.defaultDocGroup === "string" && opts.defaultDocGroup.trim().length > 0 ? opts.defaultDocGroup.trim() : void 0;
925
1172
  const sectionOrder = normalizeSectionOrder(opts.sectionOrder);
@@ -928,8 +1175,8 @@ async function publish(data, opts, tutorials) {
928
1175
  const playground = normalizePlayground(opts.playground);
929
1176
  const siteOptions = {
930
1177
  ...pkg ? { pkg } : {},
931
- ...readme ? { readme } : {},
932
- ...tutorialTree.length > 0 ? { tutorials: tutorialTree } : {},
1178
+ ...resolvedReadme ? { readme: resolvedReadme } : {},
1179
+ ...resolvedTutorials.length > 0 ? { tutorials: resolvedTutorials } : {},
933
1180
  ...sources.length > 0 ? { sources } : {},
934
1181
  ...sources.length > 0 && sourceLinkToComment ? { sourceLinkToComment } : {},
935
1182
  ...docs.length > 0 ? { docs } : {},
@@ -991,7 +1238,11 @@ async function publish(data, opts, tutorials) {
991
1238
  },
992
1239
  destination: absoluteDestination,
993
1240
  islandCacheDir,
994
- inlineSvgs,
1241
+ inlineSvgs: allInlineSvgs,
1242
+ // Emit sitemap.xml when a public site URL is configured (the protocol needs
1243
+ // absolute URLs). In a localized build each locale's basePath yields that
1244
+ // locale's URLs, so each locale dir gets its own sitemap.
1245
+ ...nonEmptyString(opts.siteUrl) ? { siteUrl: opts.siteUrl.trim() } : {},
995
1246
  // Build mode: render chrome in the locale (SSR provider + island seeding)
996
1247
  // and, with >1 locale, mount the language switcher.
997
1248
  ...buildSpec ? {
@@ -1005,13 +1256,44 @@ async function publish(data, opts, tutorials) {
1005
1256
  } : {}
1006
1257
  })
1007
1258
  );
1008
- const outputFiles = [
1259
+ const generatedFiles = [
1009
1260
  ...result.files,
1010
1261
  ...logoFiles,
1011
1262
  ...customAssets.files,
1012
- ...docImageFiles,
1263
+ ...imageFiles,
1013
1264
  ...favicon?.files ?? []
1014
1265
  ];
1266
+ const staticOutputFiles = [];
1267
+ if (staticFiles) {
1268
+ const generatedPaths = new Set(generatedFiles.map((f) => f.path));
1269
+ const RESERVED_PREFIXES = ["_assets/", "_islands/", "pagefind/"];
1270
+ let skippedConsumed = 0;
1271
+ for (const f of staticFiles.files) {
1272
+ if (images.consumed.has(f.absSource)) {
1273
+ skippedConsumed++;
1274
+ continue;
1275
+ }
1276
+ if (generatedPaths.has(f.outputPath) || RESERVED_PREFIXES.some((p) => f.outputPath.startsWith(p))) {
1277
+ console.warn(
1278
+ `clean-jsdoc-theme: static file '${f.outputPath}' would clobber generated output; skipping it.`
1279
+ );
1280
+ continue;
1281
+ }
1282
+ staticOutputFiles.push({ path: f.outputPath, contents: f.contents });
1283
+ }
1284
+ if (staticFiles.files.length > 0) {
1285
+ console.log(
1286
+ `clean-jsdoc-theme: staticFiles \u2014 copied ${staticOutputFiles.length} file(s) verbatim` + (skippedConsumed > 0 ? ` (${skippedConsumed} served hashed via _assets/)` : "") + "."
1287
+ );
1288
+ }
1289
+ }
1290
+ const outputFiles = [...generatedFiles, ...staticOutputFiles];
1291
+ if (!buildSpec && cleanOutputDirEnabled(opts)) {
1292
+ await progress.stage(
1293
+ "Cleaning output",
1294
+ () => (0, import_promises2.rm)(absoluteDestination, { recursive: true, force: true })
1295
+ );
1296
+ }
1015
1297
  await progress.stage("Writing files", () => writeOutputFiles(absoluteDestination, outputFiles));
1016
1298
  const zlib = await import("zlib");
1017
1299
  const gzipSizer = (b) => zlib.gzipSync(b).length;
@@ -1051,8 +1333,11 @@ async function publish(data, opts, tutorials) {
1051
1333
  }
1052
1334
  // Annotate the CommonJS export names for ESM import in node:
1053
1335
  0 && (module.exports = {
1336
+ cleanOutputDirEnabled,
1054
1337
  collectDocs,
1338
+ collectStaticFiles,
1055
1339
  computeRelPaths,
1340
+ createImageCollector,
1056
1341
  hasMarkdownPlugin,
1057
1342
  normalizeColors,
1058
1343
  normalizeCopyPage,
@@ -1062,12 +1347,18 @@ async function publish(data, opts, tutorials) {
1062
1347
  normalizePageNav,
1063
1348
  normalizePlayground,
1064
1349
  normalizeSectionOrder,
1350
+ normalizeStaticFilesConfig,
1065
1351
  outputSourceFilesEnabled,
1066
1352
  overlayDocs,
1067
1353
  publish,
1354
+ readStaticFilesConfig,
1068
1355
  resolveDocImages,
1356
+ resolveDocletImages,
1069
1357
  resolveFavicon,
1070
1358
  resolveFooter,
1071
- sourceLinkToCommentEnabled
1359
+ resolveTutorialImages,
1360
+ sourceLinkToCommentEnabled,
1361
+ staticFileIncluded,
1362
+ staticFileOutputName
1072
1363
  });
1073
1364
  //# sourceMappingURL=publish.js.map