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
|
@@ -7,6 +7,49 @@ import type {
|
|
|
7
7
|
GetDocParams,
|
|
8
8
|
ListDocsParams,
|
|
9
9
|
} from "@/services/mcp/types";
|
|
10
|
+
import {
|
|
11
|
+
defaultLanguage,
|
|
12
|
+
isVariantsConfigured,
|
|
13
|
+
languages,
|
|
14
|
+
versions,
|
|
15
|
+
} from "@/utils/variants";
|
|
16
|
+
|
|
17
|
+
/** The language/version a docs query is scoped to. Empty when the site has
|
|
18
|
+
* neither configured, so every page matches. */
|
|
19
|
+
export interface DocsFilter {
|
|
20
|
+
locale?: string;
|
|
21
|
+
version?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Resolve the scope of a docs query: the requested language and version, or
|
|
26
|
+
* the site's default language / default version when a request names none.
|
|
27
|
+
* A language or version the site does not declare matches nothing.
|
|
28
|
+
*/
|
|
29
|
+
export function resolveDocsFilter(params?: {
|
|
30
|
+
language?: string;
|
|
31
|
+
version?: string;
|
|
32
|
+
}): DocsFilter {
|
|
33
|
+
if (!isVariantsConfigured()) return {};
|
|
34
|
+
const filter: DocsFilter = {};
|
|
35
|
+
if (languages) {
|
|
36
|
+
filter.locale = params?.language ?? defaultLanguage()?.code ?? "";
|
|
37
|
+
}
|
|
38
|
+
if (versions) {
|
|
39
|
+
filter.version = params?.version ?? "";
|
|
40
|
+
}
|
|
41
|
+
return filter;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function matchesDocsFilter(
|
|
45
|
+
doc: { locale?: string; version?: string },
|
|
46
|
+
filter: DocsFilter,
|
|
47
|
+
): boolean {
|
|
48
|
+
return (
|
|
49
|
+
(filter.locale === undefined || doc.locale === filter.locale) &&
|
|
50
|
+
(filter.version === undefined || doc.version === filter.version)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
10
53
|
|
|
11
54
|
// Keep the corpus out of the function's JavaScript bundle. next.config.ts
|
|
12
55
|
// traces this fixed file into the RAG/MCP functions, just like docs-index.json.
|
|
@@ -63,6 +106,16 @@ export const DOCS_TOOLS: MCPToolDefinition[] = [
|
|
|
63
106
|
type: "number",
|
|
64
107
|
description: "Maximum number of results to return (default: 6)",
|
|
65
108
|
},
|
|
109
|
+
language: {
|
|
110
|
+
type: "string",
|
|
111
|
+
description:
|
|
112
|
+
"Language code to search (e.g. 'de'); defaults to the site's default language",
|
|
113
|
+
},
|
|
114
|
+
version: {
|
|
115
|
+
type: "string",
|
|
116
|
+
description:
|
|
117
|
+
"Documentation version slug to search (e.g. 'v1'); defaults to the current version",
|
|
118
|
+
},
|
|
66
119
|
},
|
|
67
120
|
required: ["query"],
|
|
68
121
|
},
|
|
@@ -95,23 +148,43 @@ export const DOCS_TOOLS: MCPToolDefinition[] = [
|
|
|
95
148
|
description:
|
|
96
149
|
"Optional directory to filter results (e.g., 'components')",
|
|
97
150
|
},
|
|
151
|
+
language: {
|
|
152
|
+
type: "string",
|
|
153
|
+
description:
|
|
154
|
+
"Language code to list (e.g. 'de'); defaults to the site's default language",
|
|
155
|
+
},
|
|
156
|
+
version: {
|
|
157
|
+
type: "string",
|
|
158
|
+
description:
|
|
159
|
+
"Documentation version slug to list (e.g. 'v1'); defaults to the current version",
|
|
160
|
+
},
|
|
98
161
|
},
|
|
99
162
|
},
|
|
100
163
|
},
|
|
101
164
|
];
|
|
102
165
|
|
|
103
166
|
/**
|
|
104
|
-
*
|
|
167
|
+
* Every documentation resource in every language and version. Indexes are
|
|
168
|
+
* built from this and filtered at query time.
|
|
169
|
+
*/
|
|
170
|
+
export async function listAllDocs(): Promise<DocsResource[]> {
|
|
171
|
+
return loadDocsContent().map((doc) => ({ ...doc }));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* List the documentation resources of one language/version (the default
|
|
176
|
+
* variant unless the params name another), optionally under a directory.
|
|
105
177
|
*/
|
|
106
178
|
export async function listDocs(
|
|
107
179
|
params?: ListDocsParams,
|
|
108
180
|
): Promise<DocsResource[]> {
|
|
109
181
|
const docsContent = loadDocsContent();
|
|
110
182
|
const filterDir = params?.directory?.replace(/\\\\/g, "/");
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
183
|
+
const filter = resolveDocsFilter(params);
|
|
184
|
+
return docsContent
|
|
185
|
+
.filter((doc) => matchesDocsFilter(doc, filter))
|
|
186
|
+
.filter((doc) => !filterDir || doc.path.includes(filterDir))
|
|
187
|
+
.map((doc) => ({ ...doc }));
|
|
115
188
|
}
|
|
116
189
|
|
|
117
190
|
/**
|
|
@@ -167,7 +240,7 @@ function chunkText(text: string, chunkSize = 800, overlap = 100): string[] {
|
|
|
167
240
|
*/
|
|
168
241
|
export async function getAllDocsChunks(): Promise<DocsChunk[]> {
|
|
169
242
|
const allChunks: DocsChunk[] = [];
|
|
170
|
-
const docs = await
|
|
243
|
+
const docs = await listAllDocs();
|
|
171
244
|
|
|
172
245
|
for (const doc of docs) {
|
|
173
246
|
const cleanContent = doc.content
|
|
@@ -182,6 +255,8 @@ export async function getAllDocsChunks(): Promise<DocsChunk[]> {
|
|
|
182
255
|
text: textChunks[i],
|
|
183
256
|
path: doc.path,
|
|
184
257
|
uri: doc.uri,
|
|
258
|
+
...(doc.locale !== undefined ? { locale: doc.locale } : {}),
|
|
259
|
+
...(doc.version !== undefined ? { version: doc.version } : {}),
|
|
185
260
|
});
|
|
186
261
|
}
|
|
187
262
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const mcpTypesTemplate = "export interface DocsResource {\n uri: string;\n name: string;\n path: string;\n content: string;\n}\n\nexport interface DocsChunk {\n id: string;\n text: string;\n path: string;\n uri: string;\n}\n\nexport interface GetDocParams {\n path: string;\n}\n\nexport interface ListDocsParams {\n directory?: string;\n}\n\nexport type MCPToolName = \"search_docs\" | \"get_doc\" | \"list_docs\";\n\nexport interface MCPToolDefinition {\n name: MCPToolName;\n description: string;\n inputSchema: {\n type: \"object\";\n properties: Record<string, unknown>;\n required?: string[];\n };\n}\n";
|
|
1
|
+
export declare const mcpTypesTemplate = "export interface DocsResource {\n uri: string;\n name: string;\n path: string;\n content: string;\n /** Language code and version slug; present only on sites that configure\n * languages.json / versions.json. */\n locale?: string;\n version?: string;\n}\n\nexport interface DocsChunk {\n id: string;\n text: string;\n path: string;\n uri: string;\n locale?: string;\n version?: string;\n}\n\nexport interface GetDocParams {\n path: string;\n}\n\nexport interface ListDocsParams {\n directory?: string;\n /** Language code and version slug to list; each defaults to the site's\n * default language / version when the site configures them. */\n language?: string;\n version?: string;\n}\n\nexport type MCPToolName = \"search_docs\" | \"get_doc\" | \"list_docs\";\n\nexport interface MCPToolDefinition {\n name: MCPToolName;\n description: string;\n inputSchema: {\n type: \"object\";\n properties: Record<string, unknown>;\n required?: string[];\n };\n}\n";
|
|
@@ -3,6 +3,10 @@ export const mcpTypesTemplate = `export interface DocsResource {
|
|
|
3
3
|
name: string;
|
|
4
4
|
path: string;
|
|
5
5
|
content: string;
|
|
6
|
+
/** Language code and version slug; present only on sites that configure
|
|
7
|
+
* languages.json / versions.json. */
|
|
8
|
+
locale?: string;
|
|
9
|
+
version?: string;
|
|
6
10
|
}
|
|
7
11
|
|
|
8
12
|
export interface DocsChunk {
|
|
@@ -10,6 +14,8 @@ export interface DocsChunk {
|
|
|
10
14
|
text: string;
|
|
11
15
|
path: string;
|
|
12
16
|
uri: string;
|
|
17
|
+
locale?: string;
|
|
18
|
+
version?: string;
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
export interface GetDocParams {
|
|
@@ -18,6 +24,10 @@ export interface GetDocParams {
|
|
|
18
24
|
|
|
19
25
|
export interface ListDocsParams {
|
|
20
26
|
directory?: string;
|
|
27
|
+
/** Language code and version slug to list; each defaults to the site's
|
|
28
|
+
* default language / version when the site configures them. */
|
|
29
|
+
language?: string;
|
|
30
|
+
version?: string;
|
|
21
31
|
}
|
|
22
32
|
|
|
23
33
|
export type MCPToolName = "search_docs" | "get_doc" | "list_docs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const searchServiceTemplate = "import MiniSearch from \"minisearch\";\nimport {
|
|
1
|
+
export declare const searchServiceTemplate = "import MiniSearch from \"minisearch\";\nimport {\n listAllDocs,\n matchesDocsFilter,\n resolveDocsFilter,\n} from \"@/services/mcp/tools\";\n\ninterface IndexedDoc {\n id: string;\n slug: string;\n title: string;\n content: string;\n locale?: string;\n version?: string;\n}\n\n/** The language/version a search is scoped to; each defaults to the site's\n * default variant when the site configures one. */\nexport interface SearchScope {\n locale?: string;\n version?: string;\n}\n\nexport interface SearchHit {\n slug: string;\n snippet: string;\n}\n\nlet index: MiniSearch<IndexedDoc> | null = null;\nlet docs: IndexedDoc[] = [];\nlet buildPromise: Promise<void> | null = null;\n\nconst CONTEXT_BEFORE = 60;\nconst CONTEXT_AFTER = 90;\n\n/**\n * Convert raw MDX (as extracted from the generated page templates) into plain,\n * human-readable text for search snippets: undoes the template-literal escaping\n * and strips common Markdown syntax so inline code shows as Test rather than a\n * backtick-wrapped or backslash-escaped fragment.\n */\nfunction toPlainText(text: string): string {\n return (\n text\n // Undo the template-literal escaping from the generated page files so\n // escaped backticks, dollar-braces and backslashes read as plain text.\n .replace(/\\\\([\\s\\S])/g, \"$1\")\n // Images and links -> visible text only.\n .replace(/!\\[([^\\]]*)\\]\\([^)]*\\)/g, \"$1\")\n .replace(/\\[([^\\]]*)\\]\\([^)]*\\)/g, \"$1\")\n // Bold markers.\n .replace(/\\*\\*([\\s\\S]*?)\\*\\*/g, \"$1\")\n // Line-leading markers: headings, blockquotes, list bullets.\n .replace(/^\\s{0,3}#{1,6}\\s+/gm, \"\")\n .replace(/^\\s{0,3}>\\s?/gm, \"\")\n .replace(/^\\s{0,3}[-*+]\\s+/gm, \"\")\n .replace(/^\\s{0,3}\\d+\\.\\s+/gm, \"\")\n // Inline code / escaped backticks -> plain text.\n .replace(/`/g, \"\")\n );\n}\n\nasync function ensureIndex(): Promise<MiniSearch<IndexedDoc>> {\n if (index) return index;\n if (buildPromise) {\n await buildPromise;\n return index!;\n }\n\n buildPromise = (async () => {\n // One index over every language and version; a search filters it down to\n // the variant the reader is looking at.\n const resources = await listAllDocs();\n\n docs = resources.map((doc) => {\n // Strip the leading \"app/\", the \"/page.ext\" suffix, and any Next.js\n // route-group segments like \"(site)\" which never appear in URLs. This\n // must match the URL slug produced by toDocPath() in mcp/tools.ts and\n // the nav slugs in the layout, otherwise content hits fail to map back\n // to a page on the client and get silently dropped.\n const slug = doc.path\n .replace(/^app\\//, \"\")\n .replace(/\\/page\\.\\w+$/, \"\")\n .split(\"/\")\n .filter((seg) => !(seg.startsWith(\"(\") && seg.endsWith(\")\")))\n .join(\"/\");\n const cleanContent = toPlainText(doc.content.replace(/\\r\\n/g, \"\\n\"))\n .replace(/\\n{3,}/g, \"\\n\\n\")\n .slice(0, 200_000);\n return {\n id: slug || \"__index__\",\n slug,\n title: doc.name,\n content: cleanContent,\n ...(doc.locale !== undefined ? { locale: doc.locale } : {}),\n ...(doc.version !== undefined ? { version: doc.version } : {}),\n };\n });\n\n index = new MiniSearch<IndexedDoc>({\n fields: [\"title\", \"content\"],\n storeFields: [\"slug\", \"title\", \"content\", \"locale\", \"version\"],\n searchOptions: {\n boost: { title: 3 },\n fuzzy: 0.2,\n prefix: true,\n },\n });\n\n index.addAll(docs);\n })();\n\n await buildPromise;\n return index!;\n}\n\nfunction extractSnippet(content: string, query: string): string {\n const lower = content.toLowerCase();\n const qLower = query.toLowerCase();\n const matchIdx = lower.indexOf(qLower);\n\n if (matchIdx === -1) {\n // Fuzzy match - no exact substring. Return start of content.\n const end = Math.min(content.length, CONTEXT_BEFORE + CONTEXT_AFTER);\n const raw = content.slice(0, end).trim();\n return raw.length < content.length ? raw + \"...\" : raw;\n }\n\n let start = Math.max(0, matchIdx - CONTEXT_BEFORE);\n let end = Math.min(content.length, matchIdx + query.length + CONTEXT_AFTER);\n\n // Align to word boundaries\n if (start > 0) {\n const space = content.indexOf(\" \", start);\n if (space !== -1 && space < matchIdx) start = space + 1;\n }\n if (end < content.length) {\n const space = content.lastIndexOf(\" \", end);\n if (space > matchIdx + query.length) end = space;\n }\n\n const prefix = start > 0 ? \"...\" : \"\";\n const suffix = end < content.length ? \"...\" : \"\";\n const snippet = content.slice(start, end).replace(/\\n+/g, \" \").trim();\n\n return prefix + snippet + suffix;\n}\n\nexport async function searchContent(\n query: string,\n limit = 10,\n scope: SearchScope = {},\n): Promise<SearchHit[]> {\n const q = query.trim();\n if (!q) return [];\n\n const idx = await ensureIndex();\n const filter = resolveDocsFilter({\n language: scope.locale,\n version: scope.version,\n });\n const results = idx.search(q, {\n // MiniSearch types a result's stored fields loosely; they are the\n // indexed doc's own locale and version.\n filter: (result) =>\n matchesDocsFilter(\n result as unknown as Pick<IndexedDoc, \"locale\" | \"version\">,\n filter,\n ),\n });\n\n return results.slice(0, limit).map((result) => {\n const doc = docs.find((d) => d.id === result.id);\n const content = doc?.content || \"\";\n return {\n slug: doc?.slug || \"\",\n snippet: extractSnippet(content, q),\n };\n });\n}\n";
|
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
export const searchServiceTemplate = `import MiniSearch from "minisearch";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
listAllDocs,
|
|
4
|
+
matchesDocsFilter,
|
|
5
|
+
resolveDocsFilter,
|
|
6
|
+
} from "@/services/mcp/tools";
|
|
3
7
|
|
|
4
8
|
interface IndexedDoc {
|
|
5
9
|
id: string;
|
|
6
10
|
slug: string;
|
|
7
11
|
title: string;
|
|
8
12
|
content: string;
|
|
13
|
+
locale?: string;
|
|
14
|
+
version?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The language/version a search is scoped to; each defaults to the site's
|
|
18
|
+
* default variant when the site configures one. */
|
|
19
|
+
export interface SearchScope {
|
|
20
|
+
locale?: string;
|
|
21
|
+
version?: string;
|
|
9
22
|
}
|
|
10
23
|
|
|
11
24
|
export interface SearchHit {
|
|
@@ -55,7 +68,9 @@ async function ensureIndex(): Promise<MiniSearch<IndexedDoc>> {
|
|
|
55
68
|
}
|
|
56
69
|
|
|
57
70
|
buildPromise = (async () => {
|
|
58
|
-
|
|
71
|
+
// One index over every language and version; a search filters it down to
|
|
72
|
+
// the variant the reader is looking at.
|
|
73
|
+
const resources = await listAllDocs();
|
|
59
74
|
|
|
60
75
|
docs = resources.map((doc) => {
|
|
61
76
|
// Strip the leading "app/", the "/page.ext" suffix, and any Next.js
|
|
@@ -77,12 +92,14 @@ async function ensureIndex(): Promise<MiniSearch<IndexedDoc>> {
|
|
|
77
92
|
slug,
|
|
78
93
|
title: doc.name,
|
|
79
94
|
content: cleanContent,
|
|
95
|
+
...(doc.locale !== undefined ? { locale: doc.locale } : {}),
|
|
96
|
+
...(doc.version !== undefined ? { version: doc.version } : {}),
|
|
80
97
|
};
|
|
81
98
|
});
|
|
82
99
|
|
|
83
100
|
index = new MiniSearch<IndexedDoc>({
|
|
84
101
|
fields: ["title", "content"],
|
|
85
|
-
storeFields: ["slug", "title", "content"],
|
|
102
|
+
storeFields: ["slug", "title", "content", "locale", "version"],
|
|
86
103
|
searchOptions: {
|
|
87
104
|
boost: { title: 3 },
|
|
88
105
|
fuzzy: 0.2,
|
|
@@ -132,12 +149,25 @@ function extractSnippet(content: string, query: string): string {
|
|
|
132
149
|
export async function searchContent(
|
|
133
150
|
query: string,
|
|
134
151
|
limit = 10,
|
|
152
|
+
scope: SearchScope = {},
|
|
135
153
|
): Promise<SearchHit[]> {
|
|
136
154
|
const q = query.trim();
|
|
137
155
|
if (!q) return [];
|
|
138
156
|
|
|
139
157
|
const idx = await ensureIndex();
|
|
140
|
-
const
|
|
158
|
+
const filter = resolveDocsFilter({
|
|
159
|
+
language: scope.locale,
|
|
160
|
+
version: scope.version,
|
|
161
|
+
});
|
|
162
|
+
const results = idx.search(q, {
|
|
163
|
+
// MiniSearch types a result's stored fields loosely; they are the
|
|
164
|
+
// indexed doc's own locale and version.
|
|
165
|
+
filter: (result) =>
|
|
166
|
+
matchesDocsFilter(
|
|
167
|
+
result as unknown as Pick<IndexedDoc, "locale" | "version">,
|
|
168
|
+
filter,
|
|
169
|
+
),
|
|
170
|
+
});
|
|
141
171
|
|
|
142
172
|
return results.slice(0, limit).map((result) => {
|
|
143
173
|
const doc = docs.find((d) => d.id === result.id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const orderNavItemsTemplate = "export interface PagesProps {\n slug: string;\n title: string;\n date: string | null;\n category: string;\n description?: string;\n path?: string;\n categoryOrder?: number;\n order?: number;\n section?: string;\n navIcon?: string;\n categoryIcon?: string;\n httpMethod?: string;\n}\n\ninterface AccProps {\n [key: string]: {\n categoryOrder: number;\n icon?: string;\n pages: {\n date: string | null;\n slug: string;\n title: string;\n order: number;\n icon?: string;\n httpMethod?: string;\n }[];\n };\n}\n\nfunction transformPagesToGroupedStructure(pages: PagesProps[]) {\n const grouped = pages.reduce((acc: AccProps, page: PagesProps) => {\n const category = page.category || \"Uncategorized\";\n\n if (!acc[category]) {\n acc[category] = {\n categoryOrder: page.categoryOrder || 0,\n pages: [],\n };\n }\n\n // The first page in a category to declare a categoryIcon sets it.\n if (!acc[category].icon && page.categoryIcon) {\n acc[category].icon = page.categoryIcon;\n }\n\n acc[category].pages.push({\n date: page.date,\n slug: page.slug,\n title: page.title,\n order: page.order || 0,\n icon: page.navIcon,\n httpMethod: page.httpMethod,\n });\n\n return acc;\n }, {});\n\n return Object.entries(grouped)\n .sort(([, a], [, b]) => a.categoryOrder - b.categoryOrder)\n .map(([categoryName, categoryData], index) => ({\n slug: index === 0 ? \"\" : categoryName.toLowerCase().replace(/\\s+/g, \"-\"),\n label: categoryName,\n icon: categoryData.icon,\n links: categoryData.pages.sort((a, b) => a.order - b.order),\n }));\n}\n\nexport { transformPagesToGroupedStructure };\n";
|
|
1
|
+
export declare const orderNavItemsTemplate = "export interface PagesProps {\n slug: string;\n title: string;\n date: string | null;\n category: string;\n description?: string;\n path?: string;\n categoryOrder?: number;\n order?: number;\n section?: string;\n navIcon?: string;\n categoryIcon?: string;\n httpMethod?: string;\n locale?: string;\n version?: string;\n}\n\ninterface AccProps {\n [key: string]: {\n categoryOrder: number;\n icon?: string;\n pages: {\n date: string | null;\n slug: string;\n title: string;\n order: number;\n icon?: string;\n httpMethod?: string;\n }[];\n };\n}\n\nfunction transformPagesToGroupedStructure(pages: PagesProps[]) {\n const grouped = pages.reduce((acc: AccProps, page: PagesProps) => {\n const category = page.category || \"Uncategorized\";\n\n if (!acc[category]) {\n acc[category] = {\n categoryOrder: page.categoryOrder || 0,\n pages: [],\n };\n }\n\n // The first page in a category to declare a categoryIcon sets it.\n if (!acc[category].icon && page.categoryIcon) {\n acc[category].icon = page.categoryIcon;\n }\n\n acc[category].pages.push({\n date: page.date,\n slug: page.slug,\n title: page.title,\n order: page.order || 0,\n icon: page.navIcon,\n httpMethod: page.httpMethod,\n });\n\n return acc;\n }, {});\n\n return Object.entries(grouped)\n .sort(([, a], [, b]) => a.categoryOrder - b.categoryOrder)\n .map(([categoryName, categoryData], index) => ({\n slug: index === 0 ? \"\" : categoryName.toLowerCase().replace(/\\s+/g, \"-\"),\n label: categoryName,\n icon: categoryData.icon,\n links: categoryData.pages.sort((a, b) => a.order - b.order),\n }));\n}\n\nexport { transformPagesToGroupedStructure };\n";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const stringsUtilTemplate: string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DEFAULT_UI_STRINGS } from "../../lib/ui-strings.js";
|
|
2
|
+
const defaults = Object.entries(DEFAULT_UI_STRINGS)
|
|
3
|
+
.map(([key, value]) => ` ${key}: ${JSON.stringify(value)},`)
|
|
4
|
+
.join("\n");
|
|
5
|
+
export const stringsUtilTemplate = `import { languages } from "@/utils/variants";
|
|
6
|
+
|
|
7
|
+
// The site's own chrome strings. A languages.json entry overrides them for
|
|
8
|
+
// its language through its \`strings\` object; anything it leaves out keeps
|
|
9
|
+
// the default below.
|
|
10
|
+
export const DEFAULT_STRINGS = {
|
|
11
|
+
${defaults}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type UiStrings = { [K in keyof typeof DEFAULT_STRINGS]: string };
|
|
15
|
+
|
|
16
|
+
export function getStrings(locale?: string): UiStrings {
|
|
17
|
+
const overrides = languages?.find(
|
|
18
|
+
(language) => language.code === locale,
|
|
19
|
+
)?.strings;
|
|
20
|
+
return overrides ? { ...DEFAULT_STRINGS, ...overrides } : DEFAULT_STRINGS;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Fills a \`{count}\` placeholder in a string. */
|
|
24
|
+
export function withCount(template: string, count: number): string {
|
|
25
|
+
return template.replace("{count}", String(count));
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const variantsUtilTemplate = "import rawLanguages from \"@/languages.json\";\nimport rawVersions from \"@/versions.json\";\n\n// Languages (languages.json) and versions (versions.json) of this site. A\n// variant's folder is its URL prefix - \"de\", \"v1\", \"de/v1\" - and the default\n// language and version live at the docs root with no prefix. The CLI\n// validated both files when it generated this app, so this module only has to\n// read them. The resolver mirrors the CLI's src/lib/variants.ts; keep the two\n// in step.\n\nexport interface LanguageConfig {\n code: string;\n label: string;\n default?: boolean;\n strings?: Record<string, string>;\n}\n\nexport interface VersionConfig {\n /** URL prefix and folder name; \"\" for the default version at the docs root. */\n slug: string;\n label: string;\n default?: boolean;\n}\n\nexport interface VariantResolution {\n /** Language code; undefined when languages.json is not configured. */\n locale?: string;\n /** Version slug (\"\" for the default); undefined when not configured. */\n version?: string;\n /** URL prefix: \"\", \"de\", \"v1\", or \"de/v1\". */\n prefix: string;\n /** The slug with the variant prefix removed. */\n rest: string;\n}\n\nfunction readLanguages(raw: unknown): LanguageConfig[] | null {\n if (!Array.isArray(raw) || raw.length === 0) return null;\n return raw as LanguageConfig[];\n}\n\nfunction readVersions(raw: unknown): VersionConfig[] | null {\n if (!Array.isArray(raw) || raw.length === 0) return null;\n return (raw as Partial<VersionConfig>[]).map((entry) => ({\n slug: entry.default ? \"\" : (entry.slug ?? \"\"),\n label: entry.label ?? \"\",\n default: entry.default === true,\n }));\n}\n\nexport const languages = readLanguages(rawLanguages);\nexport const versions = readVersions(rawVersions);\n\nexport function isVariantsConfigured(): boolean {\n return languages !== null || versions !== null;\n}\n\nexport function defaultLanguage(): LanguageConfig | null {\n return languages?.find((language) => language.default) ?? null;\n}\n\nexport function defaultVersion(): VersionConfig | null {\n return versions?.find((version) => version.default) ?? null;\n}\n\nexport function joinVariantSlug(prefix: string, slug: string): string {\n if (!prefix) return slug;\n if (slug === \"\") return prefix;\n return prefix + \"/\" + slug;\n}\n\n/**\n * Resolves the variant of a URL slug: a leading declared language folder is\n * consumed first, then a declared version folder. \"de\" alone is the German\n * home, \"de/v1\" the German v1 home.\n */\nexport function resolveVariantFromSlug(slug: string): VariantResolution {\n const normalized = slug.replace(/^\\/+|\\/+$/g, \"\");\n const segments = normalized === \"\" ? [] : normalized.split(\"/\");\n let locale = languages ? (defaultLanguage()?.code ?? \"\") : undefined;\n let version = versions ? \"\" : undefined;\n let consumed = 0;\n const prefix: string[] = [];\n\n const language = languages?.find(\n (entry) => !entry.default && entry.code === segments[0],\n );\n if (language) {\n locale = language.code;\n prefix.push(language.code);\n consumed = 1;\n }\n const versionEntry = versions?.find(\n (entry) => !entry.default && entry.slug === segments[consumed],\n );\n if (versionEntry) {\n version = versionEntry.slug;\n prefix.push(versionEntry.slug);\n consumed += 1;\n }\n\n return {\n ...(locale !== undefined ? { locale } : {}),\n ...(version !== undefined ? { version } : {}),\n prefix: prefix.join(\"/\"),\n rest: segments.slice(consumed).join(\"/\"),\n };\n}\n\n/** Key of a navigation.json object entry: the URL prefix of the scope. */\nexport function navigationScopeKey(\n prefix: string,\n sectionSlug: string,\n): string {\n return [prefix, sectionSlug].filter(Boolean).join(\"/\");\n}\n\n/** URL prefix of a language/version pair; the default of either is \"\". */\nexport function variantPrefix(\n locale: string | undefined,\n version: string | undefined,\n): string {\n const language =\n languages && locale !== undefined\n ? languages.find((entry) => entry.code === locale)\n : undefined;\n const versionEntry =\n versions && version !== undefined\n ? versions.find((entry) => entry.slug === version)\n : undefined;\n return joinVariantSlug(\n language && !language.default ? language.code : \"\",\n versionEntry && !versionEntry.default ? versionEntry.slug : \"\",\n );\n}\n\nexport function pageVariantPrefix(page: {\n locale?: string;\n version?: string;\n}): string {\n return variantPrefix(page.locale, page.version);\n}\n\n/** The slug without its language prefix: the same page in every language. */\nexport function stripLanguagePrefix(\n slug: string,\n locale: string | undefined,\n): string {\n if (!languages || locale === undefined) return slug;\n const language = languages.find((entry) => entry.code === locale);\n if (!language || language.default) return slug;\n if (slug === language.code) return \"\";\n if (slug.startsWith(language.code + \"/\")) {\n return slug.slice(language.code.length + 1);\n }\n return slug;\n}\n\n/** The slug without its whole variant prefix: the same page in every variant. */\nexport function stripVariantPrefix(\n slug: string,\n locale: string | undefined,\n version: string | undefined,\n): string {\n const prefix = variantPrefix(locale, version);\n if (!prefix) return slug;\n if (slug === prefix) return \"\";\n if (slug.startsWith(prefix + \"/\")) return slug.slice(prefix.length + 1);\n return slug;\n}\n";
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
export const variantsUtilTemplate = `import rawLanguages from "@/languages.json";
|
|
2
|
+
import rawVersions from "@/versions.json";
|
|
3
|
+
|
|
4
|
+
// Languages (languages.json) and versions (versions.json) of this site. A
|
|
5
|
+
// variant's folder is its URL prefix - "de", "v1", "de/v1" - and the default
|
|
6
|
+
// language and version live at the docs root with no prefix. The CLI
|
|
7
|
+
// validated both files when it generated this app, so this module only has to
|
|
8
|
+
// read them. The resolver mirrors the CLI's src/lib/variants.ts; keep the two
|
|
9
|
+
// in step.
|
|
10
|
+
|
|
11
|
+
export interface LanguageConfig {
|
|
12
|
+
code: string;
|
|
13
|
+
label: string;
|
|
14
|
+
default?: boolean;
|
|
15
|
+
strings?: Record<string, string>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface VersionConfig {
|
|
19
|
+
/** URL prefix and folder name; "" for the default version at the docs root. */
|
|
20
|
+
slug: string;
|
|
21
|
+
label: string;
|
|
22
|
+
default?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface VariantResolution {
|
|
26
|
+
/** Language code; undefined when languages.json is not configured. */
|
|
27
|
+
locale?: string;
|
|
28
|
+
/** Version slug ("" for the default); undefined when not configured. */
|
|
29
|
+
version?: string;
|
|
30
|
+
/** URL prefix: "", "de", "v1", or "de/v1". */
|
|
31
|
+
prefix: string;
|
|
32
|
+
/** The slug with the variant prefix removed. */
|
|
33
|
+
rest: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function readLanguages(raw: unknown): LanguageConfig[] | null {
|
|
37
|
+
if (!Array.isArray(raw) || raw.length === 0) return null;
|
|
38
|
+
return raw as LanguageConfig[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function readVersions(raw: unknown): VersionConfig[] | null {
|
|
42
|
+
if (!Array.isArray(raw) || raw.length === 0) return null;
|
|
43
|
+
return (raw as Partial<VersionConfig>[]).map((entry) => ({
|
|
44
|
+
slug: entry.default ? "" : (entry.slug ?? ""),
|
|
45
|
+
label: entry.label ?? "",
|
|
46
|
+
default: entry.default === true,
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const languages = readLanguages(rawLanguages);
|
|
51
|
+
export const versions = readVersions(rawVersions);
|
|
52
|
+
|
|
53
|
+
export function isVariantsConfigured(): boolean {
|
|
54
|
+
return languages !== null || versions !== null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function defaultLanguage(): LanguageConfig | null {
|
|
58
|
+
return languages?.find((language) => language.default) ?? null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function defaultVersion(): VersionConfig | null {
|
|
62
|
+
return versions?.find((version) => version.default) ?? null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function joinVariantSlug(prefix: string, slug: string): string {
|
|
66
|
+
if (!prefix) return slug;
|
|
67
|
+
if (slug === "") return prefix;
|
|
68
|
+
return prefix + "/" + slug;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Resolves the variant of a URL slug: a leading declared language folder is
|
|
73
|
+
* consumed first, then a declared version folder. "de" alone is the German
|
|
74
|
+
* home, "de/v1" the German v1 home.
|
|
75
|
+
*/
|
|
76
|
+
export function resolveVariantFromSlug(slug: string): VariantResolution {
|
|
77
|
+
const normalized = slug.replace(/^\\/+|\\/+$/g, "");
|
|
78
|
+
const segments = normalized === "" ? [] : normalized.split("/");
|
|
79
|
+
let locale = languages ? (defaultLanguage()?.code ?? "") : undefined;
|
|
80
|
+
let version = versions ? "" : undefined;
|
|
81
|
+
let consumed = 0;
|
|
82
|
+
const prefix: string[] = [];
|
|
83
|
+
|
|
84
|
+
const language = languages?.find(
|
|
85
|
+
(entry) => !entry.default && entry.code === segments[0],
|
|
86
|
+
);
|
|
87
|
+
if (language) {
|
|
88
|
+
locale = language.code;
|
|
89
|
+
prefix.push(language.code);
|
|
90
|
+
consumed = 1;
|
|
91
|
+
}
|
|
92
|
+
const versionEntry = versions?.find(
|
|
93
|
+
(entry) => !entry.default && entry.slug === segments[consumed],
|
|
94
|
+
);
|
|
95
|
+
if (versionEntry) {
|
|
96
|
+
version = versionEntry.slug;
|
|
97
|
+
prefix.push(versionEntry.slug);
|
|
98
|
+
consumed += 1;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
...(locale !== undefined ? { locale } : {}),
|
|
103
|
+
...(version !== undefined ? { version } : {}),
|
|
104
|
+
prefix: prefix.join("/"),
|
|
105
|
+
rest: segments.slice(consumed).join("/"),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Key of a navigation.json object entry: the URL prefix of the scope. */
|
|
110
|
+
export function navigationScopeKey(
|
|
111
|
+
prefix: string,
|
|
112
|
+
sectionSlug: string,
|
|
113
|
+
): string {
|
|
114
|
+
return [prefix, sectionSlug].filter(Boolean).join("/");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** URL prefix of a language/version pair; the default of either is "". */
|
|
118
|
+
export function variantPrefix(
|
|
119
|
+
locale: string | undefined,
|
|
120
|
+
version: string | undefined,
|
|
121
|
+
): string {
|
|
122
|
+
const language =
|
|
123
|
+
languages && locale !== undefined
|
|
124
|
+
? languages.find((entry) => entry.code === locale)
|
|
125
|
+
: undefined;
|
|
126
|
+
const versionEntry =
|
|
127
|
+
versions && version !== undefined
|
|
128
|
+
? versions.find((entry) => entry.slug === version)
|
|
129
|
+
: undefined;
|
|
130
|
+
return joinVariantSlug(
|
|
131
|
+
language && !language.default ? language.code : "",
|
|
132
|
+
versionEntry && !versionEntry.default ? versionEntry.slug : "",
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function pageVariantPrefix(page: {
|
|
137
|
+
locale?: string;
|
|
138
|
+
version?: string;
|
|
139
|
+
}): string {
|
|
140
|
+
return variantPrefix(page.locale, page.version);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** The slug without its language prefix: the same page in every language. */
|
|
144
|
+
export function stripLanguagePrefix(
|
|
145
|
+
slug: string,
|
|
146
|
+
locale: string | undefined,
|
|
147
|
+
): string {
|
|
148
|
+
if (!languages || locale === undefined) return slug;
|
|
149
|
+
const language = languages.find((entry) => entry.code === locale);
|
|
150
|
+
if (!language || language.default) return slug;
|
|
151
|
+
if (slug === language.code) return "";
|
|
152
|
+
if (slug.startsWith(language.code + "/")) {
|
|
153
|
+
return slug.slice(language.code.length + 1);
|
|
154
|
+
}
|
|
155
|
+
return slug;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** The slug without its whole variant prefix: the same page in every variant. */
|
|
159
|
+
export function stripVariantPrefix(
|
|
160
|
+
slug: string,
|
|
161
|
+
locale: string | undefined,
|
|
162
|
+
version: string | undefined,
|
|
163
|
+
): string {
|
|
164
|
+
const prefix = variantPrefix(locale, version);
|
|
165
|
+
if (!prefix) return slug;
|
|
166
|
+
if (slug === prefix) return "";
|
|
167
|
+
if (slug.startsWith(prefix + "/")) return slug.slice(prefix.length + 1);
|
|
168
|
+
return slug;
|
|
169
|
+
}
|
|
170
|
+
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "doccupine",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.160",
|
|
4
4
|
"description": "Free and open-source documentation platform. Write MDX, get a production-ready site with AI chat, built-in components, and an MCP server - in one command.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"engines": {
|
|
11
11
|
"node": ">=22.12.0"
|
|
12
12
|
},
|
|
13
|
-
"packageManager": "pnpm@12.
|
|
13
|
+
"packageManager": "pnpm@12.9.1",
|
|
14
14
|
"scripts": {
|
|
15
15
|
"clean": "node scripts/clean.mjs",
|
|
16
16
|
"build": "pnpm clean && tsc",
|
|
@@ -43,24 +43,24 @@
|
|
|
43
43
|
"license": "SEE LICENSE IN LICENSE",
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@readme/openapi-parser": "^9.0.0",
|
|
46
|
-
"chalk": "^6.0.
|
|
46
|
+
"chalk": "^6.0.1",
|
|
47
47
|
"chokidar": "^5.0.0",
|
|
48
48
|
"commander": "^15.0.0",
|
|
49
|
-
"fs-extra": "^11.4.
|
|
49
|
+
"fs-extra": "^11.4.1",
|
|
50
50
|
"gray-matter": "^4.0.3",
|
|
51
|
-
"lucide-react": "^1.
|
|
52
|
-
"next": "^16.3.
|
|
51
|
+
"lucide-react": "^1.52.0",
|
|
52
|
+
"next": "^16.3.8",
|
|
53
53
|
"prompts": "^2.4.2",
|
|
54
|
-
"react": "^19.
|
|
55
|
-
"react-dom": "^19.
|
|
54
|
+
"react": "^19.3.0",
|
|
55
|
+
"react-dom": "^19.3.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/fs-extra": "^11.0.4",
|
|
59
|
-
"@types/node": "^26.4
|
|
59
|
+
"@types/node": "^26.6.4",
|
|
60
60
|
"@types/prompts": "^2.4.9",
|
|
61
|
-
"prettier": "^3.9.
|
|
61
|
+
"prettier": "^3.9.9",
|
|
62
62
|
"typescript": "^7.0.2",
|
|
63
|
-
"vitest": "^5.0.
|
|
63
|
+
"vitest": "^5.0.3"
|
|
64
64
|
},
|
|
65
65
|
"files": [
|
|
66
66
|
"dist/**/*"
|