doccupine 0.0.157 → 0.0.159

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.
Files changed (153) hide show
  1. package/README.md +52 -2
  2. package/dist/generator/app-scaffolder.js +11 -3
  3. package/dist/generator/generated-page-publisher.d.ts +6 -6
  4. package/dist/generator/generated-page-publisher.js +7 -5
  5. package/dist/generator/icon-registry-generator.d.ts +8 -5
  6. package/dist/generator/icon-registry-generator.js +19 -11
  7. package/dist/generator/mdx-pass-builder.d.ts +4 -4
  8. package/dist/generator/mdx-pass-builder.js +8 -1
  9. package/dist/generator/mdx-reconciliation-coordinator.d.ts +23 -9
  10. package/dist/generator/mdx-reconciliation-coordinator.js +63 -9
  11. package/dist/generator/page-catalog.d.ts +2 -4
  12. package/dist/generator/page-catalog.js +7 -2
  13. package/dist/generator/page-renderer.d.ts +15 -5
  14. package/dist/generator/page-renderer.js +38 -11
  15. package/dist/generator/project-config-repository.d.ts +4 -1
  16. package/dist/generator/project-config-repository.js +26 -0
  17. package/dist/generator/public-asset-manager.d.ts +10 -0
  18. package/dist/generator/public-asset-manager.js +63 -3
  19. package/dist/generator/section-index-generator.d.ts +10 -1
  20. package/dist/generator/section-index-generator.js +43 -15
  21. package/dist/generator/section-resolver.d.ts +8 -0
  22. package/dist/generator/site-artifacts.d.ts +4 -3
  23. package/dist/generator/site-artifacts.js +94 -9
  24. package/dist/generator/watch-coordinator.js +6 -1
  25. package/dist/lib/generated-artifacts.d.ts +3 -0
  26. package/dist/lib/generated-artifacts.js +36 -0
  27. package/dist/lib/icon-registry.d.ts +10 -4
  28. package/dist/lib/icon-registry.js +13 -4
  29. package/dist/lib/layout.d.ts +6 -3
  30. package/dist/lib/layout.js +107 -4
  31. package/dist/lib/metadata.d.ts +7 -0
  32. package/dist/lib/metadata.js +33 -10
  33. package/dist/lib/structures.js +20 -0
  34. package/dist/lib/types.d.ts +28 -0
  35. package/dist/lib/ui-strings.d.ts +44 -0
  36. package/dist/lib/ui-strings.js +48 -0
  37. package/dist/lib/variants.d.ts +91 -0
  38. package/dist/lib/variants.js +411 -0
  39. package/dist/mdx-to-nextjs-generator.d.ts +22 -5
  40. package/dist/mdx-to-nextjs-generator.js +92 -12
  41. package/dist/templates/app/api/mcp/route.d.ts +1 -1
  42. package/dist/templates/app/api/mcp/route.js +14 -1
  43. package/dist/templates/app/api/rag/route.d.ts +1 -1
  44. package/dist/templates/app/api/rag/route.js +13 -2
  45. package/dist/templates/app/api/search/route.d.ts +1 -1
  46. package/dist/templates/app/api/search/route.js +16 -1
  47. package/dist/templates/app/sitemap.d.ts +2 -0
  48. package/dist/templates/app/sitemap.js +48 -3
  49. package/dist/templates/components/Chat.d.ts +1 -1
  50. package/dist/templates/components/Chat.js +40 -12
  51. package/dist/templates/components/Docs.d.ts +1 -1
  52. package/dist/templates/components/Docs.js +5 -2
  53. package/dist/templates/components/DocsSideBar.d.ts +1 -1
  54. package/dist/templates/components/DocsSideBar.js +3 -1
  55. package/dist/templates/components/SearchDocs.d.ts +1 -1
  56. package/dist/templates/components/SearchDocs.js +17 -3
  57. package/dist/templates/components/SearchModalContent.d.ts +1 -1
  58. package/dist/templates/components/SearchModalContent.js +22 -14
  59. package/dist/templates/components/SectionNavProvider.d.ts +1 -1
  60. package/dist/templates/components/SectionNavProvider.js +32 -20
  61. package/dist/templates/components/SideBar.d.ts +1 -1
  62. package/dist/templates/components/SideBar.js +26 -12
  63. package/dist/templates/components/layout/ActionBar.d.ts +1 -1
  64. package/dist/templates/components/layout/ActionBar.js +9 -7
  65. package/dist/templates/components/layout/Code.d.ts +1 -1
  66. package/dist/templates/components/layout/Code.js +6 -3
  67. package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
  68. package/dist/templates/components/layout/DocsComponents.js +38 -5
  69. package/dist/templates/components/layout/DocsNavigation.d.ts +1 -1
  70. package/dist/templates/components/layout/DocsNavigation.js +4 -2
  71. package/dist/templates/components/layout/Dropdown.d.ts +1 -0
  72. package/dist/templates/components/layout/Dropdown.js +308 -0
  73. package/dist/templates/components/layout/FocusModeToggle.d.ts +1 -1
  74. package/dist/templates/components/layout/FocusModeToggle.js +7 -4
  75. package/dist/templates/components/layout/Footer.d.ts +1 -1
  76. package/dist/templates/components/layout/Footer.js +4 -2
  77. package/dist/templates/components/layout/Header.d.ts +1 -1
  78. package/dist/templates/components/layout/Header.js +18 -8
  79. package/dist/templates/components/layout/SectionBar.d.ts +1 -1
  80. package/dist/templates/components/layout/SectionBar.js +16 -10
  81. package/dist/templates/components/layout/VariantSwitchers.d.ts +1 -0
  82. package/dist/templates/components/layout/VariantSwitchers.js +313 -0
  83. package/dist/templates/components/useStrings.d.ts +1 -0
  84. package/dist/templates/components/useStrings.js +10 -0
  85. package/dist/templates/components/useVariant.d.ts +1 -0
  86. package/dist/templates/components/useVariant.js +13 -0
  87. package/dist/templates/llms/llmsIndex.d.ts +13 -0
  88. package/dist/templates/llms/llmsIndex.js +18 -3
  89. package/dist/templates/mdx/ai-assistant.mdx.d.ts +1 -1
  90. package/dist/templates/mdx/ai-assistant.mdx.js +2 -0
  91. package/dist/templates/mdx/api-playground.mdx.d.ts +1 -1
  92. package/dist/templates/mdx/api-playground.mdx.js +2 -0
  93. package/dist/templates/mdx/commands.mdx.d.ts +1 -1
  94. package/dist/templates/mdx/commands.mdx.js +1 -1
  95. package/dist/templates/mdx/fonts.mdx.d.ts +1 -1
  96. package/dist/templates/mdx/fonts.mdx.js +1 -1
  97. package/dist/templates/mdx/footer-links.mdx.d.ts +1 -1
  98. package/dist/templates/mdx/footer-links.mdx.js +1 -1
  99. package/dist/templates/mdx/index.mdx.d.ts +1 -1
  100. package/dist/templates/mdx/index.mdx.js +2 -0
  101. package/dist/templates/mdx/languages.mdx.d.ts +1 -0
  102. package/dist/templates/mdx/languages.mdx.js +94 -0
  103. package/dist/templates/mdx/media-and-assets.mdx.d.ts +1 -1
  104. package/dist/templates/mdx/media-and-assets.mdx.js +1 -1
  105. package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
  106. package/dist/templates/mdx/model-context-protocol.mdx.js +6 -0
  107. package/dist/templates/mdx/navigation.mdx.d.ts +1 -1
  108. package/dist/templates/mdx/navigation.mdx.js +2 -0
  109. package/dist/templates/mdx/platform/ai-assistant.mdx.d.ts +1 -1
  110. package/dist/templates/mdx/platform/ai-assistant.mdx.js +2 -0
  111. package/dist/templates/mdx/platform/api-playground.mdx.d.ts +1 -1
  112. package/dist/templates/mdx/platform/api-playground.mdx.js +2 -0
  113. package/dist/templates/mdx/platform/file-editor.mdx.d.ts +1 -1
  114. package/dist/templates/mdx/platform/file-editor.mdx.js +2 -0
  115. package/dist/templates/mdx/platform/index.mdx.d.ts +1 -1
  116. package/dist/templates/mdx/platform/index.mdx.js +1 -1
  117. package/dist/templates/mdx/platform/languages.mdx.d.ts +1 -0
  118. package/dist/templates/mdx/platform/languages.mdx.js +50 -0
  119. package/dist/templates/mdx/platform/mcp.mdx.d.ts +1 -1
  120. package/dist/templates/mdx/platform/mcp.mdx.js +2 -0
  121. package/dist/templates/mdx/platform/navigation-settings.mdx.d.ts +1 -1
  122. package/dist/templates/mdx/platform/navigation-settings.mdx.js +2 -0
  123. package/dist/templates/mdx/platform/publishing.mdx.d.ts +1 -1
  124. package/dist/templates/mdx/platform/publishing.mdx.js +4 -0
  125. package/dist/templates/mdx/platform/self-updating-docs.mdx.d.ts +1 -1
  126. package/dist/templates/mdx/platform/self-updating-docs.mdx.js +2 -0
  127. package/dist/templates/mdx/platform/versions.mdx.d.ts +1 -0
  128. package/dist/templates/mdx/platform/versions.mdx.js +33 -0
  129. package/dist/templates/mdx/sections.mdx.d.ts +1 -1
  130. package/dist/templates/mdx/sections.mdx.js +1 -1
  131. package/dist/templates/mdx/theme.mdx.d.ts +1 -1
  132. package/dist/templates/mdx/theme.mdx.js +1 -1
  133. package/dist/templates/mdx/versions.mdx.d.ts +1 -0
  134. package/dist/templates/mdx/versions.mdx.js +78 -0
  135. package/dist/templates/mdx/what-is-doccupine.mdx.d.ts +1 -1
  136. package/dist/templates/mdx/what-is-doccupine.mdx.js +1 -1
  137. package/dist/templates/prettierignore.d.ts +1 -1
  138. package/dist/templates/prettierignore.js +2 -0
  139. package/dist/templates/services/mcp/server.d.ts +1 -1
  140. package/dist/templates/services/mcp/server.js +54 -10
  141. package/dist/templates/services/mcp/tools.d.ts +1 -1
  142. package/dist/templates/services/mcp/tools.js +81 -6
  143. package/dist/templates/services/mcp/types.d.ts +1 -1
  144. package/dist/templates/services/mcp/types.js +10 -0
  145. package/dist/templates/services/search.d.ts +1 -1
  146. package/dist/templates/services/search.js +34 -4
  147. package/dist/templates/utils/orderNavItems.d.ts +1 -1
  148. package/dist/templates/utils/orderNavItems.js +2 -0
  149. package/dist/templates/utils/strings.d.ts +1 -0
  150. package/dist/templates/utils/strings.js +27 -0
  151. package/dist/templates/utils/variants.d.ts +1 -0
  152. package/dist/templates/utils/variants.js +170 -0
  153. package/package.json +1 -1
@@ -42,10 +42,19 @@ function normalizeLlmsPageFile(value) {
42
42
  function normalizePublicFile(value) {
43
43
  return typeof value === "string" ? normalizeRelativePath(value) : null;
44
44
  }
45
+ function normalizeLlmsVariantFile(value) {
46
+ if (typeof value !== "string")
47
+ return null;
48
+ const normalized = normalizeRelativePath(value);
49
+ return normalized && /^(?:[a-z0-9-]+\/)+llms(?:-full)?\.txt$/.test(normalized)
50
+ ? normalized
51
+ : null;
52
+ }
45
53
  export class GeneratedArtifacts {
46
54
  outputDir;
47
55
  routes = new Map();
48
56
  llmsFiles = new Set();
57
+ llmsVariantFilePaths = new Set();
49
58
  publicFilePaths = new Set();
50
59
  iconFilePaths = new Set();
51
60
  constructor(outputDir) {
@@ -60,6 +69,7 @@ export class GeneratedArtifacts {
60
69
  async load() {
61
70
  this.routes.clear();
62
71
  this.llmsFiles.clear();
72
+ this.llmsVariantFilePaths.clear();
63
73
  this.publicFilePaths.clear();
64
74
  this.iconFilePaths.clear();
65
75
  const manifestContent = await readOutputFileIfPresent(this.outputDir, MANIFEST_FILE);
@@ -80,6 +90,13 @@ export class GeneratedArtifacts {
80
90
  this.llmsFiles.add(file);
81
91
  }
82
92
  }
93
+ if (Array.isArray(parsed.llmsVariantFiles)) {
94
+ for (const value of parsed.llmsVariantFiles) {
95
+ const file = normalizeLlmsVariantFile(value);
96
+ if (file)
97
+ this.llmsVariantFilePaths.add(file);
98
+ }
99
+ }
83
100
  if (Array.isArray(parsed.publicFiles)) {
84
101
  for (const value of parsed.publicFiles) {
85
102
  const file = normalizePublicFile(value);
@@ -173,6 +190,20 @@ export class GeneratedArtifacts {
173
190
  }
174
191
  this.llmsFiles = next;
175
192
  }
193
+ llmsVariantFiles() {
194
+ return new Set(this.llmsVariantFilePaths);
195
+ }
196
+ replaceLlmsVariantFiles(files) {
197
+ const next = new Set();
198
+ for (const value of files) {
199
+ const file = normalizeLlmsVariantFile(value);
200
+ if (!file) {
201
+ throw new Error("Refusing to record an unsafe llms variant path");
202
+ }
203
+ next.add(file);
204
+ }
205
+ this.llmsVariantFilePaths = next;
206
+ }
176
207
  publicFiles() {
177
208
  return new Set(this.publicFilePaths);
178
209
  }
@@ -206,6 +237,11 @@ export class GeneratedArtifacts {
206
237
  llmsPageFiles: [...this.llmsFiles].sort(),
207
238
  publicFiles: [...this.publicFilePaths].sort(),
208
239
  iconFiles: [...this.iconFilePaths].sort(),
240
+ // Emitted only when a site has variant aggregates, so the manifest of
241
+ // every other site keeps its exact shape.
242
+ ...(this.llmsVariantFilePaths.size > 0
243
+ ? { llmsVariantFiles: [...this.llmsVariantFilePaths].sort() }
244
+ : {}),
209
245
  };
210
246
  await writeFileAtomic(this.manifestPath(MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\n`);
211
247
  }
@@ -5,6 +5,11 @@
5
5
  * whole Lucide set.
6
6
  */
7
7
  export declare const ICON_REGISTRY_FILE = "components/layout/IconRegistry.ts";
8
+ /**
9
+ * Project config files, copied to the output directory, whose `icon` entries
10
+ * the registry includes: navigation.json (sidebar) and links.json (footer).
11
+ */
12
+ export declare const ICON_CONFIG_FILES: readonly string[];
8
13
  /** An icon name together with where it was authored, for warnings. */
9
14
  export interface IconReference {
10
15
  name: string;
@@ -30,11 +35,12 @@ export declare function resolveLucideIconName(name: string): string | null;
30
35
  */
31
36
  export declare function collectMdxIconNames(content: string): string[];
32
37
  /**
33
- * Every `icon` string in navigation.json, at any depth: category icons,
34
- * link icons, and the icons of nested link groups, in either the array or the
35
- * per-section object form. Malformed JSON contributes nothing.
38
+ * Every `icon` string in a JSON config file, at any depth: the category, link,
39
+ * and nested link-group icons of navigation.json in either the array or the
40
+ * per-section object form, and the footer link icons of links.json. Malformed
41
+ * JSON contributes nothing.
36
42
  */
37
- export declare function collectNavigationIconNames(json: string | null): string[];
43
+ export declare function collectConfigIconNames(json: string | null): string[];
38
44
  /**
39
45
  * Icon names the generated components draw themselves: `<Icon name="...">`
40
46
  * literals plus the string literals inside `name={...}` expressions, across
@@ -6,6 +6,14 @@ import { iconNames } from "lucide-react/dynamic.mjs";
6
6
  * whole Lucide set.
7
7
  */
8
8
  export const ICON_REGISTRY_FILE = "components/layout/IconRegistry.ts";
9
+ /**
10
+ * Project config files, copied to the output directory, whose `icon` entries
11
+ * the registry includes: navigation.json (sidebar) and links.json (footer).
12
+ */
13
+ export const ICON_CONFIG_FILES = [
14
+ "navigation.json",
15
+ "links.json",
16
+ ];
9
17
  /** Lucide's kebab-case ids: the canonical spelling every other form resolves to. */
10
18
  const KEBAB_IDS = new Set(iconNames);
11
19
  /**
@@ -70,11 +78,12 @@ export function collectMdxIconNames(content) {
70
78
  ];
71
79
  }
72
80
  /**
73
- * Every `icon` string in navigation.json, at any depth: category icons,
74
- * link icons, and the icons of nested link groups, in either the array or the
75
- * per-section object form. Malformed JSON contributes nothing.
81
+ * Every `icon` string in a JSON config file, at any depth: the category, link,
82
+ * and nested link-group icons of navigation.json in either the array or the
83
+ * per-section object form, and the footer link icons of links.json. Malformed
84
+ * JSON contributes nothing.
76
85
  */
77
- export function collectNavigationIconNames(json) {
86
+ export function collectConfigIconNames(json) {
78
87
  if (!json)
79
88
  return [];
80
89
  let parsed;
@@ -1,4 +1,5 @@
1
- import type { FontConfig, SectionConfig } from "./types.js";
1
+ import type { FontConfig, LanguageConfig, SectionConfig } from "./types.js";
2
+ import { type VariantSet } from "./variants.js";
2
3
  interface PageData {
3
4
  slug: string;
4
5
  title: string;
@@ -9,6 +10,8 @@ interface PageData {
9
10
  categoryOrder: number;
10
11
  order: number;
11
12
  section: string;
13
+ locale?: string;
14
+ version?: string;
12
15
  }
13
16
  /**
14
17
  * Root layout ("app/layout.tsx"). Minimal shell: html/body, fonts, the theme
@@ -19,7 +22,7 @@ interface PageData {
19
22
  * the SITE_PASSWORD gate is enforced in the middleware (proxy.ts), which
20
23
  * rewrites locked page requests to "/gate".
21
24
  */
22
- export declare const rootLayoutTemplate: (fontConfig: FontConfig | null, analyticsEnabled?: boolean) => string;
25
+ export declare const rootLayoutTemplate: (fontConfig: FontConfig | null, analyticsEnabled?: boolean, languages?: LanguageConfig[] | null) => string;
23
26
  /**
24
27
  * Docs chrome layout ("app/(site)/layout.tsx"). Wraps every documentation page
25
28
  * with the header, sidebar/section navigation, chat, and footer. Lives in the
@@ -27,5 +30,5 @@ export declare const rootLayoutTemplate: (fontConfig: FontConfig | null, analyti
27
30
  * screen at "/gate", which renders under the root shell alone. Renders inside
28
31
  * the root layout's providers, so it needs no html/body or theme provider.
29
32
  */
30
- export declare const siteLayoutTemplate: (pages: PageData[], sectionsConfig?: SectionConfig[] | null) => string;
33
+ export declare const siteLayoutTemplate: (pages: PageData[], sectionsConfig?: SectionConfig[] | null, variants?: VariantSet | null) => string;
31
34
  export {};
@@ -1,4 +1,5 @@
1
1
  import { DEFAULT_DESCRIPTION, DEFAULT_OG_IMAGE, DEFAULT_SITE_NAME, } from "./constants.js";
2
+ import { defaultLanguage, listVariantPrefixes, sectionsForVariant, } from "./variants.js";
2
3
  function formatObjectArray(items) {
3
4
  const MAX_WIDTH = 80;
4
5
  const formatted = items.map((item) => {
@@ -20,6 +21,24 @@ function formatObjectArray(items) {
20
21
  });
21
22
  return "[\n" + formatted.join("\n") + "\n]";
22
23
  }
24
+ /**
25
+ * `{ "": ["", "api"], de: [""] }` as Prettier prints it: keys quoted only when
26
+ * they are not identifiers, one entry per line, arrays inline unless the line
27
+ * would overflow.
28
+ */
29
+ function formatSectionScopes(scopes) {
30
+ const lines = Object.entries(scopes).map(([prefix, slugs]) => {
31
+ const key = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(prefix)
32
+ ? prefix
33
+ : JSON.stringify(prefix);
34
+ const items = slugs.map((slug) => JSON.stringify(slug));
35
+ const inline = ` ${key}: [${items.join(", ")}],`;
36
+ if (inline.length <= 80)
37
+ return inline;
38
+ return ` ${key}: [\n${items.map((item) => ` ${item},`).join("\n")}\n ],`;
39
+ });
40
+ return `{\n${lines.join("\n")}\n}`;
41
+ }
23
42
  function isGoogleFont(fc) {
24
43
  return (!!fc?.googleFont?.fontName &&
25
44
  /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(fc.googleFont.fontName));
@@ -121,7 +140,18 @@ const THEME_INIT_SCRIPT = `(function(){try{var c=document.cookie.split(";").map(
121
140
  * the SITE_PASSWORD gate is enforced in the middleware (proxy.ts), which
122
141
  * rewrites locked page requests to "/gate".
123
142
  */
124
- export const rootLayoutTemplate = (fontConfig, analyticsEnabled = false) => {
143
+ export const rootLayoutTemplate = (fontConfig, analyticsEnabled = false, languages = null) => {
144
+ // A single root layout serves every language, so the server-rendered
145
+ // <html lang> is the default language's. The pre-paint script corrects it
146
+ // from the URL's language prefix before anything renders, and the docs
147
+ // content container carries its own lang attribute server-side.
148
+ const defaultCode = defaultLanguage(languages)?.code ?? "en";
149
+ const languageCodes = (languages ?? [])
150
+ .filter((language) => !language.default)
151
+ .map((language) => language.code);
152
+ const themeInitScript = languages
153
+ ? THEME_INIT_SCRIPT.replace("document.write(", `var p=location.pathname.split("/")[1];r.lang=${JSON.stringify(languageCodes)}.indexOf(p)>=0?p:${JSON.stringify(defaultCode)};document.write(`)
154
+ : THEME_INIT_SCRIPT;
125
155
  return `import type { Metadata } from "next";
126
156
  ${fontImportLine(fontConfig)}
127
157
  import { StyledComponentsRegistry } from "cherry-styled-components/next";
@@ -164,7 +194,7 @@ export default function RootLayout({
164
194
  children: React.ReactNode;
165
195
  }>) {
166
196
  return (
167
- <html lang="en" suppressHydrationWarning>
197
+ <html lang="${defaultCode}" suppressHydrationWarning>
168
198
  <head>
169
199
  {/* Resolves dark mode before the first paint by stamping data-theme
170
200
  on <html>, which flips the CSS variables in GlobalStyles.
@@ -175,7 +205,7 @@ export default function RootLayout({
175
205
  intentionally different between server (none) and client. */}
176
206
  <script
177
207
  dangerouslySetInnerHTML={{
178
- __html: \`${THEME_INIT_SCRIPT}\`,
208
+ __html: \`${themeInitScript}\`,
179
209
  }}
180
210
  />
181
211
  </head>
@@ -204,9 +234,12 @@ ${analyticsEnabled
204
234
  * screen at "/gate", which renders under the root shell alone. Renders inside
205
235
  * the root layout's providers, so it needs no html/body or theme provider.
206
236
  */
207
- export const siteLayoutTemplate = (pages, sectionsConfig = null) => {
237
+ export const siteLayoutTemplate = (pages, sectionsConfig = null, variants = null) => {
208
238
  const hasSections = sectionsConfig !== null && sectionsConfig.length > 0;
209
239
  const chtOpen = `<ChtProvider isChatActive={process.env.LLM_PROVIDER ? true : false}>`;
240
+ if (variants) {
241
+ return variantSiteLayout(pages, sectionsConfig, variants, chtOpen);
242
+ }
210
243
  return `import dynamic from "next/dynamic";
211
244
  import { ChtProvider } from "@/components/Chat";
212
245
  import { SearchProvider } from "@/components/SearchDocs";
@@ -314,3 +347,73 @@ ${hasSections
314
347
  }`}
315
348
  `;
316
349
  };
350
+ /**
351
+ * The docs chrome layout of a site with languages or versions. Always routes
352
+ * the sidebar through SectionNavProvider, which scopes sections and pages to
353
+ * the current language/version prefix and hands the sidebar the full page list
354
+ * its language and version switchers navigate through. The section bar shows
355
+ * only the sections that have pages in the current prefix.
356
+ */
357
+ function variantSiteLayout(pages, sectionsConfig, variants, chtOpen) {
358
+ const hasSections = sectionsConfig !== null && sectionsConfig.length > 0;
359
+ const { languages, versions } = variants;
360
+ const sectionScopes = {};
361
+ if (hasSections) {
362
+ for (const prefix of listVariantPrefixes(languages, versions)) {
363
+ sectionScopes[prefix] = sectionsForVariant(pages, sectionsConfig, prefix, languages, versions);
364
+ }
365
+ }
366
+ const sectionBar = hasSections
367
+ ? `
368
+ <SectionBar
369
+ sections={doccupineSections}
370
+ variantSections={doccupineVariantSections}
371
+ />
372
+ `
373
+ : "";
374
+ return `import dynamic from "next/dynamic";
375
+ import { ChtProvider } from "@/components/Chat";
376
+ import { SearchProvider } from "@/components/SearchDocs";
377
+ import { Header } from "@/components/layout/Header";
378
+ import { DocsWrapper, LlmsDirective } from "@/components/layout/DocsComponents";
379
+ import { type PagesProps } from "@/utils/orderNavItems";
380
+ import { verifyBrandingKey } from "@/utils/branding";
381
+ ${hasSections ? `import { SectionBar } from "@/components/layout/SectionBar";\n` : ""}import { SectionNavProvider } from "@/components/SectionNavProvider";
382
+
383
+ const Chat = dynamic(() => import("@/components/Chat").then((mod) => mod.Chat));
384
+
385
+ const doccupinePages = ${formatObjectArray(pages)};${hasSections
386
+ ? `\nconst doccupineSections = ${formatObjectArray(sectionsConfig)};
387
+ const doccupineVariantSections: Record<string, string[]> = ${formatSectionScopes(sectionScopes)};`
388
+ : ""}
389
+
390
+ export default function SiteLayout({
391
+ children,
392
+ }: Readonly<{
393
+ children: React.ReactNode;
394
+ }>) {
395
+ const hideBranding = verifyBrandingKey();
396
+
397
+ const pages: PagesProps[] = doccupinePages;
398
+
399
+ return (
400
+ ${chtOpen}
401
+ <SearchProvider pages={pages}${hasSections ? " sections={doccupineSections}" : ""}>
402
+ <LlmsDirective />
403
+ <Header${hasSections ? `>${sectionBar}</Header>` : " />"}
404
+ {process.env.LLM_PROVIDER && <Chat />}
405
+ <DocsWrapper>
406
+ <SectionNavProvider
407
+ sections={${hasSections ? "doccupineSections" : "[]"}}
408
+ allPages={pages}
409
+ hideBranding={hideBranding}${hasSections ? "" : "\n hasSectionBar={false}"}
410
+ >
411
+ {children}
412
+ </SectionNavProvider>
413
+ </DocsWrapper>
414
+ </SearchProvider>
415
+ </ChtProvider>
416
+ );
417
+ }
418
+ `;
419
+ }
@@ -41,6 +41,13 @@ export interface MetadataOptions {
41
41
  * `alternates.types` entry so feed readers can autodiscover the feed.
42
42
  */
43
43
  rssPath?: string;
44
+ /**
45
+ * hreflang -> path of the same page in each language it exists in,
46
+ * including "x-default" (languages.json). Emitted as `alternates.languages`.
47
+ */
48
+ alternateLanguages?: Record<string, string>;
49
+ /** Open Graph locale of the page ("de", "pt_BR"). */
50
+ ogLocale?: string;
44
51
  }
45
52
  export declare function generateMetadataBlock(opts: MetadataOptions): string;
46
53
  export declare function generateRuntimeOnlyMetadataBlock(): string;
@@ -84,6 +84,18 @@ export function generateJsonLdScript(opts) {
84
84
  />`;
85
85
  return { declarations, element };
86
86
  }
87
+ function formatLanguagesBlock(languages) {
88
+ const entries = Object.entries(languages).map(([lang, href]) => {
89
+ const key = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(lang)
90
+ ? lang
91
+ : JSON.stringify(lang);
92
+ return `${key}: ${JSON.stringify(href)}`;
93
+ });
94
+ const inline = ` languages: { ${entries.join(", ")} },`;
95
+ return inline.length <= 80
96
+ ? inline
97
+ : ` languages: {\n${entries.map((entry) => ` ${entry},`).join("\n")}\n },`;
98
+ }
87
99
  function buildFieldExpression(staticValue, configKey, defaultValue) {
88
100
  if (staticValue)
89
101
  return JSON.stringify(String(staticValue));
@@ -115,24 +127,32 @@ function formatProperty(indent, name, expression) {
115
127
  ? inline
116
128
  : `${prefix}${name}:\n${prefix} ${expression},`;
117
129
  }
118
- function buildAlternatesBlock(canonicalPath, rssPath) {
130
+ function buildAlternatesBlock(canonicalPath, rssPath, alternateLanguages) {
119
131
  if (canonicalPath === undefined)
120
132
  return "";
121
133
  const safePath = canonicalPath.replace(/^\/+/, "");
122
134
  // Relative paths resolve against `metadataBase` set in the root layout.
123
135
  // Empty string means the homepage canonical equals the base URL itself.
124
136
  const canonical = JSON.stringify("/" + safePath);
125
- if (!rssPath)
137
+ const hasLanguages = alternateLanguages !== undefined &&
138
+ Object.keys(alternateLanguages).length > 0;
139
+ if (!rssPath && !hasLanguages) {
126
140
  return `\n alternates: { canonical: ${canonical} },`;
127
- const rss = JSON.stringify(rssPath);
141
+ }
128
142
  // Prettier preserves an object literal that already breaks after "{", so
129
143
  // the expanded form is stable; only the inner `types` line can overflow
130
144
  // the 80-col print width (long slugs) and needs the pre-wrap check.
131
- const typesInline = ` types: { "application/rss+xml": ${rss} },`;
132
- const typesLines = typesInline.length <= 80
133
- ? typesInline
134
- : ` types: {\n "application/rss+xml": ${rss},\n },`;
135
- return `\n alternates: {\n canonical: ${canonical},\n${typesLines}\n },`;
145
+ const lines = [` canonical: ${canonical},`];
146
+ if (hasLanguages)
147
+ lines.push(formatLanguagesBlock(alternateLanguages));
148
+ if (rssPath) {
149
+ const rss = JSON.stringify(rssPath);
150
+ const typesInline = ` types: { "application/rss+xml": ${rss} },`;
151
+ lines.push(typesInline.length <= 80
152
+ ? typesInline
153
+ : ` types: {\n "application/rss+xml": ${rss},\n },`);
154
+ }
155
+ return `\n alternates: {\n${lines.join("\n")}\n },`;
136
156
  }
137
157
  export function generateMetadataBlock(opts) {
138
158
  const title = buildTitleExpression(opts);
@@ -141,7 +161,10 @@ export function generateMetadataBlock(opts) {
141
161
  // built by utils/icons.ts (root icon files > config.icon > default) applies.
142
162
  const icon = opts.icon ? JSON.stringify(String(opts.icon)) : "siteIcons";
143
163
  const image = buildFieldExpression(opts.image, "image", DEFAULT_OG_IMAGE);
144
- const canonical = buildAlternatesBlock(opts.canonicalPath, opts.rssPath);
164
+ const canonical = buildAlternatesBlock(opts.canonicalPath, opts.rssPath, opts.alternateLanguages);
165
+ const ogLocaleLine = opts.ogLocale
166
+ ? `\n locale: ${JSON.stringify(opts.ogLocale)},`
167
+ : "";
145
168
  const inlineTitleDeclaration = `const pageTitle = ${title};`;
146
169
  const titleDeclaration = title.includes("\n") || inlineTitleDeclaration.length <= 80
147
170
  ? inlineTitleDeclaration
@@ -159,7 +182,7 @@ ${iconLine}${canonical}
159
182
  openGraph: {
160
183
  title: pageTitle,
161
184
  ${openGraphDescriptionLine}
162
- ${imageLine}
185
+ ${imageLine}${ogLocaleLine}
163
186
  },
164
187
  };`;
165
188
  }
@@ -32,6 +32,12 @@ import { searchModalContentTemplate } from "../templates/components/SearchModalC
32
32
  import { sideBarTemplate } from "../templates/components/SideBar.js";
33
33
  import { spinnerTemplate } from "../templates/components/Spinner.js";
34
34
  import { sectionBarTemplate } from "../templates/components/layout/SectionBar.js";
35
+ import { variantSwitchersTemplate } from "../templates/components/layout/VariantSwitchers.js";
36
+ import { dropdownTemplate } from "../templates/components/layout/Dropdown.js";
37
+ import { useVariantTemplate } from "../templates/components/useVariant.js";
38
+ import { useStringsTemplate } from "../templates/components/useStrings.js";
39
+ import { variantsUtilTemplate } from "../templates/utils/variants.js";
40
+ import { stringsUtilTemplate } from "../templates/utils/strings.js";
35
41
  import { accordionTemplate } from "../templates/components/layout/Accordion.js";
36
42
  import { actionBarTemplate } from "../templates/components/layout/ActionBar.js";
37
43
  import { badgeTemplate } from "../templates/components/layout/Badge.js";
@@ -163,6 +169,10 @@ import { platformBuildAndDeployMdxTemplate } from "../templates/mdx/platform/bui
163
169
  import { platformTeamMembersMdxTemplate } from "../templates/mdx/platform/team-members.mdx.js";
164
170
  import { platformBillingMdxTemplate } from "../templates/mdx/platform/billing.mdx.js";
165
171
  import { platformProjectSettingsMdxTemplate } from "../templates/mdx/platform/project-settings.mdx.js";
172
+ import { platformLanguagesMdxTemplate } from "../templates/mdx/platform/languages.mdx.js";
173
+ import { platformVersionsMdxTemplate } from "../templates/mdx/platform/versions.mdx.js";
174
+ import { languagesMdxTemplate } from "../templates/mdx/languages.mdx.js";
175
+ import { versionsMdxTemplate } from "../templates/mdx/versions.mdx.js";
166
176
  export const appStructure = {
167
177
  ".env.example": envExampleTemplate,
168
178
  ".gitignore": gitignoreTemplate,
@@ -208,6 +218,8 @@ export const appStructure = {
208
218
  "utils/rateLimit.ts": rateLimitTemplate,
209
219
  "utils/rehypeCodeMeta.ts": rehypeCodeMetaTemplate,
210
220
  "utils/config.ts": configTemplate,
221
+ "utils/variants.ts": variantsUtilTemplate,
222
+ "utils/strings.ts": stringsUtilTemplate,
211
223
  "utils/icons.ts": iconsTemplate,
212
224
  "utils/playgroundAllowlist.ts": playgroundAllowlistTemplate,
213
225
  "utils/ssrfGuard.ts": ssrfGuardTemplate,
@@ -227,6 +239,8 @@ export const appStructure = {
227
239
  "components/SearchModalContent.tsx": searchModalContentTemplate,
228
240
  "components/SideBar.tsx": sideBarTemplate,
229
241
  "components/Spinner.tsx": spinnerTemplate,
242
+ "components/useVariant.ts": useVariantTemplate,
243
+ "components/useStrings.ts": useStringsTemplate,
230
244
  "components/layout/Accordion.tsx": accordionTemplate,
231
245
  "components/layout/ActionBar.tsx": actionBarTemplate,
232
246
  "components/layout/ApiPlayground.tsx": apiPlaygroundTemplate,
@@ -242,6 +256,7 @@ export const appStructure = {
242
256
  "components/layout/Columns.tsx": columnsTemplate,
243
257
  "components/layout/DemoTheme.tsx": demoThemeTemplate,
244
258
  "components/layout/DocsComponents.tsx": docsComponentsTemplate,
259
+ "components/layout/Dropdown.tsx": dropdownTemplate,
245
260
  "components/layout/DocsNavigation.tsx": docsNavigationTemplate,
246
261
  "components/layout/SectionBar.tsx": sectionBarTemplate,
247
262
  "components/layout/Field.tsx": fieldTemplate,
@@ -268,6 +283,7 @@ export const appStructure = {
268
283
  "components/layout/TreeData.ts": treeDataTemplate,
269
284
  "components/layout/Typography.ts": typographyTemplate,
270
285
  "components/layout/Update.tsx": updateTemplate,
286
+ "components/layout/VariantSwitchers.tsx": variantSwitchersTemplate,
271
287
  };
272
288
  // Files generated by earlier CLI versions that no longer exist in the
273
289
  // template set. Unlike app/ (wiped on every run), components/ and friends
@@ -311,6 +327,8 @@ export const startingDocsStructure = {
311
327
  "navigation.mdx": navigationMdxTemplate,
312
328
  "prompt.mdx": promptMdxTemplate,
313
329
  "sections.mdx": sectionsMdxTemplate,
330
+ "languages.mdx": languagesMdxTemplate,
331
+ "versions.mdx": versionsMdxTemplate,
314
332
  "side-panel.mdx": sidePanelMdxTemplate,
315
333
  "space.mdx": spaceMdxTemplate,
316
334
  "steps.mdx": stepsMdxTemplate,
@@ -332,6 +350,8 @@ export const startingDocsStructure = {
332
350
  "platform/fonts-settings.mdx": platformFontsSettingsMdxTemplate,
333
351
  "platform/footer-links.mdx": platformFooterLinksMdxTemplate,
334
352
  "platform/authentication.mdx": platformAuthenticationMdxTemplate,
353
+ "platform/languages.mdx": platformLanguagesMdxTemplate,
354
+ "platform/versions.mdx": platformVersionsMdxTemplate,
335
355
  "platform/analytics.mdx": platformAnalyticsMdxTemplate,
336
356
  "platform/ai-assistant.mdx": platformAiAssistantMdxTemplate,
337
357
  "platform/mcp.mdx": platformMcpMdxTemplate,
@@ -3,6 +3,10 @@ export interface MDXFile {
3
3
  content: string;
4
4
  frontmatter: Record<string, any>;
5
5
  slug: string;
6
+ /** Language code and version slug of the page's variant. Set only when
7
+ * `languages.json` / `versions.json` are configured. */
8
+ locale?: string;
9
+ version?: string;
6
10
  }
7
11
  export interface PageMeta {
8
12
  slug: string;
@@ -22,12 +26,36 @@ export interface PageMeta {
22
26
  * omitted on hand-written MDX pages so their serialized nav objects are
23
27
  * unchanged. */
24
28
  httpMethod?: string;
29
+ /** Language code (`languages.json`) and version slug (`versions.json`, ""
30
+ * for the default version) of the page's variant. Omitted entirely when
31
+ * the corresponding file is not configured so serialized nav objects are
32
+ * unchanged for sites that do not use the feature. */
33
+ locale?: string;
34
+ version?: string;
25
35
  }
26
36
  export interface SectionConfig {
27
37
  label: string;
28
38
  slug: string;
29
39
  directory?: string;
30
40
  }
41
+ /** One entry of `languages.json`. The default language lives at the docs root
42
+ * and has no URL prefix; every other language lives in `docs/<code>/`. */
43
+ export interface LanguageConfig {
44
+ /** Lowercase URL segment (`en`, `pt-br`); also the `lang`/`hreflang` value. */
45
+ code: string;
46
+ label: string;
47
+ default: boolean;
48
+ /** Per-language overrides for the generated site's UI strings. */
49
+ strings?: Record<string, string>;
50
+ }
51
+ /** One entry of `versions.json`. The default version lives at the docs root
52
+ * and has `slug: ""`, mirroring the root section; every other version lives in
53
+ * `docs/<slug>/` (or `docs/<code>/<slug>/` inside a language folder). */
54
+ export interface VersionConfig {
55
+ slug: string;
56
+ label: string;
57
+ default: boolean;
58
+ }
31
59
  export interface DoccupineConfig {
32
60
  watchDir: string;
33
61
  outputDir: string;
@@ -0,0 +1,44 @@
1
+ export declare const DEFAULT_UI_STRINGS: {
2
+ readonly searchButton: "Search docs";
3
+ readonly searchDialog: "Search documentation";
4
+ readonly searchPlaceholder: "Search docs...";
5
+ readonly searchResults: "Search results";
6
+ readonly searching: "Searching documentation";
7
+ readonly noResults: "No results found";
8
+ readonly resultsAvailable: "{count} search results available";
9
+ readonly resultAvailable: "1 search result available";
10
+ readonly askAi: "Ask AI";
11
+ readonly askAiAssistant: "Ask AI Assistant";
12
+ readonly closeSearch: "Close search";
13
+ readonly onThisPage: "On this page";
14
+ readonly previous: "Previous";
15
+ readonly next: "Next";
16
+ readonly openNavigation: "Open navigation menu";
17
+ readonly closeNavigation: "Close navigation menu";
18
+ readonly expandGroup: "Expand {title}";
19
+ readonly collapseGroup: "Collapse {title}";
20
+ readonly enterFocusMode: "Enter focus mode";
21
+ readonly exitFocusMode: "Exit focus mode";
22
+ readonly focusMode: "Focus mode";
23
+ readonly copyContent: "Copy content";
24
+ readonly copied: "Copied!";
25
+ readonly copyCode: "Copy code";
26
+ readonly codeVariants: "Code variants";
27
+ readonly rss: "RSS";
28
+ readonly rssFeed: "RSS feed";
29
+ readonly viewAsMarkdown: "View as Markdown";
30
+ readonly toggleView: "Toggle View";
31
+ readonly poweredBy: "Powered by";
32
+ readonly githubLink: "Doccupine on GitHub";
33
+ readonly aiAssistant: "AI Assistant";
34
+ readonly resetChat: "Reset chat history";
35
+ readonly chatGreeting: "Hey there, how can I assist you?";
36
+ readonly chatPlaceholder: "Ask AI Assistant...";
37
+ readonly chatInputLabel: "Ask a question";
38
+ readonly chatAnswering: "Answering";
39
+ readonly chatError: "Error:";
40
+ readonly language: "Language";
41
+ readonly version: "Version";
42
+ };
43
+ export type UiStringKey = keyof typeof DEFAULT_UI_STRINGS;
44
+ export declare const UI_STRING_KEYS: readonly string[];
@@ -0,0 +1,48 @@
1
+ // The generated site's own chrome strings: search, sidebar, action bar,
2
+ // footer, chat, and the language/version switchers. A `languages.json` entry
3
+ // may override any of them through its `strings` object, so a translated
4
+ // site is not stuck with English labels around translated pages. The keys
5
+ // are the contract: `validateLanguagesConfig` warns on one it does not know.
6
+ export const DEFAULT_UI_STRINGS = {
7
+ searchButton: "Search docs",
8
+ searchDialog: "Search documentation",
9
+ searchPlaceholder: "Search docs...",
10
+ searchResults: "Search results",
11
+ searching: "Searching documentation",
12
+ noResults: "No results found",
13
+ resultsAvailable: "{count} search results available",
14
+ resultAvailable: "1 search result available",
15
+ askAi: "Ask AI",
16
+ askAiAssistant: "Ask AI Assistant",
17
+ closeSearch: "Close search",
18
+ onThisPage: "On this page",
19
+ previous: "Previous",
20
+ next: "Next",
21
+ openNavigation: "Open navigation menu",
22
+ closeNavigation: "Close navigation menu",
23
+ expandGroup: "Expand {title}",
24
+ collapseGroup: "Collapse {title}",
25
+ enterFocusMode: "Enter focus mode",
26
+ exitFocusMode: "Exit focus mode",
27
+ focusMode: "Focus mode",
28
+ copyContent: "Copy content",
29
+ copied: "Copied!",
30
+ copyCode: "Copy code",
31
+ codeVariants: "Code variants",
32
+ rss: "RSS",
33
+ rssFeed: "RSS feed",
34
+ viewAsMarkdown: "View as Markdown",
35
+ toggleView: "Toggle View",
36
+ poweredBy: "Powered by",
37
+ githubLink: "Doccupine on GitHub",
38
+ aiAssistant: "AI Assistant",
39
+ resetChat: "Reset chat history",
40
+ chatGreeting: "Hey there, how can I assist you?",
41
+ chatPlaceholder: "Ask AI Assistant...",
42
+ chatInputLabel: "Ask a question",
43
+ chatAnswering: "Answering",
44
+ chatError: "Error:",
45
+ language: "Language",
46
+ version: "Version",
47
+ };
48
+ export const UI_STRING_KEYS = Object.keys(DEFAULT_UI_STRINGS);