clean-jsdoc-theme 5.0.0-alpha.3 → 5.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -42,8 +42,13 @@ of every page for LLMs. No CSS or build config required to get started.
42
42
  [Pagefind](https://pagefind.app/) full-text index.
43
43
  - **Guides + API in one site** — hand-written Markdown guides and the
44
44
  auto-generated reference share one sidebar and one search.
45
+ - **Localization built in** — declare your locales and the `clean-jsdoc` CLI
46
+ builds one static site per language (translated UI, API descriptions, and
47
+ prose) with a header language switcher, per-language fonts, and `hreflang`.
45
48
  - **LLM-friendly** — every page ships a clean companion `.md`, plus a
46
- copy-page button to hand any page to Claude / ChatGPT / Perplexity.
49
+ copy-page button to hand any page to Claude / ChatGPT / Perplexity. A
50
+ downloadable [skill](https://ankdev.me/clean-jsdoc-theme/theme/llm-skill) turns
51
+ any coding assistant into a setup expert.
47
52
  - **Polished by default** — light/dark OKLCH themes, Google Fonts, shiki syntax
48
53
  highlighting, a Monaco source viewer, and `Source: file:line` links.
49
54
 
@@ -1,4 +1,4 @@
1
- import { ThemeColors, CopyPageConfig, PageNavConfig, SiteLogo, OutputFile } from '@clean-jsdoc-theme/dwar';
1
+ import { OutputFile, ThemeColors, CopyPageConfig, PageNavConfig, SiteLogo } from '@clean-jsdoc-theme/dwar';
2
2
  import { DocInput, MenuItem } from '@clean-jsdoc-theme/setu';
3
3
 
4
4
  interface JSDocOpts {
@@ -276,6 +276,22 @@ declare function resolveDocImages(docs: DocInput[], docsDir: string): Promise<{
276
276
  files: OutputFile[];
277
277
  inlineSvgs: Record<string, string>;
278
278
  }>;
279
+ /** The output of {@link resolveDocImages}: resolved docs + their image assets. */
280
+ interface ResolvedDocs {
281
+ docs: DocInput[];
282
+ files: OutputFile[];
283
+ inlineSvgs: Record<string, string>;
284
+ }
285
+ /**
286
+ * Overlay a locale's resolved docs over the default set (the per-locale docs
287
+ * track). A locale page WINS over the default page with the same `path`; a
288
+ * default page absent from the locale falls back (stays). Image asset files are
289
+ * deduped by served path (same content-hashed name → one copy), and inline SVGs
290
+ * merge locale-over-default. Output docs are re-sorted by `path` so the manifest
291
+ * stays stable regardless of merge order. Pure — the I/O already happened in the
292
+ * two {@link resolveDocImages} calls that produced `base`/`locale`.
293
+ */
294
+ declare function overlayDocs(base: ResolvedDocs, locale: ResolvedDocs): ResolvedDocs;
279
295
  /**
280
296
  * Validate `opts.docGroups` into a clean `string[]`, or `undefined` to fall back
281
297
  * to setu's default doc-group order. Mirrors {@link normalizeSectionOrder}:
@@ -284,4 +300,4 @@ declare function resolveDocImages(docs: DocInput[], docsDir: string): Promise<{
284
300
  declare function normalizeDocGroups(raw: unknown): string[] | undefined;
285
301
  declare function publish(data: unknown, opts: JSDocOpts, tutorials?: unknown): Promise<void>;
286
302
 
287
- export { collectDocs, computeRelPaths, hasMarkdownPlugin, normalizeColors, normalizeCopyPage, normalizeDocGroups, normalizeMenu, normalizePageNav, normalizeSectionOrder, outputSourceFilesEnabled, publish, resolveDocImages, sourceLinkToCommentEnabled };
303
+ export { type ResolvedDocs, collectDocs, computeRelPaths, hasMarkdownPlugin, normalizeColors, normalizeCopyPage, normalizeDocGroups, normalizeMenu, normalizePageNav, normalizeSectionOrder, outputSourceFilesEnabled, overlayDocs, publish, resolveDocImages, sourceLinkToCommentEnabled };
package/dist/publish.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ThemeColors, CopyPageConfig, PageNavConfig, SiteLogo, OutputFile } from '@clean-jsdoc-theme/dwar';
1
+ import { OutputFile, ThemeColors, CopyPageConfig, PageNavConfig, SiteLogo } from '@clean-jsdoc-theme/dwar';
2
2
  import { DocInput, MenuItem } from '@clean-jsdoc-theme/setu';
3
3
 
4
4
  interface JSDocOpts {
@@ -276,6 +276,22 @@ declare function resolveDocImages(docs: DocInput[], docsDir: string): Promise<{
276
276
  files: OutputFile[];
277
277
  inlineSvgs: Record<string, string>;
278
278
  }>;
279
+ /** The output of {@link resolveDocImages}: resolved docs + their image assets. */
280
+ interface ResolvedDocs {
281
+ docs: DocInput[];
282
+ files: OutputFile[];
283
+ inlineSvgs: Record<string, string>;
284
+ }
285
+ /**
286
+ * Overlay a locale's resolved docs over the default set (the per-locale docs
287
+ * track). A locale page WINS over the default page with the same `path`; a
288
+ * default page absent from the locale falls back (stays). Image asset files are
289
+ * deduped by served path (same content-hashed name → one copy), and inline SVGs
290
+ * merge locale-over-default. Output docs are re-sorted by `path` so the manifest
291
+ * stays stable regardless of merge order. Pure — the I/O already happened in the
292
+ * two {@link resolveDocImages} calls that produced `base`/`locale`.
293
+ */
294
+ declare function overlayDocs(base: ResolvedDocs, locale: ResolvedDocs): ResolvedDocs;
279
295
  /**
280
296
  * Validate `opts.docGroups` into a clean `string[]`, or `undefined` to fall back
281
297
  * to setu's default doc-group order. Mirrors {@link normalizeSectionOrder}:
@@ -284,4 +300,4 @@ declare function resolveDocImages(docs: DocInput[], docsDir: string): Promise<{
284
300
  declare function normalizeDocGroups(raw: unknown): string[] | undefined;
285
301
  declare function publish(data: unknown, opts: JSDocOpts, tutorials?: unknown): Promise<void>;
286
302
 
287
- export { collectDocs, computeRelPaths, hasMarkdownPlugin, normalizeColors, normalizeCopyPage, normalizeDocGroups, normalizeMenu, normalizePageNav, normalizeSectionOrder, outputSourceFilesEnabled, publish, resolveDocImages, sourceLinkToCommentEnabled };
303
+ export { type ResolvedDocs, collectDocs, computeRelPaths, hasMarkdownPlugin, normalizeColors, normalizeCopyPage, normalizeDocGroups, normalizeMenu, normalizePageNav, normalizeSectionOrder, outputSourceFilesEnabled, overlayDocs, publish, resolveDocImages, sourceLinkToCommentEnabled };
package/dist/publish.js CHANGED
@@ -40,6 +40,7 @@ __export(publish_exports, {
40
40
  normalizePageNav: () => normalizePageNav,
41
41
  normalizeSectionOrder: () => normalizeSectionOrder,
42
42
  outputSourceFilesEnabled: () => outputSourceFilesEnabled,
43
+ overlayDocs: () => overlayDocs,
43
44
  publish: () => publish,
44
45
  resolveDocImages: () => resolveDocImages,
45
46
  sourceLinkToCommentEnabled: () => sourceLinkToCommentEnabled
@@ -137,7 +138,7 @@ async function loadDep(name, requiredExports) {
137
138
  }
138
139
  return mod;
139
140
  }
140
- var loadSetu = () => loadDep("@clean-jsdoc-theme/setu", ["generateSite"]);
141
+ var loadSetu = () => loadDep("@clean-jsdoc-theme/setu", ["generateSite", "stampSite"]);
141
142
  var loadDwar = () => loadDep("@clean-jsdoc-theme/dwar", ["render", "runPagefindAgainstDir"]);
142
143
  var loadUtils = () => loadDep("@clean-jsdoc-theme/utils", [
143
144
  "validateThemeOpts",
@@ -145,7 +146,8 @@ var loadUtils = () => loadDep("@clean-jsdoc-theme/utils", [
145
146
  "formatDiagnostics",
146
147
  "formatBuildReport",
147
148
  "normalizeBasePath",
148
- "withBase"
149
+ "withBase",
150
+ "toExtractManifest"
149
151
  ]);
150
152
  var loadOra = async () => {
151
153
  try {
@@ -207,7 +209,16 @@ var defaultTheme = {
207
209
  },
208
210
  basePath: "/"
209
211
  };
210
- function resolveTheme(opts, siteName, fonts, basePath) {
212
+ function resolveFontSet(fonts, locale) {
213
+ const base = defaultTheme.tokens.fonts;
214
+ const override = locale && fonts.locales?.[locale] || {};
215
+ return {
216
+ heading: override.heading ?? fonts.heading ?? base.heading,
217
+ body: override.body ?? fonts.body ?? base.body,
218
+ mono: override.mono ?? fonts.mono ?? base.mono
219
+ };
220
+ }
221
+ function resolveTheme(opts, siteName, fonts, basePath, locale) {
211
222
  const aiPrompt = typeof opts.aiPrompt === "string" && opts.aiPrompt.trim() ? opts.aiPrompt.trim() : void 0;
212
223
  const copyPage = normalizeCopyPage(opts.copyPage);
213
224
  const pageNav = normalizePageNav(opts.pageNav);
@@ -223,11 +234,7 @@ function resolveTheme(opts, siteName, fonts, basePath) {
223
234
  ...defaultTheme.tokens,
224
235
  colors: { ...defaultTheme.tokens.colors, ...colors ?? {} },
225
236
  darkColors: { ...defaultTheme.tokens.darkColors, ...darkColors ?? {} },
226
- fonts: {
227
- heading: fonts.heading ?? defaultTheme.tokens.fonts.heading,
228
- body: fonts.body ?? defaultTheme.tokens.fonts.body,
229
- mono: fonts.mono ?? defaultTheme.tokens.fonts.mono
230
- },
237
+ fonts: resolveFontSet(fonts, locale),
231
238
  ...siteName ? { siteName } : {}
232
239
  }
233
240
  };
@@ -385,9 +392,7 @@ function sourceLinkToCommentEnabled(opts) {
385
392
  }
386
393
  function hasMarkdownPlugin(plugins) {
387
394
  if (!Array.isArray(plugins)) return false;
388
- return plugins.some(
389
- (p) => typeof p === "string" && /(^|[\\/])markdown(\.js)?$/i.test(p.trim())
390
- );
395
+ return plugins.some((p) => typeof p === "string" && /(^|[\\/])markdown(\.js)?$/i.test(p.trim()));
391
396
  }
392
397
  function assertMarkdownPlugin() {
393
398
  let conf;
@@ -636,6 +641,17 @@ async function resolveDocImages(docs, docsDir) {
636
641
  }
637
642
  return { docs: out, files, inlineSvgs };
638
643
  }
644
+ function overlayDocs(base, locale) {
645
+ const byPath = new Map(base.docs.map((d) => [d.path, d]));
646
+ for (const d of locale.docs) byPath.set(d.path, d);
647
+ const filesByPath = /* @__PURE__ */ new Map();
648
+ for (const f of [...base.files, ...locale.files]) filesByPath.set(f.path, f);
649
+ return {
650
+ docs: [...byPath.values()].sort((a, b) => a.path.localeCompare(b.path)),
651
+ files: [...filesByPath.values()],
652
+ inlineSvgs: { ...base.inlineSvgs, ...locale.inlineSvgs }
653
+ };
654
+ }
639
655
  function normalizeDocGroups(raw) {
640
656
  return normalizeSectionOrder(raw);
641
657
  }
@@ -675,8 +691,33 @@ function createBuildProgress(ora) {
675
691
  }
676
692
  return { stage };
677
693
  }
694
+ function readBuildSpec() {
695
+ const path = process.env.CLEAN_JSDOC_THEME_BUILD?.trim();
696
+ if (!path) return null;
697
+ const spec = JSON.parse((0, import_node_fs.readFileSync)(path, "utf8"));
698
+ if (typeof spec.version === "number" && spec.version !== 1) {
699
+ throw new Error(
700
+ `clean-jsdoc-theme: build spec version ${spec.version} unsupported (expected 1) \u2014 update clean-jsdoc-theme and aadesh together.`
701
+ );
702
+ }
703
+ if (typeof spec.destination !== "string" || typeof spec.basePath !== "string") {
704
+ throw new Error(`clean-jsdoc-theme: malformed build spec at "${path}".`);
705
+ }
706
+ return {
707
+ locale: typeof spec.locale === "string" ? spec.locale : "",
708
+ defaultLocale: typeof spec.defaultLocale === "string" ? spec.defaultLocale : "en",
709
+ apiMessages: spec.apiMessages ?? {},
710
+ chromeMessages: spec.chromeMessages ?? {},
711
+ destination: spec.destination,
712
+ basePath: spec.basePath,
713
+ siteBasePath: typeof spec.siteBasePath === "string" ? spec.siteBasePath : "/",
714
+ locales: Array.isArray(spec.locales) ? spec.locales : [],
715
+ ...typeof spec.docsDir === "string" && spec.docsDir ? { docsDir: spec.docsDir } : {}
716
+ };
717
+ }
678
718
  async function publish(data, opts, tutorials) {
679
- const destination = opts.destination;
719
+ const buildSpec = readBuildSpec();
720
+ const destination = buildSpec?.destination ?? opts.destination;
680
721
  if (!destination || typeof destination !== "string") {
681
722
  throw new Error(
682
723
  'clean-jsdoc-theme publish: opts.destination is required (set "opts.destination" in your jsdoc.json).'
@@ -691,7 +732,7 @@ async function publish(data, opts, tutorials) {
691
732
  const ora = opts.progress === false ? null : await loadOra();
692
733
  const progress = createBuildProgress(ora);
693
734
  const [
694
- { generateSite },
735
+ { generateSite, stampSite },
695
736
  { render, runPagefindAgainstDir },
696
737
  {
697
738
  validateThemeOpts,
@@ -699,7 +740,8 @@ async function publish(data, opts, tutorials) {
699
740
  formatDiagnostics,
700
741
  formatBuildReport,
701
742
  normalizeBasePath,
702
- withBase
743
+ withBase,
744
+ toExtractManifest
703
745
  }
704
746
  // Loaded sequentially (not Promise.all) so the spinner can step its label
705
747
  // through each module — the evaluation of these large ESM bundles is the
@@ -714,7 +756,7 @@ async function publish(data, opts, tutorials) {
714
756
  const utils = await loadUtils();
715
757
  return [setu, dwar, utils];
716
758
  });
717
- const basePath = normalizeBasePath(opts.basePath);
759
+ const basePath = normalizeBasePath(buildSpec?.basePath ?? opts.basePath);
718
760
  const hrefForServed = (servedPath) => withBase(basePath, "/" + servedPath);
719
761
  const fontResolver = createGoogleFontResolver();
720
762
  const { value, diagnostics } = await progress.stage(
@@ -745,12 +787,23 @@ async function publish(data, opts, tutorials) {
745
787
  "Reading sources & docs",
746
788
  async () => {
747
789
  const [srcs, rawDocs] = await Promise.all([sourcesPromise, docsPromise]);
748
- const resolved = docsDir ? await resolveDocImages(rawDocs, docsDir) : { docs: rawDocs, files: [], inlineSvgs: {} };
790
+ const base = docsDir ? await resolveDocImages(rawDocs, docsDir) : { docs: rawDocs, files: [], inlineSvgs: {} };
791
+ if (!buildSpec?.docsDir) {
792
+ return {
793
+ sources: srcs,
794
+ docs: base.docs,
795
+ docImageFiles: base.files,
796
+ inlineSvgs: base.inlineSvgs
797
+ };
798
+ }
799
+ const localeRaw = await collectDocs(buildSpec.docsDir);
800
+ const locale = await resolveDocImages(localeRaw, buildSpec.docsDir);
801
+ const merged = overlayDocs(base, locale);
749
802
  return {
750
803
  sources: srcs,
751
- docs: resolved.docs,
752
- docImageFiles: resolved.files,
753
- inlineSvgs: resolved.inlineSvgs
804
+ docs: merged.docs,
805
+ docImageFiles: merged.files,
806
+ inlineSvgs: merged.inlineSvgs
754
807
  };
755
808
  }
756
809
  );
@@ -759,7 +812,7 @@ async function publish(data, opts, tutorials) {
759
812
  const sectionOrder = normalizeSectionOrder(opts.sectionOrder);
760
813
  const menu = normalizeMenu(opts.menu);
761
814
  const clubSidebarItems = opts.clubSidebarItems === true;
762
- const manifest = await progress.stage("Generating pages", () => generateSite(data, {
815
+ const siteOptions = {
763
816
  ...pkg ? { pkg } : {},
764
817
  ...readme ? { readme } : {},
765
818
  ...tutorialTree.length > 0 ? { tutorials: tutorialTree } : {},
@@ -771,7 +824,23 @@ async function publish(data, opts, tutorials) {
771
824
  ...sectionOrder ? { sectionOrder } : {},
772
825
  ...menu ? { menu } : {},
773
826
  ...clubSidebarItems ? { clubSidebarItems } : {}
774
- }));
827
+ };
828
+ const manifest = await progress.stage(
829
+ "Generating pages",
830
+ () => buildSpec ? stampSite(data, buildSpec.apiMessages, siteOptions) : generateSite(data, siteOptions)
831
+ );
832
+ const extractPath = process.env.CLEAN_JSDOC_THEME_EXTRACT?.trim();
833
+ if (extractPath) {
834
+ const target = (0, import_node_path2.resolve)(extractPath);
835
+ await progress.stage("Writing extract manifest", async () => {
836
+ await (0, import_promises2.mkdir)((0, import_node_path2.dirname)(target), { recursive: true });
837
+ await (0, import_promises2.writeFile)(target, JSON.stringify(toExtractManifest(manifest), null, 2) + "\n", "utf8");
838
+ });
839
+ console.log(
840
+ `clean-jsdoc-theme: extract mode \u2014 wrote ${manifest.slots?.length ?? 0} slot(s) to ${target}`
841
+ );
842
+ return;
843
+ }
775
844
  const { siteName, files: logoFiles } = await prepareSiteName(value.siteName, hrefForServed);
776
845
  const notGoogle = new Set(
777
846
  diagnostics.list.filter((d) => d.code === "fonts/not-google" && d.path).map((d) => d.path)
@@ -779,23 +848,44 @@ async function publish(data, opts, tutorials) {
779
848
  const fonts = { ...value.fonts };
780
849
  if (notGoogle.has("fonts.heading")) delete fonts.heading;
781
850
  if (notGoogle.has("fonts.body")) delete fonts.body;
851
+ if (fonts.locales) {
852
+ const cleaned = {};
853
+ for (const [loc, set] of Object.entries(fonts.locales)) {
854
+ const s = { ...set };
855
+ if (notGoogle.has(`fonts.${loc}:heading`)) delete s.heading;
856
+ if (notGoogle.has(`fonts.${loc}:body`)) delete s.body;
857
+ cleaned[loc] = s;
858
+ }
859
+ fonts.locales = cleaned;
860
+ }
782
861
  const customAssets = await resolveCustomAssets(opts, hrefForServed);
783
862
  const absoluteDestination = (0, import_node_path2.resolve)(destination);
784
863
  const islandCacheDir = (0, import_node_path2.resolve)(process.cwd(), "node_modules", ".cache", "clean-jsdoc-theme");
785
864
  const result = await progress.stage(
786
865
  "Rendering site",
787
866
  () => render(manifest, {
788
- theme: { ...resolveTheme(opts, siteName, fonts, basePath), ...customAssets.theme },
867
+ theme: {
868
+ ...resolveTheme(opts, siteName, fonts, basePath, buildSpec?.locale),
869
+ ...customAssets.theme
870
+ },
789
871
  destination: absoluteDestination,
790
872
  islandCacheDir,
791
- inlineSvgs
873
+ inlineSvgs,
874
+ // Build mode: render chrome in the locale (SSR provider + island seeding)
875
+ // and, with >1 locale, mount the language switcher.
876
+ ...buildSpec ? {
877
+ locale: {
878
+ code: buildSpec.locale,
879
+ defaultLocale: buildSpec.defaultLocale,
880
+ messages: buildSpec.chromeMessages,
881
+ siteBasePath: buildSpec.siteBasePath,
882
+ locales: buildSpec.locales.map((l) => ({ code: l.code, label: l.name ?? l.code }))
883
+ }
884
+ } : {}
792
885
  })
793
886
  );
794
887
  const outputFiles = [...result.files, ...logoFiles, ...customAssets.files, ...docImageFiles];
795
- await progress.stage(
796
- "Writing files",
797
- () => writeOutputFiles(absoluteDestination, outputFiles)
798
- );
888
+ await progress.stage("Writing files", () => writeOutputFiles(absoluteDestination, outputFiles));
799
889
  const zlib = await import("zlib");
800
890
  const gzipSizer = (b) => zlib.gzipSync(b).length;
801
891
  console.log(
@@ -821,9 +911,7 @@ async function publish(data, opts, tutorials) {
821
911
  () => runPagefindAgainstDir(absoluteDestination)
822
912
  );
823
913
  } catch (err) {
824
- console.warn(
825
- `clean-jsdoc-theme: pagefind step skipped (optional) \u2014 ${err.message}`
826
- );
914
+ console.warn(`clean-jsdoc-theme: pagefind step skipped (optional) \u2014 ${err.message}`);
827
915
  }
828
916
  }
829
917
  // Annotate the CommonJS export names for ESM import in node:
@@ -838,6 +926,7 @@ async function publish(data, opts, tutorials) {
838
926
  normalizePageNav,
839
927
  normalizeSectionOrder,
840
928
  outputSourceFilesEnabled,
929
+ overlayDocs,
841
930
  publish,
842
931
  resolveDocImages,
843
932
  sourceLinkToCommentEnabled