doccupine 0.0.158 → 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 (149) hide show
  1. package/README.md +51 -1
  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/mdx-pass-builder.d.ts +4 -4
  6. package/dist/generator/mdx-pass-builder.js +8 -1
  7. package/dist/generator/mdx-reconciliation-coordinator.d.ts +23 -9
  8. package/dist/generator/mdx-reconciliation-coordinator.js +63 -9
  9. package/dist/generator/page-catalog.d.ts +2 -4
  10. package/dist/generator/page-catalog.js +7 -2
  11. package/dist/generator/page-renderer.d.ts +15 -5
  12. package/dist/generator/page-renderer.js +38 -11
  13. package/dist/generator/project-config-repository.d.ts +4 -1
  14. package/dist/generator/project-config-repository.js +26 -0
  15. package/dist/generator/public-asset-manager.d.ts +10 -0
  16. package/dist/generator/public-asset-manager.js +63 -3
  17. package/dist/generator/section-index-generator.d.ts +10 -1
  18. package/dist/generator/section-index-generator.js +43 -15
  19. package/dist/generator/section-resolver.d.ts +8 -0
  20. package/dist/generator/site-artifacts.d.ts +4 -3
  21. package/dist/generator/site-artifacts.js +94 -9
  22. package/dist/generator/watch-coordinator.js +6 -1
  23. package/dist/lib/generated-artifacts.d.ts +3 -0
  24. package/dist/lib/generated-artifacts.js +36 -0
  25. package/dist/lib/layout.d.ts +6 -3
  26. package/dist/lib/layout.js +107 -4
  27. package/dist/lib/metadata.d.ts +7 -0
  28. package/dist/lib/metadata.js +33 -10
  29. package/dist/lib/structures.js +20 -0
  30. package/dist/lib/types.d.ts +28 -0
  31. package/dist/lib/ui-strings.d.ts +44 -0
  32. package/dist/lib/ui-strings.js +48 -0
  33. package/dist/lib/variants.d.ts +91 -0
  34. package/dist/lib/variants.js +411 -0
  35. package/dist/mdx-to-nextjs-generator.d.ts +22 -5
  36. package/dist/mdx-to-nextjs-generator.js +89 -10
  37. package/dist/templates/app/api/mcp/route.d.ts +1 -1
  38. package/dist/templates/app/api/mcp/route.js +14 -1
  39. package/dist/templates/app/api/rag/route.d.ts +1 -1
  40. package/dist/templates/app/api/rag/route.js +13 -2
  41. package/dist/templates/app/api/search/route.d.ts +1 -1
  42. package/dist/templates/app/api/search/route.js +16 -1
  43. package/dist/templates/app/sitemap.d.ts +2 -0
  44. package/dist/templates/app/sitemap.js +48 -3
  45. package/dist/templates/components/Chat.d.ts +1 -1
  46. package/dist/templates/components/Chat.js +40 -12
  47. package/dist/templates/components/Docs.d.ts +1 -1
  48. package/dist/templates/components/Docs.js +5 -2
  49. package/dist/templates/components/DocsSideBar.d.ts +1 -1
  50. package/dist/templates/components/DocsSideBar.js +3 -1
  51. package/dist/templates/components/SearchDocs.d.ts +1 -1
  52. package/dist/templates/components/SearchDocs.js +17 -3
  53. package/dist/templates/components/SearchModalContent.d.ts +1 -1
  54. package/dist/templates/components/SearchModalContent.js +22 -14
  55. package/dist/templates/components/SectionNavProvider.d.ts +1 -1
  56. package/dist/templates/components/SectionNavProvider.js +32 -20
  57. package/dist/templates/components/SideBar.d.ts +1 -1
  58. package/dist/templates/components/SideBar.js +26 -12
  59. package/dist/templates/components/layout/ActionBar.d.ts +1 -1
  60. package/dist/templates/components/layout/ActionBar.js +9 -7
  61. package/dist/templates/components/layout/Code.d.ts +1 -1
  62. package/dist/templates/components/layout/Code.js +6 -3
  63. package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
  64. package/dist/templates/components/layout/DocsComponents.js +38 -5
  65. package/dist/templates/components/layout/DocsNavigation.d.ts +1 -1
  66. package/dist/templates/components/layout/DocsNavigation.js +4 -2
  67. package/dist/templates/components/layout/Dropdown.d.ts +1 -0
  68. package/dist/templates/components/layout/Dropdown.js +308 -0
  69. package/dist/templates/components/layout/FocusModeToggle.d.ts +1 -1
  70. package/dist/templates/components/layout/FocusModeToggle.js +7 -4
  71. package/dist/templates/components/layout/Footer.d.ts +1 -1
  72. package/dist/templates/components/layout/Footer.js +4 -2
  73. package/dist/templates/components/layout/Header.d.ts +1 -1
  74. package/dist/templates/components/layout/Header.js +18 -8
  75. package/dist/templates/components/layout/SectionBar.d.ts +1 -1
  76. package/dist/templates/components/layout/SectionBar.js +16 -10
  77. package/dist/templates/components/layout/VariantSwitchers.d.ts +1 -0
  78. package/dist/templates/components/layout/VariantSwitchers.js +313 -0
  79. package/dist/templates/components/useStrings.d.ts +1 -0
  80. package/dist/templates/components/useStrings.js +10 -0
  81. package/dist/templates/components/useVariant.d.ts +1 -0
  82. package/dist/templates/components/useVariant.js +13 -0
  83. package/dist/templates/llms/llmsIndex.d.ts +13 -0
  84. package/dist/templates/llms/llmsIndex.js +18 -3
  85. package/dist/templates/mdx/ai-assistant.mdx.d.ts +1 -1
  86. package/dist/templates/mdx/ai-assistant.mdx.js +2 -0
  87. package/dist/templates/mdx/api-playground.mdx.d.ts +1 -1
  88. package/dist/templates/mdx/api-playground.mdx.js +2 -0
  89. package/dist/templates/mdx/commands.mdx.d.ts +1 -1
  90. package/dist/templates/mdx/commands.mdx.js +1 -1
  91. package/dist/templates/mdx/fonts.mdx.d.ts +1 -1
  92. package/dist/templates/mdx/fonts.mdx.js +1 -1
  93. package/dist/templates/mdx/footer-links.mdx.d.ts +1 -1
  94. package/dist/templates/mdx/footer-links.mdx.js +1 -1
  95. package/dist/templates/mdx/index.mdx.d.ts +1 -1
  96. package/dist/templates/mdx/index.mdx.js +2 -0
  97. package/dist/templates/mdx/languages.mdx.d.ts +1 -0
  98. package/dist/templates/mdx/languages.mdx.js +94 -0
  99. package/dist/templates/mdx/media-and-assets.mdx.d.ts +1 -1
  100. package/dist/templates/mdx/media-and-assets.mdx.js +1 -1
  101. package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
  102. package/dist/templates/mdx/model-context-protocol.mdx.js +6 -0
  103. package/dist/templates/mdx/navigation.mdx.d.ts +1 -1
  104. package/dist/templates/mdx/navigation.mdx.js +2 -0
  105. package/dist/templates/mdx/platform/ai-assistant.mdx.d.ts +1 -1
  106. package/dist/templates/mdx/platform/ai-assistant.mdx.js +2 -0
  107. package/dist/templates/mdx/platform/api-playground.mdx.d.ts +1 -1
  108. package/dist/templates/mdx/platform/api-playground.mdx.js +2 -0
  109. package/dist/templates/mdx/platform/file-editor.mdx.d.ts +1 -1
  110. package/dist/templates/mdx/platform/file-editor.mdx.js +2 -0
  111. package/dist/templates/mdx/platform/index.mdx.d.ts +1 -1
  112. package/dist/templates/mdx/platform/index.mdx.js +1 -1
  113. package/dist/templates/mdx/platform/languages.mdx.d.ts +1 -0
  114. package/dist/templates/mdx/platform/languages.mdx.js +50 -0
  115. package/dist/templates/mdx/platform/mcp.mdx.d.ts +1 -1
  116. package/dist/templates/mdx/platform/mcp.mdx.js +2 -0
  117. package/dist/templates/mdx/platform/navigation-settings.mdx.d.ts +1 -1
  118. package/dist/templates/mdx/platform/navigation-settings.mdx.js +2 -0
  119. package/dist/templates/mdx/platform/publishing.mdx.d.ts +1 -1
  120. package/dist/templates/mdx/platform/publishing.mdx.js +4 -0
  121. package/dist/templates/mdx/platform/self-updating-docs.mdx.d.ts +1 -1
  122. package/dist/templates/mdx/platform/self-updating-docs.mdx.js +2 -0
  123. package/dist/templates/mdx/platform/versions.mdx.d.ts +1 -0
  124. package/dist/templates/mdx/platform/versions.mdx.js +33 -0
  125. package/dist/templates/mdx/sections.mdx.d.ts +1 -1
  126. package/dist/templates/mdx/sections.mdx.js +1 -1
  127. package/dist/templates/mdx/theme.mdx.d.ts +1 -1
  128. package/dist/templates/mdx/theme.mdx.js +1 -1
  129. package/dist/templates/mdx/versions.mdx.d.ts +1 -0
  130. package/dist/templates/mdx/versions.mdx.js +78 -0
  131. package/dist/templates/mdx/what-is-doccupine.mdx.d.ts +1 -1
  132. package/dist/templates/mdx/what-is-doccupine.mdx.js +1 -1
  133. package/dist/templates/prettierignore.d.ts +1 -1
  134. package/dist/templates/prettierignore.js +2 -0
  135. package/dist/templates/services/mcp/server.d.ts +1 -1
  136. package/dist/templates/services/mcp/server.js +54 -10
  137. package/dist/templates/services/mcp/tools.d.ts +1 -1
  138. package/dist/templates/services/mcp/tools.js +81 -6
  139. package/dist/templates/services/mcp/types.d.ts +1 -1
  140. package/dist/templates/services/mcp/types.js +10 -0
  141. package/dist/templates/services/search.d.ts +1 -1
  142. package/dist/templates/services/search.js +34 -4
  143. package/dist/templates/utils/orderNavItems.d.ts +1 -1
  144. package/dist/templates/utils/orderNavItems.js +2 -0
  145. package/dist/templates/utils/strings.d.ts +1 -0
  146. package/dist/templates/utils/strings.js +27 -0
  147. package/dist/templates/utils/variants.d.ts +1 -0
  148. package/dist/templates/utils/variants.js +170 -0
  149. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import type { AnalyticsConfig, FontConfig, SectionConfig } from "../lib/types.js";
1
+ import type { AnalyticsConfig, FontConfig, LanguageConfig, SectionConfig, VersionConfig } from "../lib/types.js";
2
2
  import { SecureSourceFs } from "./secure-source-fs.js";
3
3
  export declare class ProjectConfigRepository {
4
4
  private readonly rootDir;
@@ -32,4 +32,7 @@ export declare class ProjectConfigRepository {
32
32
  copyAnalyticsConfig(loadConfig: () => Promise<AnalyticsConfig | null>): Promise<void>;
33
33
  resetAnalyticsConfig(): Promise<void>;
34
34
  loadSectionsConfig(): Promise<SectionConfig[] | null>;
35
+ private loadVariantConfig;
36
+ loadLanguagesConfig(): Promise<LanguageConfig[] | null>;
37
+ loadVersionsConfig(): Promise<VersionConfig[] | null>;
35
38
  }
@@ -5,11 +5,14 @@ import path from "node:path";
5
5
  import { resolveOutputPath } from "../lib/output-safety.js";
6
6
  import { validateAnalyticsConfig, validateFontConfig, } from "../lib/project-config.js";
7
7
  import { writeFileAtomic } from "../lib/utils.js";
8
+ import { validateLanguagesConfig, validateVersionsConfig, } from "../lib/variants.js";
8
9
  import { validateSectionsConfig } from "./section-resolver.js";
9
10
  const ARRAY_CONFIG_DEFAULTS = new Set([
11
+ "languages.json",
10
12
  "links.json",
11
13
  "navigation.json",
12
14
  "sections.json",
15
+ "versions.json",
13
16
  ]);
14
17
  export class ProjectConfigRepository {
15
18
  rootDir;
@@ -196,4 +199,27 @@ export class ProjectConfigRepository {
196
199
  }
197
200
  return null;
198
201
  }
202
+ // Unlike sections.json, an invalid languages.json or versions.json is an
203
+ // error rather than a warning: silently ignoring it would publish every
204
+ // variant folder as ordinary pages at the same URLs, without the switchers,
205
+ // scoping, or hreflang the author expects.
206
+ async loadVariantConfig(fileName, validate) {
207
+ const content = await this.readOptionalRootSourceFile(fileName, "variant source");
208
+ if (content === null)
209
+ return null;
210
+ let parsed;
211
+ try {
212
+ parsed = JSON.parse(content);
213
+ }
214
+ catch (error) {
215
+ throw new Error(`${fileName} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
216
+ }
217
+ return validate(parsed);
218
+ }
219
+ async loadLanguagesConfig() {
220
+ return this.loadVariantConfig("languages.json", validateLanguagesConfig);
221
+ }
222
+ async loadVersionsConfig() {
223
+ return this.loadVariantConfig("versions.json", validateVersionsConfig);
224
+ }
199
225
  }
@@ -16,6 +16,16 @@ export declare class PublicAssetManager {
16
16
  handlePublicFileDelete(filePath: string, copyCurrentSource: () => Promise<void>, restoreGeneratedArtifacts: () => Promise<void>): Promise<void>;
17
17
  findSourcePublicAsset(relativePath: string): Promise<string | null>;
18
18
  writePublicAggregate(relativePath: string, content: string): Promise<void>;
19
+ hasVariantAggregates(): boolean;
20
+ /**
21
+ * Writes the per-language/version `llms.txt` and `llms-full.txt` files and
22
+ * removes the ones a previous run wrote for a variant that no longer
23
+ * exists. A project asset that owns one of the paths wins, as for every
24
+ * generated public file.
25
+ */
26
+ syncVariantAggregates(files: ReadonlyMap<string, string>): Promise<void>;
27
+ /** Removes now-empty directories under public/ left by a stale aggregate. */
28
+ private removeEmptyPublicDirs;
19
29
  syncMcpManifest(baseUrl: string | null, siteName: string): Promise<void>;
20
30
  syncLlmsPageFiles(pages: PageWithBody[], baseUrl: string | null): Promise<void>;
21
31
  }
@@ -11,15 +11,20 @@ const PUBLIC_AGGREGATE_PATHS = new Set([
11
11
  "skill.md",
12
12
  ".well-known/mcp.json",
13
13
  ]);
14
+ // `llms.txt` / `llms-full.txt` under a language or version prefix
15
+ // (`de/llms.txt`, `de/v1/llms-full.txt`).
16
+ const VARIANT_AGGREGATE_PATTERN = /^(?:[a-z0-9-]+\/)+llms(?:-full)?\.txt$/;
14
17
  function normalizePublicArtifactPath(relativePath) {
15
18
  return relativePath.replace(/\\/g, "/").toLowerCase();
16
19
  }
17
20
  function isPublicAggregate(relativePath) {
18
- return PUBLIC_AGGREGATE_PATHS.has(normalizePublicArtifactPath(relativePath));
21
+ const normalized = normalizePublicArtifactPath(relativePath);
22
+ return (PUBLIC_AGGREGATE_PATHS.has(normalized) ||
23
+ VARIANT_AGGREGATE_PATTERN.test(normalized));
19
24
  }
20
25
  function isManagedPublicArtifact(relativePath) {
21
- const normalized = normalizePublicArtifactPath(relativePath);
22
- return PUBLIC_AGGREGATE_PATHS.has(normalized) || normalized.endsWith(".md");
26
+ return (isPublicAggregate(relativePath) ||
27
+ normalizePublicArtifactPath(relativePath).endsWith(".md"));
23
28
  }
24
29
  function publicDestinationRelativePath(relativePath) {
25
30
  return isPublicAggregate(relativePath)
@@ -169,6 +174,61 @@ export class PublicAssetManager {
169
174
  await fs.ensureDir(path.dirname(targetPath));
170
175
  await writeFileAtomic(targetPath, content);
171
176
  }
177
+ hasVariantAggregates() {
178
+ return this.artifacts.llmsVariantFiles().size > 0;
179
+ }
180
+ /**
181
+ * Writes the per-language/version `llms.txt` and `llms-full.txt` files and
182
+ * removes the ones a previous run wrote for a variant that no longer
183
+ * exists. A project asset that owns one of the paths wins, as for every
184
+ * generated public file.
185
+ */
186
+ async syncVariantAggregates(files) {
187
+ const publicDir = this.outputPath("public");
188
+ const nextRelativePaths = new Set();
189
+ for (const [relativePath, content] of files) {
190
+ const sourcePath = await this.findSourcePublicAsset(relativePath);
191
+ if (sourcePath) {
192
+ console.warn(chalk.yellow(`⚠️ Skipping generated public/${relativePath}; a project public asset owns that path`));
193
+ await this.copyRegularPublicFile(sourcePath, this.publicOutputFilePath(relativePath));
194
+ continue;
195
+ }
196
+ const targetPath = this.publicOutputFilePath(relativePath);
197
+ await fs.ensureDir(path.dirname(targetPath));
198
+ await writeFileAtomic(targetPath, content);
199
+ nextRelativePaths.add(relativePath);
200
+ }
201
+ for (const stale of this.artifacts.llmsVariantFiles()) {
202
+ if (nextRelativePaths.has(stale))
203
+ continue;
204
+ try {
205
+ if (await this.findSourcePublicAsset(stale))
206
+ continue;
207
+ const stalePath = resolveOutputPath(publicDir, stale);
208
+ if (await fs.pathExists(stalePath)) {
209
+ await fs.remove(stalePath);
210
+ await this.removeEmptyPublicDirs(path.dirname(stalePath));
211
+ }
212
+ }
213
+ catch {
214
+ // ignore
215
+ }
216
+ }
217
+ this.artifacts.replaceLlmsVariantFiles(nextRelativePaths);
218
+ await this.artifacts.save();
219
+ }
220
+ /** Removes now-empty directories under public/ left by a stale aggregate. */
221
+ async removeEmptyPublicDirs(dir) {
222
+ const publicDir = this.outputPath("public");
223
+ let current = dir;
224
+ while (current !== publicDir && current.startsWith(publicDir)) {
225
+ const entries = await fs.readdir(current).catch(() => null);
226
+ if (entries === null || entries.length > 0)
227
+ return;
228
+ await fs.remove(current);
229
+ current = path.dirname(current);
230
+ }
231
+ }
172
232
  async syncMcpManifest(baseUrl, siteName) {
173
233
  const relativePath = ".well-known/mcp.json";
174
234
  const outputPath = this.publicOutputFilePath(relativePath);
@@ -1,10 +1,19 @@
1
1
  import type { PageMeta, SectionConfig } from "../lib/types.js";
2
+ import { type VariantSet } from "../lib/variants.js";
2
3
  import { GeneratedRouteManager } from "./generated-route-manager.js";
3
4
  type WriteRedirect = (slug: string, target: string) => Promise<void>;
4
5
  export declare class SectionIndexGenerator {
5
6
  private readonly outputDir;
6
7
  private readonly routeManager;
7
8
  constructor(outputDir: string, routeManager: GeneratedRouteManager);
8
- generate(pages: PageMeta[], sections: SectionConfig[] | null, declaredSlugs: Set<string> | undefined, writeRedirect: WriteRedirect): Promise<void>;
9
+ /**
10
+ * Redirect pages for every route that has pages beneath it but no page of
11
+ * its own: each section's index (`/api` -> its first page) and, when
12
+ * languages or versions are configured, each variant's home (`/de`,
13
+ * `/v1`, `/de/v1`) and the section indexes inside it (`/de/api`). A real
14
+ * page at that route (`docs/de/index.mdx`, `docs/api/index.mdx`) always
15
+ * wins. Without variants this reproduces the single-tree behaviour exactly.
16
+ */
17
+ generate(pages: PageMeta[], sections: SectionConfig[] | null, declaredSlugs: Set<string> | undefined, writeRedirect: WriteRedirect, variants?: VariantSet | null): Promise<void>;
9
18
  }
10
19
  export {};
@@ -1,6 +1,13 @@
1
1
  import fs from "fs-extra";
2
2
  import { readOutputFileIfPresent, resolveOutputPath, } from "../lib/output-safety.js";
3
3
  import { writeFileAtomic } from "../lib/utils.js";
4
+ import { joinVariantSlug, listVariantPrefixes, pageVariantPrefix, } from "../lib/variants.js";
5
+ function byNavOrder(a, b) {
6
+ if (a.categoryOrder !== b.categoryOrder) {
7
+ return a.categoryOrder - b.categoryOrder;
8
+ }
9
+ return a.order - b.order;
10
+ }
4
11
  export class SectionIndexGenerator {
5
12
  outputDir;
6
13
  routeManager;
@@ -8,27 +15,48 @@ export class SectionIndexGenerator {
8
15
  this.outputDir = outputDir;
9
16
  this.routeManager = routeManager;
10
17
  }
11
- async generate(pages, sections, declaredSlugs, writeRedirect) {
18
+ /**
19
+ * Redirect pages for every route that has pages beneath it but no page of
20
+ * its own: each section's index (`/api` -> its first page) and, when
21
+ * languages or versions are configured, each variant's home (`/de`,
22
+ * `/v1`, `/de/v1`) and the section indexes inside it (`/de/api`). A real
23
+ * page at that route (`docs/de/index.mdx`, `docs/api/index.mdx`) always
24
+ * wins. Without variants this reproduces the single-tree behaviour exactly.
25
+ */
26
+ async generate(pages, sections, declaredSlugs, writeRedirect, variants = null) {
12
27
  const occupiedSlugs = new Set(pages.map((page) => page.slug));
13
28
  const resolvedDeclaredSlugs = new Set(occupiedSlugs);
14
29
  for (const slug of declaredSlugs ?? [])
15
30
  resolvedDeclaredSlugs.add(slug);
16
31
  const redirects = new Map();
17
- for (const section of sections ?? []) {
18
- if (section.slug === "" || resolvedDeclaredSlugs.has(section.slug)) {
19
- continue;
32
+ const languages = variants?.languages ?? null;
33
+ const versions = variants?.versions ?? null;
34
+ const sectionOrder = new Map((sections ?? []).map((section, index) => [section.slug, index]));
35
+ for (const prefix of listVariantPrefixes(languages, versions)) {
36
+ const variantPages = variants
37
+ ? pages.filter((page) => pageVariantPrefix(page, languages, versions) === prefix)
38
+ : pages;
39
+ if (prefix !== "" && !resolvedDeclaredSlugs.has(prefix)) {
40
+ const firstPage = [...variantPages].sort((a, b) => {
41
+ const sectionDelta = (sectionOrder.get(a.section) ?? Number.MAX_SAFE_INTEGER) -
42
+ (sectionOrder.get(b.section) ?? Number.MAX_SAFE_INTEGER);
43
+ return sectionDelta !== 0 ? sectionDelta : byNavOrder(a, b);
44
+ })[0];
45
+ if (firstPage)
46
+ redirects.set(prefix, firstPage.slug);
47
+ }
48
+ for (const section of sections ?? []) {
49
+ if (section.slug === "")
50
+ continue;
51
+ const route = joinVariantSlug(prefix, section.slug);
52
+ if (resolvedDeclaredSlugs.has(route))
53
+ continue;
54
+ const firstPage = variantPages
55
+ .filter((page) => page.section === section.slug)
56
+ .sort(byNavOrder)[0];
57
+ if (firstPage)
58
+ redirects.set(route, firstPage.slug);
20
59
  }
21
- const sectionPages = pages
22
- .filter((page) => page.section === section.slug)
23
- .sort((a, b) => {
24
- if (a.categoryOrder !== b.categoryOrder) {
25
- return a.categoryOrder - b.categoryOrder;
26
- }
27
- return a.order - b.order;
28
- });
29
- const firstPage = sectionPages[0];
30
- if (firstPage)
31
- redirects.set(section.slug, firstPage.slug);
32
60
  }
33
61
  const previousSlugs = this.routeManager.sectionIndexSlugs();
34
62
  const touchedSlugs = new Set([...previousSlugs, ...redirects.keys()]);
@@ -7,6 +7,14 @@ export interface SectionRoute {
7
7
  sectionSlug: string;
8
8
  pageSlug: string;
9
9
  }
10
+ /** A section route plus the variant (language/version) folder it was
11
+ * resolved under. `prefix` is the URL prefix of that variant ("" at the
12
+ * docs root); `locale`/`version` are present only when configured. */
13
+ export interface ResolvedPageRoute extends SectionRoute {
14
+ prefix?: string;
15
+ locale?: string;
16
+ version?: string;
17
+ }
10
18
  export declare function validateSectionsConfig(parsed: unknown): SectionConfig[] | null;
11
19
  export declare function discoverSections(documents: SectionDocument[]): SectionConfig[] | null;
12
20
  export declare function addApiReferenceSection(sections: SectionConfig[] | null, hasApiReference: boolean, apiBaseSlug: string): SectionConfig[] | null;
@@ -1,4 +1,5 @@
1
1
  import type { PageMeta, SectionConfig } from "../lib/types.js";
2
+ import { type VariantSet } from "../lib/variants.js";
2
3
  import { type SitemapEntry } from "../templates/app/sitemap.js";
3
4
  import { type PageWithBody } from "../templates/llms/llmsFull.js";
4
5
  import type { PublicAssetManager } from "./public-asset-manager.js";
@@ -15,9 +16,9 @@ type ReadOpenApiBody = (slug: string) => string | undefined;
15
16
  type ReadConfigSource = () => Promise<string | null>;
16
17
  export declare function loadSiteUrl(readConfigSource: ReadConfigSource): Promise<string | null>;
17
18
  export declare function loadSiteMetadata(readConfigSource: ReadConfigSource): Promise<SiteMetadata>;
18
- export declare function buildSitemapEntries(pages: PageMeta[], sectionsConfig: SectionConfig[] | null): SitemapEntry[];
19
- export declare function writeSitemap(outputDir: string, sectionsConfig: SectionConfig[] | null, resolvePages: ResolvePages, resolveSiteUrl: () => Promise<string | null>): Promise<void>;
19
+ export declare function buildSitemapEntries(pages: PageMeta[], sectionsConfig: SectionConfig[] | null, variants?: VariantSet | null): SitemapEntry[];
20
+ export declare function writeSitemap(outputDir: string, sectionsConfig: SectionConfig[] | null, resolvePages: ResolvePages, resolveSiteUrl: () => Promise<string | null>, variants?: VariantSet | null): Promise<void>;
20
21
  export declare function writeRobots(outputDir: string, resolveSiteUrl: () => Promise<string | null>): Promise<void>;
21
22
  export declare function collectPageBodies(pages: PageMeta[], readMdxSource: ReadMdxSource, readOpenApiBody: ReadOpenApiBody): Promise<PageWithBody[]>;
22
- export declare function writeLlmsFiles(outputDir: string, sectionsConfig: SectionConfig[] | null, resolvePages: ResolvePages, readMdxSource: ReadMdxSource, readOpenApiBody: ReadOpenApiBody, resolveSiteMetadata: () => Promise<SiteMetadata>, publicAssetManager: PublicAssetManager): Promise<void>;
23
+ export declare function writeLlmsFiles(outputDir: string, sectionsConfig: SectionConfig[] | null, resolvePages: ResolvePages, readMdxSource: ReadMdxSource, readOpenApiBody: ReadOpenApiBody, resolveSiteMetadata: () => Promise<SiteMetadata>, publicAssetManager: PublicAssetManager, variants?: VariantSet | null): Promise<void>;
23
24
  export {};
@@ -2,10 +2,11 @@ import chalk from "chalk";
2
2
  import fs from "fs-extra";
3
3
  import { resolveOutputPath } from "../lib/output-safety.js";
4
4
  import { isMdxPath, safeMatter, writeFileAtomic } from "../lib/utils.js";
5
+ import { buildLanguageAlternates, joinVariantSlug, listVariantPrefixes, pageVariantPrefix, resolveVariantFromSlug, } from "../lib/variants.js";
5
6
  import { robotsTemplate } from "../templates/app/robots.js";
6
7
  import { sitemapTemplate, } from "../templates/app/sitemap.js";
7
8
  import { llmsFullTemplate, } from "../templates/llms/llmsFull.js";
8
- import { llmsIndexTemplate } from "../templates/llms/llmsIndex.js";
9
+ import { llmsIndexTemplate, } from "../templates/llms/llmsIndex.js";
9
10
  import { skillMdTemplate } from "../templates/llms/skillMd.js";
10
11
  export async function loadSiteUrl(readConfigSource) {
11
12
  const fromEnv = process.env.NEXT_PUBLIC_SITE_URL?.trim();
@@ -57,23 +58,43 @@ export async function loadSiteMetadata(readConfigSource) {
57
58
  }
58
59
  return { url, name, description };
59
60
  }
60
- export function buildSitemapEntries(pages, sectionsConfig) {
61
+ export function buildSitemapEntries(pages, sectionsConfig, variants = null) {
61
62
  const sectionSlugs = new Set((sectionsConfig || [])
62
63
  .map((section) => section.slug)
63
64
  .filter((slug) => typeof slug === "string" && slug !== ""));
65
+ // Section indexes rank 0.8 in every language/version, as do the variant
66
+ // homes themselves (`de`, `v1`).
67
+ const prominentSlugs = new Set();
68
+ for (const prefix of listVariantPrefixes(variants?.languages ?? null, variants?.versions ?? null)) {
69
+ if (prefix !== "")
70
+ prominentSlugs.add(prefix);
71
+ for (const slug of sectionSlugs) {
72
+ prominentSlugs.add(joinVariantSlug(prefix, slug));
73
+ }
74
+ }
75
+ const alternates = buildLanguageAlternates(pages, variants?.languages ?? null);
64
76
  const entries = pages.map((page) => {
65
77
  let priority = 0.5;
66
78
  if (page.slug === "") {
67
79
  priority = 1.0;
68
80
  }
69
- else if (sectionSlugs.has(page.slug)) {
81
+ else if (prominentSlugs.has(page.slug)) {
70
82
  priority = 0.8;
71
83
  }
84
+ const pageAlternates = alternates.get(page.slug);
72
85
  return {
73
86
  slug: page.slug,
74
87
  lastModified: page.lastModified,
75
88
  changeFrequency: "weekly",
76
89
  priority,
90
+ ...(pageAlternates
91
+ ? {
92
+ alternates: Object.fromEntries(Object.entries(pageAlternates).map(([lang, href]) => [
93
+ lang,
94
+ href.replace(/^\/+/, ""),
95
+ ])),
96
+ }
97
+ : {}),
77
98
  };
78
99
  });
79
100
  if (!entries.some((entry) => entry.slug === "")) {
@@ -85,9 +106,9 @@ export function buildSitemapEntries(pages, sectionsConfig) {
85
106
  }
86
107
  return entries;
87
108
  }
88
- export async function writeSitemap(outputDir, sectionsConfig, resolvePages, resolveSiteUrl) {
109
+ export async function writeSitemap(outputDir, sectionsConfig, resolvePages, resolveSiteUrl, variants = null) {
89
110
  const siteUrl = await resolveSiteUrl();
90
- const entries = buildSitemapEntries(await resolvePages(), sectionsConfig);
111
+ const entries = buildSitemapEntries(await resolvePages(), sectionsConfig, variants);
91
112
  await writeFileAtomic(resolveOutputPath(outputDir, "app", "sitemap.ts"), sitemapTemplate(entries));
92
113
  console.log(chalk.green(`🗺️ Generated sitemap.ts with ${entries.length} page(s)${siteUrl ? ` using ${siteUrl}` : " (waiting for a deployment URL)"}`));
93
114
  }
@@ -108,7 +129,16 @@ export async function collectPageBodies(pages, readMdxSource, readOpenApiBody) {
108
129
  return { ...page, body };
109
130
  }));
110
131
  }
111
- export async function writeLlmsFiles(outputDir, sectionsConfig, resolvePages, readMdxSource, readOpenApiBody, resolveSiteMetadata, publicAssetManager) {
132
+ /** "Deutsch", "v1.0", or "Deutsch (v1.0)": the label of a variant prefix. */
133
+ function variantLabel(prefix, languages, versions) {
134
+ const { locale, version } = resolveVariantFromSlug(prefix, languages, versions);
135
+ const language = languages?.find((entry) => entry.code === locale)?.label;
136
+ const versionLabel = versions?.find((entry) => entry.slug === version)?.label;
137
+ if (language && versionLabel)
138
+ return `${language} (${versionLabel})`;
139
+ return language ?? versionLabel ?? prefix;
140
+ }
141
+ export async function writeLlmsFiles(outputDir, sectionsConfig, resolvePages, readMdxSource, readOpenApiBody, resolveSiteMetadata, publicAssetManager, variants = null) {
112
142
  await fs.ensureDir(resolveOutputPath(outputDir, "public"));
113
143
  const { url: baseUrl, name, description } = await resolveSiteMetadata();
114
144
  const resolvedPages = await resolvePages();
@@ -123,30 +153,85 @@ export async function writeLlmsFiles(outputDir, sectionsConfig, resolvePages, re
123
153
  name: page.title,
124
154
  path: pagePath,
125
155
  content: page.body,
156
+ // Present only on sites that configure languages.json / versions.json.
157
+ ...(page.locale !== undefined ? { locale: page.locale } : {}),
158
+ ...(page.version !== undefined ? { version: page.version } : {}),
126
159
  };
127
160
  });
128
161
  await writeFileAtomic(resolveOutputPath(outputDir, "services", "mcp", "docs-content.json"), JSON.stringify(docsContent, null, 2) + "\n");
162
+ // Each language/version gets its own llms.txt and llms-full.txt under its
163
+ // URL prefix; the root files describe the default variant and link to the
164
+ // others. Without variants there is exactly one group, the root.
165
+ const languages = variants?.languages ?? null;
166
+ const versions = variants?.versions ?? null;
167
+ const prefixes = listVariantPrefixes(languages, versions);
168
+ const pagesByPrefix = new Map(prefixes.map((prefix) => [prefix, []]));
169
+ for (const page of pagesWithBodies) {
170
+ const prefix = variants ? pageVariantPrefix(page, languages, versions) : "";
171
+ pagesByPrefix.get(prefix)?.push(page);
172
+ }
173
+ const urlPrefix = baseUrl ?? "";
174
+ const linksFor = (current) => prefixes.length > 1
175
+ ? {
176
+ heading: "Other languages and versions",
177
+ links: prefixes
178
+ .filter((prefix) => prefix !== current)
179
+ .map((prefix) => ({
180
+ label: variantLabel(prefix, languages, versions),
181
+ url: `${urlPrefix}/${joinVariantSlug(prefix, "llms.txt")}`,
182
+ })),
183
+ }
184
+ : undefined;
185
+ const rootPages = pagesByPrefix.get("") ?? [];
129
186
  const indexContent = llmsIndexTemplate({
130
187
  siteName: name,
131
188
  siteDescription: description,
132
189
  baseUrl,
133
- pages: resolvedPages,
190
+ pages: rootPages,
134
191
  sectionsConfig,
192
+ variantLinks: linksFor(""),
135
193
  });
136
194
  const fullContent = llmsFullTemplate({
137
195
  siteName: name,
138
196
  siteDescription: description,
139
197
  baseUrl,
140
- pages: pagesWithBodies,
198
+ pages: rootPages,
141
199
  sectionsConfig,
142
200
  });
143
201
  await publicAssetManager.writePublicAggregate("llms.txt", indexContent);
144
202
  await publicAssetManager.writePublicAggregate("llms-full.txt", fullContent);
203
+ const variantAggregates = new Map();
204
+ for (const prefix of prefixes) {
205
+ if (prefix === "")
206
+ continue;
207
+ const variantPages = pagesByPrefix.get(prefix) ?? [];
208
+ variantAggregates.set(`${prefix}/llms.txt`, llmsIndexTemplate({
209
+ siteName: name,
210
+ siteDescription: description,
211
+ baseUrl,
212
+ pages: variantPages,
213
+ sectionsConfig,
214
+ variantLinks: linksFor(prefix),
215
+ variantPrefix: prefix,
216
+ }));
217
+ variantAggregates.set(`${prefix}/llms-full.txt`, llmsFullTemplate({
218
+ siteName: name,
219
+ siteDescription: description,
220
+ baseUrl,
221
+ pages: variantPages,
222
+ sectionsConfig,
223
+ }));
224
+ }
225
+ // Also runs when the variant files were just removed, so the aggregates of
226
+ // a previous run are cleaned up; a site that never had any skips it.
227
+ if (variantAggregates.size > 0 || publicAssetManager.hasVariantAggregates()) {
228
+ await publicAssetManager.syncVariantAggregates(variantAggregates);
229
+ }
145
230
  const skillContent = skillMdTemplate({
146
231
  siteName: name,
147
232
  siteDescription: description,
148
233
  baseUrl,
149
- pages: resolvedPages,
234
+ pages: rootPages,
150
235
  sectionsConfig,
151
236
  });
152
237
  await publicAssetManager.writePublicAggregate("skill.md", skillContent);
@@ -4,6 +4,7 @@ import fs from "fs-extra";
4
4
  import path from "node:path";
5
5
  import { isPathInside } from "../lib/output-safety.js";
6
6
  import { isMdxPath } from "../lib/utils.js";
7
+ import { VARIANT_CONFIG_FILES } from "../lib/variants.js";
7
8
  export class WatchCoordinator {
8
9
  options;
9
10
  watcher = null;
@@ -159,8 +160,12 @@ export class WatchCoordinator {
159
160
  else {
160
161
  await callbacks.handleConfigFileDelete(sourcePath);
161
162
  }
162
- if (configFile === "sections.json")
163
+ // These handlers already run a full MDX pass, so the mdx check below
164
+ // must not schedule a second one.
165
+ if (configFile === "sections.json" ||
166
+ VARIANT_CONFIG_FILES.includes(configFile)) {
163
167
  sectionsChanged = true;
168
+ }
164
169
  }
165
170
  const fontPath = path.join(rootDir, fontConfigFile);
166
171
  if (previous === null || previous.font !== current.font) {
@@ -8,6 +8,7 @@ export declare class GeneratedArtifacts {
8
8
  private readonly outputDir;
9
9
  private routes;
10
10
  private llmsFiles;
11
+ private llmsVariantFilePaths;
11
12
  private publicFilePaths;
12
13
  private iconFilePaths;
13
14
  constructor(outputDir: string);
@@ -29,6 +30,8 @@ export declare class GeneratedArtifacts {
29
30
  removeRouteAndSave(kind: RouteOwnerKind, source: string): Promise<void>;
30
31
  llmsPageFiles(): Set<string>;
31
32
  replaceLlmsPageFiles(files: Iterable<string>): void;
33
+ llmsVariantFiles(): Set<string>;
34
+ replaceLlmsVariantFiles(files: Iterable<string>): void;
32
35
  publicFiles(): Set<string>;
33
36
  replacePublicFiles(files: Iterable<string>): void;
34
37
  iconFiles(): Set<string>;
@@ -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
  }
@@ -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 {};