doccupine 0.0.158 → 0.0.160
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 +56 -4
- package/dist/generator/app-scaffolder.js +11 -3
- package/dist/generator/generated-page-publisher.d.ts +6 -6
- package/dist/generator/generated-page-publisher.js +7 -5
- package/dist/generator/mdx-pass-builder.d.ts +4 -4
- package/dist/generator/mdx-pass-builder.js +8 -1
- package/dist/generator/mdx-reconciliation-coordinator.d.ts +23 -9
- package/dist/generator/mdx-reconciliation-coordinator.js +63 -9
- package/dist/generator/page-catalog.d.ts +2 -4
- package/dist/generator/page-catalog.js +7 -2
- package/dist/generator/page-renderer.d.ts +15 -5
- package/dist/generator/page-renderer.js +38 -11
- package/dist/generator/project-config-repository.d.ts +4 -1
- package/dist/generator/project-config-repository.js +26 -0
- package/dist/generator/public-asset-manager.d.ts +10 -0
- package/dist/generator/public-asset-manager.js +63 -3
- package/dist/generator/section-index-generator.d.ts +10 -1
- package/dist/generator/section-index-generator.js +43 -15
- package/dist/generator/section-resolver.d.ts +8 -0
- package/dist/generator/site-artifacts.d.ts +4 -3
- package/dist/generator/site-artifacts.js +94 -9
- package/dist/generator/watch-coordinator.js +6 -1
- package/dist/lib/generated-artifacts.d.ts +3 -0
- package/dist/lib/generated-artifacts.js +36 -0
- package/dist/lib/layout.d.ts +6 -3
- package/dist/lib/layout.js +107 -4
- package/dist/lib/metadata.d.ts +7 -0
- package/dist/lib/metadata.js +33 -10
- package/dist/lib/structures.js +20 -0
- package/dist/lib/types.d.ts +28 -0
- package/dist/lib/ui-strings.d.ts +44 -0
- package/dist/lib/ui-strings.js +48 -0
- package/dist/lib/variants.d.ts +91 -0
- package/dist/lib/variants.js +411 -0
- package/dist/mdx-to-nextjs-generator.d.ts +22 -5
- package/dist/mdx-to-nextjs-generator.js +89 -10
- package/dist/templates/app/api/mcp/route.d.ts +1 -1
- package/dist/templates/app/api/mcp/route.js +14 -1
- package/dist/templates/app/api/rag/route.d.ts +1 -1
- package/dist/templates/app/api/rag/route.js +13 -2
- package/dist/templates/app/api/search/route.d.ts +1 -1
- package/dist/templates/app/api/search/route.js +16 -1
- package/dist/templates/app/sitemap.d.ts +2 -0
- package/dist/templates/app/sitemap.js +48 -3
- package/dist/templates/components/Chat.d.ts +1 -1
- package/dist/templates/components/Chat.js +40 -12
- package/dist/templates/components/Docs.d.ts +1 -1
- package/dist/templates/components/Docs.js +5 -2
- package/dist/templates/components/DocsSideBar.d.ts +1 -1
- package/dist/templates/components/DocsSideBar.js +3 -1
- package/dist/templates/components/SearchDocs.d.ts +1 -1
- package/dist/templates/components/SearchDocs.js +17 -3
- package/dist/templates/components/SearchModalContent.d.ts +1 -1
- package/dist/templates/components/SearchModalContent.js +22 -14
- package/dist/templates/components/SectionNavProvider.d.ts +1 -1
- package/dist/templates/components/SectionNavProvider.js +32 -20
- package/dist/templates/components/SideBar.d.ts +1 -1
- package/dist/templates/components/SideBar.js +26 -12
- package/dist/templates/components/layout/ActionBar.d.ts +1 -1
- package/dist/templates/components/layout/ActionBar.js +9 -7
- package/dist/templates/components/layout/Code.d.ts +1 -1
- package/dist/templates/components/layout/Code.js +6 -3
- package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
- package/dist/templates/components/layout/DocsComponents.js +38 -5
- package/dist/templates/components/layout/DocsNavigation.d.ts +1 -1
- package/dist/templates/components/layout/DocsNavigation.js +4 -2
- package/dist/templates/components/layout/Dropdown.d.ts +1 -0
- package/dist/templates/components/layout/Dropdown.js +308 -0
- package/dist/templates/components/layout/FocusModeToggle.d.ts +1 -1
- package/dist/templates/components/layout/FocusModeToggle.js +7 -4
- package/dist/templates/components/layout/Footer.d.ts +1 -1
- package/dist/templates/components/layout/Footer.js +4 -2
- package/dist/templates/components/layout/Header.d.ts +1 -1
- package/dist/templates/components/layout/Header.js +18 -8
- package/dist/templates/components/layout/SectionBar.d.ts +1 -1
- package/dist/templates/components/layout/SectionBar.js +16 -10
- package/dist/templates/components/layout/VariantSwitchers.d.ts +1 -0
- package/dist/templates/components/layout/VariantSwitchers.js +313 -0
- package/dist/templates/components/useStrings.d.ts +1 -0
- package/dist/templates/components/useStrings.js +10 -0
- package/dist/templates/components/useVariant.d.ts +1 -0
- package/dist/templates/components/useVariant.js +13 -0
- package/dist/templates/env.example.d.ts +1 -1
- package/dist/templates/env.example.js +2 -1
- package/dist/templates/llms/llmsIndex.d.ts +13 -0
- package/dist/templates/llms/llmsIndex.js +18 -3
- package/dist/templates/mdx/ai-assistant.mdx.d.ts +1 -1
- package/dist/templates/mdx/ai-assistant.mdx.js +9 -3
- package/dist/templates/mdx/api-playground.mdx.d.ts +1 -1
- package/dist/templates/mdx/api-playground.mdx.js +2 -0
- package/dist/templates/mdx/commands.mdx.d.ts +1 -1
- package/dist/templates/mdx/commands.mdx.js +1 -1
- package/dist/templates/mdx/fonts.mdx.d.ts +1 -1
- package/dist/templates/mdx/fonts.mdx.js +1 -1
- package/dist/templates/mdx/footer-links.mdx.d.ts +1 -1
- package/dist/templates/mdx/footer-links.mdx.js +1 -1
- package/dist/templates/mdx/index.mdx.d.ts +1 -1
- package/dist/templates/mdx/index.mdx.js +2 -0
- package/dist/templates/mdx/languages.mdx.d.ts +1 -0
- package/dist/templates/mdx/languages.mdx.js +94 -0
- package/dist/templates/mdx/media-and-assets.mdx.d.ts +1 -1
- package/dist/templates/mdx/media-and-assets.mdx.js +1 -1
- package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
- package/dist/templates/mdx/model-context-protocol.mdx.js +6 -0
- package/dist/templates/mdx/navigation.mdx.d.ts +1 -1
- package/dist/templates/mdx/navigation.mdx.js +2 -0
- package/dist/templates/mdx/platform/ai-assistant.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/ai-assistant.mdx.js +2 -0
- package/dist/templates/mdx/platform/api-playground.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/api-playground.mdx.js +2 -0
- package/dist/templates/mdx/platform/file-editor.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/file-editor.mdx.js +2 -0
- package/dist/templates/mdx/platform/index.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/index.mdx.js +1 -1
- package/dist/templates/mdx/platform/languages.mdx.d.ts +1 -0
- package/dist/templates/mdx/platform/languages.mdx.js +50 -0
- package/dist/templates/mdx/platform/mcp.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/mcp.mdx.js +2 -0
- package/dist/templates/mdx/platform/navigation-settings.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/navigation-settings.mdx.js +2 -0
- package/dist/templates/mdx/platform/publishing.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/publishing.mdx.js +4 -0
- package/dist/templates/mdx/platform/self-updating-docs.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/self-updating-docs.mdx.js +2 -0
- package/dist/templates/mdx/platform/versions.mdx.d.ts +1 -0
- package/dist/templates/mdx/platform/versions.mdx.js +33 -0
- package/dist/templates/mdx/sections.mdx.d.ts +1 -1
- package/dist/templates/mdx/sections.mdx.js +1 -1
- package/dist/templates/mdx/theme.mdx.d.ts +1 -1
- package/dist/templates/mdx/theme.mdx.js +1 -1
- package/dist/templates/mdx/versions.mdx.d.ts +1 -0
- package/dist/templates/mdx/versions.mdx.js +78 -0
- package/dist/templates/mdx/what-is-doccupine.mdx.d.ts +1 -1
- package/dist/templates/mdx/what-is-doccupine.mdx.js +1 -1
- package/dist/templates/package.js +20 -20
- package/dist/templates/prettierignore.d.ts +1 -1
- package/dist/templates/prettierignore.js +2 -0
- package/dist/templates/services/llm/config.d.ts +1 -1
- package/dist/templates/services/llm/config.js +50 -3
- package/dist/templates/services/llm/factory.d.ts +1 -1
- package/dist/templates/services/llm/factory.js +6 -3
- package/dist/templates/services/llm/types.d.ts +1 -1
- package/dist/templates/services/llm/types.js +2 -1
- package/dist/templates/services/mcp/server.d.ts +1 -1
- package/dist/templates/services/mcp/server.js +54 -10
- package/dist/templates/services/mcp/tools.d.ts +1 -1
- package/dist/templates/services/mcp/tools.js +81 -6
- package/dist/templates/services/mcp/types.d.ts +1 -1
- package/dist/templates/services/mcp/types.js +10 -0
- package/dist/templates/services/search.d.ts +1 -1
- package/dist/templates/services/search.js +34 -4
- package/dist/templates/utils/orderNavItems.d.ts +1 -1
- package/dist/templates/utils/orderNavItems.js +2 -0
- package/dist/templates/utils/strings.d.ts +1 -0
- package/dist/templates/utils/strings.js +27 -0
- package/dist/templates/utils/variants.d.ts +1 -0
- package/dist/templates/utils/variants.js +170 -0
- package/package.json +11 -11
|
@@ -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
|
}
|
package/dist/lib/layout.d.ts
CHANGED
|
@@ -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 {};
|
package/dist/lib/layout.js
CHANGED
|
@@ -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="
|
|
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: \`${
|
|
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
|
+
}
|
package/dist/lib/metadata.d.ts
CHANGED
|
@@ -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;
|
package/dist/lib/metadata.js
CHANGED
|
@@ -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
|
-
|
|
137
|
+
const hasLanguages = alternateLanguages !== undefined &&
|
|
138
|
+
Object.keys(alternateLanguages).length > 0;
|
|
139
|
+
if (!rssPath && !hasLanguages) {
|
|
126
140
|
return `\n alternates: { canonical: ${canonical} },`;
|
|
127
|
-
|
|
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
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
}
|
package/dist/lib/structures.js
CHANGED
|
@@ -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,
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -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);
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { LanguageConfig, PageMeta, SectionConfig, VersionConfig } from "./types.js";
|
|
2
|
+
export type VariantConfigFile = "languages.json" | "versions.json";
|
|
3
|
+
export declare const VARIANT_CONFIG_FILES: readonly string[];
|
|
4
|
+
/** Top-level route segments the generated app owns; never a language code or
|
|
5
|
+
* version slug. `api` and `gate` are app routes, `mcp` and `ingest` are proxy
|
|
6
|
+
* rewrites in the generated `proxy.ts`. */
|
|
7
|
+
export declare const RESERVED_VARIANT_SEGMENTS: readonly string[];
|
|
8
|
+
export declare const MAX_VARIANT_TOKEN_LENGTH = 32;
|
|
9
|
+
export interface VariantSet {
|
|
10
|
+
languages: LanguageConfig[] | null;
|
|
11
|
+
versions: VersionConfig[] | null;
|
|
12
|
+
}
|
|
13
|
+
export interface VariantResolution {
|
|
14
|
+
/** Language code; undefined when `languages.json` is not configured. */
|
|
15
|
+
locale?: string;
|
|
16
|
+
/** Version slug ("" for the default); undefined when not configured. */
|
|
17
|
+
version?: string;
|
|
18
|
+
/** URL prefix: "", "de", "v1", or "de/v1". */
|
|
19
|
+
prefix: string;
|
|
20
|
+
/** The input with the variant folders stripped. */
|
|
21
|
+
rest: string;
|
|
22
|
+
}
|
|
23
|
+
export declare class VariantCollisionError extends Error {
|
|
24
|
+
readonly file: VariantConfigFile;
|
|
25
|
+
readonly value: string;
|
|
26
|
+
readonly conflict: string;
|
|
27
|
+
constructor(file: VariantConfigFile, value: string, conflict: string);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Validates the parsed contents of `languages.json`. Returns null for an empty
|
|
31
|
+
* array (the feature is off, like `sections.json`) and throws with a message
|
|
32
|
+
* naming the entry for anything the generator would not accept.
|
|
33
|
+
*/
|
|
34
|
+
export declare function validateLanguagesConfig(parsed: unknown): LanguageConfig[] | null;
|
|
35
|
+
/**
|
|
36
|
+
* Validates the parsed contents of `versions.json`. The default version has no
|
|
37
|
+
* slug (it lives at the docs root) and is normalized to `slug: ""`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function validateVersionsConfig(parsed: unknown): VersionConfig[] | null;
|
|
40
|
+
export declare function defaultLanguage(languages: LanguageConfig[] | null): LanguageConfig | null;
|
|
41
|
+
export declare function defaultVersion(versions: VersionConfig[] | null): VersionConfig | null;
|
|
42
|
+
/**
|
|
43
|
+
* Resolves the variant of a docs-relative file path. Only directory segments
|
|
44
|
+
* are candidates, so a file literally named `de.mdx` is never a variant. The
|
|
45
|
+
* language folder is consumed first, then the version folder.
|
|
46
|
+
*/
|
|
47
|
+
export declare function resolveVariant(relPath: string, languages: LanguageConfig[] | null, versions: VersionConfig[] | null): VariantResolution;
|
|
48
|
+
/**
|
|
49
|
+
* Resolves the variant of a URL slug (no leading slash). Every segment is a
|
|
50
|
+
* candidate, so `de` alone is the German home and `de/v1` the German v1 home.
|
|
51
|
+
*/
|
|
52
|
+
export declare function resolveVariantFromSlug(slug: string, languages: LanguageConfig[] | null, versions: VersionConfig[] | null): VariantResolution;
|
|
53
|
+
export declare function joinVariantSlug(prefix: string, slug: string): string;
|
|
54
|
+
/** Key of a `navigation.json` object entry: the URL prefix of the scope. */
|
|
55
|
+
export declare function navigationScopeKey(prefix: string, sectionSlug: string): string;
|
|
56
|
+
/** URL prefix for a language/version pair; the default of either is "". */
|
|
57
|
+
export declare function variantPrefix(locale: string | undefined, version: string | undefined, languages: LanguageConfig[] | null, versions: VersionConfig[] | null): string;
|
|
58
|
+
export declare function pageVariantPrefix(page: {
|
|
59
|
+
locale?: string;
|
|
60
|
+
version?: string;
|
|
61
|
+
}, languages: LanguageConfig[] | null, versions: VersionConfig[] | null): string;
|
|
62
|
+
/** Every URL prefix a configured site publishes, "" first, then the languages
|
|
63
|
+
* and versions in file order (languages outer, versions inner). */
|
|
64
|
+
export declare function listVariantPrefixes(languages: LanguageConfig[] | null, versions: VersionConfig[] | null): string[];
|
|
65
|
+
/** The translation key of a slug: the slug without its language prefix, so
|
|
66
|
+
* `de/v1/guide` and `v1/guide` are the same page in two languages. */
|
|
67
|
+
export declare function stripLanguagePrefix(slug: string, locale: string | undefined, languages: LanguageConfig[] | null): string;
|
|
68
|
+
/**
|
|
69
|
+
* hreflang alternates for every page that exists in at least two languages:
|
|
70
|
+
* slug -> { <code>: "/<slug>", ..., "x-default": "/<default-language slug>" }.
|
|
71
|
+
* Keys follow the order of `languages.json`; `x-default` points at the default
|
|
72
|
+
* language's page when it exists, otherwise at the first available language.
|
|
73
|
+
*/
|
|
74
|
+
export declare function buildLanguageAlternates(pages: readonly PageMeta[], languages: LanguageConfig[] | null): Map<string, Record<string, string>>;
|
|
75
|
+
/** Section slugs, in `sections` order, that have at least one page in the
|
|
76
|
+
* given variant prefix. */
|
|
77
|
+
export declare function sectionsForVariant(pages: readonly PageMeta[], sections: SectionConfig[] | null, prefix: string, languages: LanguageConfig[] | null, versions: VersionConfig[] | null): string[];
|
|
78
|
+
/** `pt-br` -> `pt_BR`, `de` -> `de` (Open Graph locale format). */
|
|
79
|
+
export declare function toOgLocale(code: string): string;
|
|
80
|
+
/**
|
|
81
|
+
* Language codes and version slugs must not collide with each other, with a
|
|
82
|
+
* section slug, or with the first segment of a section directory: all of them
|
|
83
|
+
* claim the same top-level folder or URL prefix.
|
|
84
|
+
*/
|
|
85
|
+
export declare function assertVariantsDisjoint(languages: LanguageConfig[] | null, versions: VersionConfig[] | null, sections: SectionConfig[] | null): void;
|
|
86
|
+
/**
|
|
87
|
+
* The default language lives at the docs root, so a `docs/<default code>/`
|
|
88
|
+
* folder is a mistake rather than a variant, and a language folder must come
|
|
89
|
+
* before a version folder. Both would otherwise publish surprising URLs.
|
|
90
|
+
*/
|
|
91
|
+
export declare function assertVariantLayout(files: readonly string[], languages: LanguageConfig[] | null, versions: VersionConfig[] | null): void;
|