@vercel/geistdocs 1.12.0 → 1.14.0
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/dist/cli/index.js +1 -1
- package/dist/config.d.ts +5 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +35 -0
- package/dist/controls.d.ts.map +1 -1
- package/dist/controls.js +7 -5
- package/dist/footer.d.ts +1 -1
- package/dist/footer.d.ts.map +1 -1
- package/dist/footer.js +1 -1
- package/dist/home-layout.d.ts.map +1 -1
- package/dist/home-layout.js +2 -7
- package/dist/internal/chat/shell.d.ts.map +1 -1
- package/dist/internal/chat/shell.js +2 -1
- package/dist/internal/footer/rss-button.d.ts +3 -1
- package/dist/internal/footer/rss-button.d.ts.map +1 -1
- package/dist/internal/footer/rss-button.js +2 -1
- package/dist/internal/localized-link.d.ts.map +1 -1
- package/dist/internal/localized-link.js +9 -4
- package/dist/internal/page-actions-client.d.ts +1 -0
- package/dist/internal/page-actions-client.d.ts.map +1 -1
- package/dist/internal/page-actions-client.js +2 -4
- package/dist/internal/provider-client.d.ts.map +1 -1
- package/dist/internal/provider-client.js +1 -1
- package/dist/internal/search.d.ts.map +1 -1
- package/dist/internal/search.js +2 -1
- package/dist/internal/sidebar-responsive.d.ts +3 -0
- package/dist/internal/sidebar-responsive.d.ts.map +1 -0
- package/dist/internal/sidebar-responsive.js +10 -0
- package/dist/internal/sidebar-tree.d.ts +23 -0
- package/dist/internal/sidebar-tree.d.ts.map +1 -0
- package/dist/internal/sidebar-tree.js +115 -0
- package/dist/internal/sidebar.d.ts +2 -5
- package/dist/internal/sidebar.d.ts.map +1 -1
- package/dist/internal/sidebar.js +282 -44
- package/dist/internal/table-of-contents.js +1 -1
- package/dist/internal/ui/sheet.d.ts.map +1 -1
- package/dist/internal/ui/sheet.js +2 -2
- package/dist/internal/version-paths.d.ts +49 -0
- package/dist/internal/version-paths.d.ts.map +1 -0
- package/dist/internal/version-paths.js +57 -0
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +1 -6
- package/dist/mdx.d.ts +1 -0
- package/dist/mdx.d.ts.map +1 -1
- package/dist/mobile-docs-bar.d.ts.map +1 -1
- package/dist/mobile-docs-bar.js +3 -3
- package/dist/navbar.js +1 -1
- package/dist/pages/docs.d.ts +25 -7
- package/dist/pages/docs.d.ts.map +1 -1
- package/dist/pages/docs.js +40 -8
- package/dist/proxy.d.ts +4 -3
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +124 -46
- package/dist/routes/agents.d.ts +1 -1
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/agents.js +27 -16
- package/dist/routes/chat.d.ts +1 -1
- package/dist/routes/chat.d.ts.map +1 -1
- package/dist/routes/chat.js +18 -11
- package/dist/routes/discovery.d.ts +6 -2
- package/dist/routes/discovery.d.ts.map +1 -1
- package/dist/routes/discovery.js +6 -12
- package/dist/routes/sitemap.d.ts +3 -2
- package/dist/routes/sitemap.d.ts.map +1 -1
- package/dist/routes/sitemap.js +18 -5
- package/dist/source-config.d.ts +1 -0
- package/dist/source-config.d.ts.map +1 -1
- package/dist/source-config.js +1 -0
- package/dist/source.d.ts +40 -2
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +132 -15
- package/dist/versions.d.ts +22 -2
- package/dist/versions.d.ts.map +1 -1
- package/dist/versions.js +29 -6
- package/docs/agents.md +2 -2
- package/docs/llms.txt +313 -31
- package/docs/manifest.json +10 -9
- package/docs/pages/configuration.md +26 -1
- package/docs/pages/getting-started.md +2 -0
- package/docs/pages/guides/nested-navigation.md +174 -13
- package/docs/pages/md.md +4 -0
- package/docs/pages/migration.md +4 -0
- package/docs/pages/proxy.md +15 -0
- package/docs/pages/rss.md +2 -0
- package/docs/pages/syntax.md +2 -1
- package/docs/pages/versioned-docs.md +68 -0
- package/docs/sitemap.md +1 -1
- package/package.json +1 -1
- package/source-config.js +1 -0
- package/template/AGENTS.md +2 -0
- package/template/app/[lang]/rss.xml/route.ts +7 -3
- package/template/app/styles/geistdocs.css +8 -6
- package/template/content/docs/configuration.mdx +26 -1
- package/template/content/docs/getting-started.mdx +2 -0
- package/template/content/docs/guides/nested-navigation.mdx +174 -12
- package/template/content/docs/md.mdx +4 -0
- package/template/content/docs/migration.mdx +4 -0
- package/template/content/docs/proxy.mdx +15 -0
- package/template/content/docs/rss.mdx +2 -0
- package/template/content/docs/syntax.mdx +2 -1
- package/template/content/docs/versioned-docs.mdx +68 -0
- package/template/package.json +1 -1
- package/theme.css +150 -0
package/dist/routes/chat.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { convertToModelMessages, createUIMessageStream, createUIMessageStreamResponse, stepCountIs, streamText, tool, } from "ai";
|
|
2
2
|
import { initAdvancedSearch } from "fumadocs-core/search/server";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
+
import { getPublicPath } from "../config";
|
|
4
5
|
import { isPageVisibleForSurface } from "../internal/page-visibility";
|
|
5
6
|
const DEFAULT_CHAT_MODEL = "openai/gpt-4.1-mini";
|
|
6
7
|
const MAX_CONTEXT_CHARS = 1500;
|
|
@@ -91,7 +92,7 @@ const createSearchServer = (sources, lang) => {
|
|
|
91
92
|
}));
|
|
92
93
|
return initAdvancedSearch({ indexes });
|
|
93
94
|
};
|
|
94
|
-
const resolveSearchResult = ({ lang, sources, url, }) => {
|
|
95
|
+
const resolveSearchResult = ({ basePath, lang, sources, url, }) => {
|
|
95
96
|
const result = sources
|
|
96
97
|
.map((source) => source.source.getPageByHref(url, { language: lang }))
|
|
97
98
|
.find((entry) => entry?.page);
|
|
@@ -105,14 +106,15 @@ const resolveSearchResult = ({ lang, sources, url, }) => {
|
|
|
105
106
|
description: data.description ?? "",
|
|
106
107
|
content: getStructuredContent(page),
|
|
107
108
|
slug: page.url,
|
|
109
|
+
url: getPublicPath(page.url, basePath),
|
|
108
110
|
};
|
|
109
111
|
};
|
|
110
|
-
const searchDocs = async ({ lang, limit, query, sources, }) => {
|
|
112
|
+
const searchDocs = async ({ basePath, lang, limit, query, sources, }) => {
|
|
111
113
|
const searchServer = createSearchServer(sources, lang);
|
|
112
114
|
const results = await searchServer.search(query);
|
|
113
115
|
const seenSlugs = new Set();
|
|
114
116
|
return results
|
|
115
|
-
.map(({ url }) => resolveSearchResult({ lang, sources, url }))
|
|
117
|
+
.map(({ url }) => resolveSearchResult({ basePath, lang, sources, url }))
|
|
116
118
|
.filter((doc) => Boolean(doc))
|
|
117
119
|
.filter((doc) => {
|
|
118
120
|
if (seenSlugs.has(doc.slug)) {
|
|
@@ -123,7 +125,7 @@ const searchDocs = async ({ lang, limit, query, sources, }) => {
|
|
|
123
125
|
})
|
|
124
126
|
.slice(0, limit);
|
|
125
127
|
};
|
|
126
|
-
const formatDocForContext = (doc) => `**${doc.title}**\nURL: ${doc.
|
|
128
|
+
const formatDocForContext = (doc) => `**${doc.title}**\nURL: ${doc.url}\n${doc.description || ""}\n\n${doc.content.slice(0, MAX_CONTEXT_CHARS)}${doc.content.length > MAX_CONTEXT_CHARS ? "..." : ""}`;
|
|
127
129
|
const getRouteCandidates = ({ basePath, currentRoute, lang, }) => {
|
|
128
130
|
const pathname = normalizePathname(currentRoute);
|
|
129
131
|
const withoutBasePath = stripBasePath(pathname, basePath);
|
|
@@ -156,6 +158,7 @@ const getCurrentPageDoc = async ({ basePath, currentRoute, lang, pageContext, so
|
|
|
156
158
|
description: "",
|
|
157
159
|
content: pageContext.content,
|
|
158
160
|
slug: pageContext.url,
|
|
161
|
+
url: pageContext.url,
|
|
159
162
|
};
|
|
160
163
|
}
|
|
161
164
|
const result = findCurrentPage({ basePath, currentRoute, lang, sources });
|
|
@@ -168,13 +171,14 @@ const getCurrentPageDoc = async ({ basePath, currentRoute, lang, pageContext, so
|
|
|
168
171
|
description: data.description ?? "",
|
|
169
172
|
content: await result.source.getPageMarkdown(result.page),
|
|
170
173
|
slug: result.page.url,
|
|
174
|
+
url: getPublicPath(result.page.url, basePath),
|
|
171
175
|
};
|
|
172
176
|
};
|
|
173
177
|
const isFirstUserMessage = (messages) => messages.filter((message) => message.role === "user").length === 1;
|
|
174
178
|
const createSourceChunks = (docs) => docs.map((doc, index) => ({
|
|
175
179
|
type: "source-url",
|
|
176
180
|
sourceId: `doc-${index}-${doc.slug}`,
|
|
177
|
-
url: doc.
|
|
181
|
+
url: doc.url,
|
|
178
182
|
title: doc.title,
|
|
179
183
|
}));
|
|
180
184
|
const buildProxyMessages = async ({ actualMessages, config, currentRoute, defaultLanguage, languages, pageContext, routeSources, }) => {
|
|
@@ -201,6 +205,7 @@ const buildProxyMessages = async ({ actualMessages, config, currentRoute, defaul
|
|
|
201
205
|
});
|
|
202
206
|
const relatedDocs = userQuestion.trim()
|
|
203
207
|
? await searchDocs({
|
|
208
|
+
basePath: config.basePath,
|
|
204
209
|
lang,
|
|
205
210
|
limit: MAX_PROXY_RELATED_PAGES,
|
|
206
211
|
query: userQuestion,
|
|
@@ -210,7 +215,7 @@ const buildProxyMessages = async ({ actualMessages, config, currentRoute, defaul
|
|
|
210
215
|
const filteredRelatedDocs = relatedDocs.filter((doc) => doc.slug !== currentPageDoc?.slug);
|
|
211
216
|
const contextParts = [];
|
|
212
217
|
if (currentPageDoc) {
|
|
213
|
-
contextParts.push(`Here's the content from the current page:\n\n**Page:** ${currentPageDoc.title}\n**URL:** ${currentPageDoc.
|
|
218
|
+
contextParts.push(`Here's the content from the current page:\n\n**Page:** ${currentPageDoc.title}\n**URL:** ${currentPageDoc.url}\n\n---\n\n${currentPageDoc.content.slice(0, MAX_CONTEXT_CHARS)}${currentPageDoc.content.length > MAX_CONTEXT_CHARS ? "..." : ""}`);
|
|
214
219
|
}
|
|
215
220
|
if (filteredRelatedDocs.length > 0) {
|
|
216
221
|
contextParts.push(`Related documentation pages:\n\n${filteredRelatedDocs.map(formatDocForContext).join("\n\n---\n\n")}`);
|
|
@@ -337,7 +342,7 @@ You are a helpful assistant specializing in answering questions strictly. If inf
|
|
|
337
342
|
- Be friendly, clear, and specific.`;
|
|
338
343
|
return [basePrompt, config.ai?.prompt].filter(Boolean).join("\n\n");
|
|
339
344
|
};
|
|
340
|
-
const createTools = (writer, sources, defaultLanguage) => {
|
|
345
|
+
const createTools = (writer, sources, defaultLanguage, basePath) => {
|
|
341
346
|
const log = (message) => {
|
|
342
347
|
console.log(`[Geistdocs chat] ${message}`);
|
|
343
348
|
};
|
|
@@ -355,6 +360,7 @@ const createTools = (writer, sources, defaultLanguage) => {
|
|
|
355
360
|
try {
|
|
356
361
|
log(`Creating search server for language: ${lang}`);
|
|
357
362
|
const trimmedResults = await searchDocs({
|
|
363
|
+
basePath,
|
|
358
364
|
lang,
|
|
359
365
|
limit: MAX_TOOL_RESULTS,
|
|
360
366
|
query,
|
|
@@ -367,7 +373,7 @@ const createTools = (writer, sources, defaultLanguage) => {
|
|
|
367
373
|
writer.write({
|
|
368
374
|
type: "source-url",
|
|
369
375
|
sourceId: `doc-${index}-${doc.slug}`,
|
|
370
|
-
url: doc.
|
|
376
|
+
url: doc.url,
|
|
371
377
|
title: doc.title,
|
|
372
378
|
});
|
|
373
379
|
}
|
|
@@ -395,12 +401,13 @@ const createTools = (writer, sources, defaultLanguage) => {
|
|
|
395
401
|
.default(defaultLanguage),
|
|
396
402
|
}),
|
|
397
403
|
execute: async ({ slug, lang }) => {
|
|
404
|
+
const sourceSlug = stripBasePath(normalizePathname(slug), basePath);
|
|
398
405
|
const doc = sources
|
|
399
406
|
.flatMap((source) => source.source
|
|
400
407
|
.getPages(lang)
|
|
401
408
|
.filter((page) => isPageVisibleForSurface(page, "chat"))
|
|
402
409
|
.map((page) => ({ page, source })))
|
|
403
|
-
.find(({ page }) => page.url ===
|
|
410
|
+
.find(({ page }) => page.url === sourceSlug || page.url.endsWith(sourceSlug));
|
|
404
411
|
if (!doc) {
|
|
405
412
|
return `Documentation page not found: "${slug}"`;
|
|
406
413
|
}
|
|
@@ -421,7 +428,7 @@ const createTools = (writer, sources, defaultLanguage) => {
|
|
|
421
428
|
.getPages(lang)
|
|
422
429
|
.filter((page) => isPageVisibleForSurface(page, "chat")));
|
|
423
430
|
const docsList = pages
|
|
424
|
-
.map((doc) => `- **${doc.data.title}** (${doc.url}): ${doc.data.description}`)
|
|
431
|
+
.map((doc) => `- **${doc.data.title}** (${getPublicPath(doc.url, basePath)}): ${doc.data.description}`)
|
|
425
432
|
.join("\n");
|
|
426
433
|
return `Available documentation pages (${pages.length} total):\n\n${docsList}`;
|
|
427
434
|
},
|
|
@@ -519,7 +526,7 @@ export const createChatRoute = ({ config, model = DEFAULT_CHAT_MODEL, proxy, sou
|
|
|
519
526
|
model,
|
|
520
527
|
messages: modelMessages,
|
|
521
528
|
stopWhen: stepCountIs(10),
|
|
522
|
-
tools: createTools(writer, routeSources, defaultLanguage),
|
|
529
|
+
tools: createTools(writer, routeSources, defaultLanguage, config.basePath),
|
|
523
530
|
system: createSystemPrompt(currentRoute ?? "/", config),
|
|
524
531
|
prepareStep: ({ stepNumber }) => {
|
|
525
532
|
if (stepNumber === 0) {
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type GeistdocsConfig } from "../config";
|
|
2
2
|
type DiscoveryConfig = Pick<GeistdocsConfig, "agent">;
|
|
3
3
|
export declare const getDiscoveryLanguages: (config: Pick<GeistdocsConfig, "defaultLanguage" | "translations">) => string[];
|
|
4
|
-
export declare const withBasePath: (href: string, basePath: string | undefined) => string;
|
|
5
4
|
export declare const toAbsoluteUrl: ({ basePath, href, origin, }: {
|
|
6
5
|
basePath?: string;
|
|
7
6
|
href: string;
|
|
8
7
|
origin: string;
|
|
9
8
|
}) => string;
|
|
9
|
+
export declare const toPublicUrl: ({ basePath, href, origin, }: {
|
|
10
|
+
basePath?: string;
|
|
11
|
+
href: string;
|
|
12
|
+
origin: string;
|
|
13
|
+
}) => string;
|
|
10
14
|
export declare const toSiteUrl: (config: Pick<GeistdocsConfig, "basePath">, origin: string, href: string) => string;
|
|
11
15
|
export declare const validateAgentDiscoveryConfig: (config: DiscoveryConfig) => void;
|
|
12
16
|
export declare const validateMcpManifestConfig: (config: DiscoveryConfig) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/routes/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/routes/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAA+B,MAAM,WAAW,CAAC;AAE9E,KAAK,eAAe,GAAG,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;AAItD,eAAO,MAAM,qBAAqB,GAChC,QAAQ,IAAI,CAAC,eAAe,EAAE,iBAAiB,GAAG,cAAc,CAAC,aAMlE,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,6BAI3B;IACD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB,WAMA,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,6BAIzB;IACD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB,WAMA,CAAC;AAEF,eAAO,MAAM,SAAS,GACpB,QAAQ,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,EACzC,QAAQ,MAAM,EACd,MAAM,MAAM,WACiD,CAAC;AAiChE,eAAO,MAAM,4BAA4B,GAAI,QAAQ,eAAe,SAenE,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,QAAQ,eAAe,SAahE,CAAC"}
|
package/dist/routes/discovery.js
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
|
+
import { getPublicPath, withBasePath } from "../config";
|
|
1
2
|
const ABSOLUTE_URL_PATTERN = /^[a-z][a-z\d+.-]*:/i;
|
|
2
|
-
const TRAILING_SLASH_PATTERN = /\/$/;
|
|
3
3
|
export const getDiscoveryLanguages = (config) => {
|
|
4
4
|
const defaultLanguage = config.defaultLanguage ?? "en";
|
|
5
5
|
const languages = Object.keys(config.translations ?? {});
|
|
6
6
|
return Array.from(new Set([defaultLanguage, ...languages]));
|
|
7
7
|
};
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
if (!(href.startsWith("/") && basePath)) {
|
|
11
|
-
return href;
|
|
12
|
-
}
|
|
13
|
-
const normalizedBasePath = normalizeBasePath(basePath);
|
|
14
|
-
if (href === normalizedBasePath ||
|
|
15
|
-
href.startsWith(`${normalizedBasePath}/`)) {
|
|
8
|
+
export const toAbsoluteUrl = ({ basePath, href, origin, }) => {
|
|
9
|
+
if (ABSOLUTE_URL_PATTERN.test(href) || href.startsWith("#")) {
|
|
16
10
|
return href;
|
|
17
11
|
}
|
|
18
|
-
return
|
|
12
|
+
return new URL(withBasePath(href, basePath), origin).toString();
|
|
19
13
|
};
|
|
20
|
-
export const
|
|
14
|
+
export const toPublicUrl = ({ basePath, href, origin, }) => {
|
|
21
15
|
if (ABSOLUTE_URL_PATTERN.test(href) || href.startsWith("#")) {
|
|
22
16
|
return href;
|
|
23
17
|
}
|
|
24
|
-
return new URL(
|
|
18
|
+
return new URL(getPublicPath(href, basePath), origin).toString();
|
|
25
19
|
};
|
|
26
20
|
export const toSiteUrl = (config, origin, href) => toAbsoluteUrl({ basePath: config.basePath, href, origin });
|
|
27
21
|
const assertDiscoveryUrl = (value, field) => {
|
package/dist/routes/sitemap.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NextRequest } from "next/server";
|
|
2
|
-
import type
|
|
2
|
+
import { type GeistdocsConfig } from "../config";
|
|
3
3
|
import { type GeistdocsPageVisibilityData } from "../internal/page-visibility";
|
|
4
4
|
import { type GeistdocsSourceBundle } from "../source";
|
|
5
5
|
interface SitemapPage {
|
|
@@ -12,6 +12,7 @@ interface SitemapPage {
|
|
|
12
12
|
product?: string;
|
|
13
13
|
lastModified?: Date;
|
|
14
14
|
} & GeistdocsPageVisibilityData;
|
|
15
|
+
sourceUrl?: string;
|
|
15
16
|
url: string;
|
|
16
17
|
}
|
|
17
18
|
interface SitemapSource {
|
|
@@ -23,7 +24,7 @@ interface SitemapSection {
|
|
|
23
24
|
title?: string;
|
|
24
25
|
}
|
|
25
26
|
interface CreateSitemapMarkdownRouteOptions {
|
|
26
|
-
config: Pick<GeistdocsConfig, "defaultLanguage" | "translations">;
|
|
27
|
+
config: Pick<GeistdocsConfig, "basePath" | "defaultLanguage" | "translations">;
|
|
27
28
|
source?: SitemapSourceInput;
|
|
28
29
|
sources?: SitemapSection[];
|
|
29
30
|
title?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sitemap.d.ts","sourceRoot":"","sources":["../../src/routes/sitemap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"sitemap.d.ts","sourceRoot":"","sources":["../../src/routes/sitemap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,WAAW,CAAC;AAChE,OAAO,EACL,KAAK,2BAA2B,EAEjC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,KAAK,qBAAqB,EAA2B,MAAM,WAAW,CAAC;AAKhF,UAAU,WAAW;IACnB,IAAI,EAAE;QACJ,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;QACzB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,YAAY,CAAC,EAAE,IAAI,CAAC;KACrB,GAAG,2BAA2B,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,UAAU,aAAa;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,CAAC;CACvC;AAED,KAAK,kBAAkB,GAAG,qBAAqB,GAAG,aAAa,CAAC;AAEhE,UAAU,cAAc;IACtB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,iCAAiC;IACzC,MAAM,EAAE,IAAI,CACV,eAAe,EACf,UAAU,GAAG,iBAAiB,GAAG,cAAc,CAChD,CAAC;IACF,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,OAAO,CAAC,EAAE,cAAc,EAAE,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,CACV,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KACtB,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CAC/B;AAoMD,eAAO,MAAM,0BAA0B,GAAI,gDAMxC,iCAAiC;gBAK1B,WAAW,cACL;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE;;;;;;CA4DpD,CAAC"}
|
package/dist/routes/sitemap.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getPublicPath } from "../config";
|
|
1
2
|
import { isPageVisibleForSurface, } from "../internal/page-visibility";
|
|
2
3
|
import { isGeistdocsSourceBundle } from "../source";
|
|
3
4
|
const DOCS_PREFIX_PATTERN = /^\/docs\/?/;
|
|
@@ -18,6 +19,7 @@ function buildTree(pages) {
|
|
|
18
19
|
url: page.url,
|
|
19
20
|
type: page.data.type,
|
|
20
21
|
summary: page.data.summary,
|
|
22
|
+
sourceUrl: page.sourceUrl ?? page.url,
|
|
21
23
|
prerequisites: page.data.prerequisites,
|
|
22
24
|
product: page.data.product,
|
|
23
25
|
lastmod: page.data.lastModified
|
|
@@ -102,7 +104,7 @@ function renderNode(node, indent, parentTitle) {
|
|
|
102
104
|
if (prereqs) {
|
|
103
105
|
segments.push(`Prerequisites: ${prereqs}`);
|
|
104
106
|
}
|
|
105
|
-
const topics = extractTopics(node.
|
|
107
|
+
const topics = extractTopics(node.sourceUrl, node.product);
|
|
106
108
|
if (topics.length > 0) {
|
|
107
109
|
segments.push(`Topics: ${topics.join(", ")}`);
|
|
108
110
|
}
|
|
@@ -120,9 +122,20 @@ const resolveSitemapSections = (source, sources) => {
|
|
|
120
122
|
}
|
|
121
123
|
return sections;
|
|
122
124
|
};
|
|
123
|
-
const getSectionPages = (source, lang) =>
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
const getSectionPages = (source, lang, basePath) => {
|
|
126
|
+
const pages = (isGeistdocsSourceBundle(source)
|
|
127
|
+
? source.source.getPages(lang)
|
|
128
|
+
: source.getPages(lang));
|
|
129
|
+
return pages.map((page) => ({
|
|
130
|
+
...page,
|
|
131
|
+
data: {
|
|
132
|
+
...page.data,
|
|
133
|
+
prerequisites: page.data.prerequisites?.map((prerequisite) => getPublicPath(prerequisite, basePath)),
|
|
134
|
+
},
|
|
135
|
+
sourceUrl: page.url,
|
|
136
|
+
url: getPublicPath(page.url, basePath),
|
|
137
|
+
}));
|
|
138
|
+
};
|
|
126
139
|
const getSectionTitle = (section) => section.title ??
|
|
127
140
|
(isGeistdocsSourceBundle(section.source) ? section.source.label : undefined);
|
|
128
141
|
export const createSitemapMarkdownRoute = ({ config, source, sources, title = "Documentation Sitemap", transform, }) => {
|
|
@@ -148,7 +161,7 @@ It is not intended to replace individual docs.
|
|
|
148
161
|
`;
|
|
149
162
|
const body = sections
|
|
150
163
|
.map((section) => {
|
|
151
|
-
const pages = getSectionPages(section.source, lang).filter((page) => isPageVisibleForSurface(page, "sitemap"));
|
|
164
|
+
const pages = getSectionPages(section.source, lang, config.basePath).filter((page) => isPageVisibleForSurface(page, "sitemap"));
|
|
152
165
|
const tree = buildTree(pages);
|
|
153
166
|
const renderedTree = tree
|
|
154
167
|
.map((node) => renderNode(node, 0))
|
package/dist/source-config.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export declare const geistdocsFrontmatterSchema: z.ZodObject<{
|
|
|
30
30
|
icon: z.ZodOptional<z.ZodString>;
|
|
31
31
|
full: z.ZodOptional<z.ZodBoolean>;
|
|
32
32
|
_openapi: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
33
|
+
badge: z.ZodOptional<z.ZodString>;
|
|
33
34
|
product: z.ZodOptional<z.ZodString>;
|
|
34
35
|
url: z.ZodOptional<z.ZodString>;
|
|
35
36
|
type: z.ZodOptional<z.ZodEnum<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source-config.d.ts","sourceRoot":"","sources":["../src/source-config.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,iBAAiB,EACtB,YAAY,IAAI,oBAAoB,EAGrC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,KAAK,mBAAmB,GAAG,WAAW,CACpC,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAC3C,CAAC;AAEF,MAAM,WAAW,4BAA4B;IAC3C,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,OAAO,CAAC,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;CAC1C;AAED,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;CAsG3B,CAAC;AAEF,eAAO,MAAM,0BAA0B
|
|
1
|
+
{"version":3,"file":"source-config.d.ts","sourceRoot":"","sources":["../src/source-config.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,iBAAiB,EACtB,YAAY,IAAI,oBAAoB,EAGrC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,KAAK,mBAAmB,GAAG,WAAW,CACpC,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAC3C,CAAC;AAEF,MAAM,WAAW,4BAA4B;IAC3C,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,OAAO,CAAC,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;CAC1C;AAED,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;CAsG3B,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsCrC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;iBAAa,CAAC;AAE9C,eAAO,MAAM,2BAA2B,GACtC,SAAQ,4BAAiC,+CAoB1C,CAAC"}
|
package/dist/source-config.js
CHANGED
package/dist/source.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { type InferPageType, loader } from "fumadocs-core/source";
|
|
2
|
-
import type
|
|
2
|
+
import { type GeistdocsConfig, type GeistdocsPageSurface } from "./config.js";
|
|
3
|
+
import { type GeistdocsVersionPaths } from "./internal/version-paths.js";
|
|
4
|
+
export type { GeistdocsVersionPaths } from "./internal/version-paths.js";
|
|
3
5
|
type LoaderOptions = Parameters<typeof loader>[0];
|
|
4
6
|
export interface FumadocsCollection {
|
|
5
7
|
toFumadocsSource(): LoaderOptions["source"];
|
|
6
8
|
}
|
|
7
9
|
export interface GeistdocsSourcePageData {
|
|
10
|
+
badge?: string;
|
|
8
11
|
canonical?: string;
|
|
9
12
|
description?: string;
|
|
10
13
|
excludeFrom?: GeistdocsPageSurface[];
|
|
@@ -177,5 +180,40 @@ export declare const createVersionedSources: ({ config, current, versions, }: Cr
|
|
|
177
180
|
};
|
|
178
181
|
currentVersion: string;
|
|
179
182
|
};
|
|
180
|
-
export {
|
|
183
|
+
export interface CollectVersionPathsOptions {
|
|
184
|
+
/**
|
|
185
|
+
* Map a page to its public URL when the app rewrites loader URLs at render
|
|
186
|
+
* time (e.g. `({ page }) => \`/v5${page.url}\``). Defaults to `page.url`.
|
|
187
|
+
*/
|
|
188
|
+
getPageUrl?: (context: {
|
|
189
|
+
page: {
|
|
190
|
+
slugs: string[];
|
|
191
|
+
url: string;
|
|
192
|
+
};
|
|
193
|
+
}) => string;
|
|
194
|
+
lang?: string;
|
|
195
|
+
/** The version's public route prefix, stripped from every collected path. */
|
|
196
|
+
routePrefix?: string;
|
|
197
|
+
sources: GeistdocsSourceBundle | GeistdocsSourceBundle[];
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Collect the prefix-relative paths of every page in one version's sources.
|
|
201
|
+
* Pass the result to the version switcher (via `GeistdocsVersionSelect`'s
|
|
202
|
+
* `paths` prop) so switching never lands on a page that doesn't exist in the
|
|
203
|
+
* target version. Handles both URL shapes: loaders whose `baseUrl` already
|
|
204
|
+
* includes the version prefix, and loaders whose URLs get prefixed at render
|
|
205
|
+
* time (via `routePrefix` / `getPageUrl`).
|
|
206
|
+
*/
|
|
207
|
+
export declare const collectVersionPaths: ({ getPageUrl, lang, routePrefix, sources, }: CollectVersionPathsOptions) => string[];
|
|
208
|
+
export interface CollectVersionSwitchPathsOptions {
|
|
209
|
+
getPageUrl?: CollectVersionPathsOptions["getPageUrl"];
|
|
210
|
+
lang?: string;
|
|
211
|
+
versions: Pick<ReturnType<typeof createVersionedSources>, "all">;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Build the `paths` prop for `GeistdocsVersionSelect` from
|
|
215
|
+
* `createVersionedSources` output: for each version, the prefix-relative
|
|
216
|
+
* paths of its pages plus its docs root as the fallback landing page.
|
|
217
|
+
*/
|
|
218
|
+
export declare const collectVersionSwitchPaths: ({ getPageUrl, lang, versions, }: CollectVersionSwitchPathsOptions) => Record<string, GeistdocsVersionPaths>;
|
|
181
219
|
//# sourceMappingURL=source.d.ts.map
|
package/dist/source.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,aAAa,EAClB,MAAM,EAEP,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,oBAAoB,EAG1B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,qBAAqB,EAE3B,MAAM,6BAA6B,CAAC;AAErC,YAAY,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEzE,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AA0FlD,MAAM,WAAW,kBAAkB;IACjC,gBAAgB,IAAI,aAAa,CAAC,QAAQ,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,oBAAoB,EAAE,CAAC;IACrC,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,CAAC,EAAE,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,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C,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,OAAO,sBAAsB,CAAC,EAAE,KAAK,CAAC,CAAC;CAClE;AAED;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GAAI,iCAIvC,gCAAgC,KAAG,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAiBvE,CAAC"}
|
package/dist/source.js
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
import { defineI18n } from "fumadocs-core/i18n";
|
|
2
|
-
import { loader } from "fumadocs-core/source";
|
|
2
|
+
import { loader, } from "fumadocs-core/source";
|
|
3
3
|
import { lucideIconsPlugin } from "fumadocs-core/source/lucide-icons";
|
|
4
|
+
import { getPublicPath, withBasePath, } from "./config.js";
|
|
5
|
+
import { stripVersionRoutePrefix, } from "./internal/version-paths.js";
|
|
6
|
+
const MARKDOWN_LINK_PATTERN = /(\]\()(\/(?!\/)[^)\s]*)/g;
|
|
7
|
+
const ROOT_ATTRIBUTE_PATTERN = /(\b(?:href|src)=["'])(\/(?!\/)[^"']*)/g;
|
|
8
|
+
const FENCE_PATTERN = /^\s*(`{3,}|~{3,})/;
|
|
9
|
+
const CLOSING_FENCE_PATTERN = /^\s*(`{3,}|~{3,})\s*$/;
|
|
10
|
+
const FRONTMATTER_FIELD_PATTERN = /^([a-zA-Z][\w-]*):/;
|
|
11
|
+
const FRONTMATTER_CANONICAL_PATTERN = /^(canonical:\s+)(\/(?!\/)\S+)$/;
|
|
12
|
+
const FRONTMATTER_LIST_URL_PATTERN = /^(\s+-\s+)(\/(?!\/)\S+)$/;
|
|
13
|
+
const prefixLineUrl = (line, pattern, basePath) => line.replace(pattern, (_match, prefix, href) => `${prefix}${withBasePath(href, basePath)}`);
|
|
14
|
+
const prefixFrontmatterLinks = (lines, basePath) => {
|
|
15
|
+
let field;
|
|
16
|
+
return lines.map((line) => {
|
|
17
|
+
field = line.match(FRONTMATTER_FIELD_PATTERN)?.[1] ?? field;
|
|
18
|
+
if (field === "canonical") {
|
|
19
|
+
return prefixLineUrl(line, FRONTMATTER_CANONICAL_PATTERN, basePath);
|
|
20
|
+
}
|
|
21
|
+
if (field === "prerequisites" || field === "related") {
|
|
22
|
+
return prefixLineUrl(line, FRONTMATTER_LIST_URL_PATTERN, basePath);
|
|
23
|
+
}
|
|
24
|
+
return line;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const prefixContentLinks = (lines, basePath) => {
|
|
28
|
+
let fenceMarker;
|
|
29
|
+
return lines.map((line) => {
|
|
30
|
+
if (fenceMarker) {
|
|
31
|
+
const closingFence = line.match(CLOSING_FENCE_PATTERN)?.[1];
|
|
32
|
+
if (closingFence?.[0] === fenceMarker[0] &&
|
|
33
|
+
closingFence.length >= fenceMarker.length) {
|
|
34
|
+
fenceMarker = undefined;
|
|
35
|
+
}
|
|
36
|
+
return line;
|
|
37
|
+
}
|
|
38
|
+
const openingFence = line.match(FENCE_PATTERN)?.[1];
|
|
39
|
+
if (openingFence) {
|
|
40
|
+
fenceMarker = openingFence;
|
|
41
|
+
return line;
|
|
42
|
+
}
|
|
43
|
+
return prefixLineUrl(prefixLineUrl(line, MARKDOWN_LINK_PATTERN, basePath), ROOT_ATTRIBUTE_PATTERN, basePath);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
const prefixMarkdownLinks = (markdown, basePath) => {
|
|
47
|
+
if (!basePath) {
|
|
48
|
+
return markdown;
|
|
49
|
+
}
|
|
50
|
+
const lines = markdown.split("\n");
|
|
51
|
+
const frontmatterEnd = lines[0] === "---" ? lines.indexOf("---", 1) : -1;
|
|
52
|
+
if (frontmatterEnd === -1) {
|
|
53
|
+
return prefixContentLinks(lines, basePath).join("\n");
|
|
54
|
+
}
|
|
55
|
+
return [
|
|
56
|
+
...prefixFrontmatterLinks(lines.slice(0, frontmatterEnd + 1), basePath),
|
|
57
|
+
...prefixContentLinks(lines.slice(frontmatterEnd + 1), basePath),
|
|
58
|
+
].join("\n");
|
|
59
|
+
};
|
|
4
60
|
const getLanguages = (config) => {
|
|
5
61
|
const defaultLanguage = config.defaultLanguage ?? "en";
|
|
6
62
|
const languages = Object.keys(config.translations ?? {});
|
|
@@ -9,6 +65,21 @@ const getLanguages = (config) => {
|
|
|
9
65
|
languages: Array.from(new Set([defaultLanguage, ...languages])),
|
|
10
66
|
};
|
|
11
67
|
};
|
|
68
|
+
const badgePageTreeTransformer = {
|
|
69
|
+
file(node, filePath) {
|
|
70
|
+
if (!filePath) {
|
|
71
|
+
return node;
|
|
72
|
+
}
|
|
73
|
+
const file = this.storage.read(filePath);
|
|
74
|
+
if (file?.format !== "page") {
|
|
75
|
+
return node;
|
|
76
|
+
}
|
|
77
|
+
const badge = file.data.badge;
|
|
78
|
+
return typeof badge === "string" && badge.length > 0
|
|
79
|
+
? { ...node, badge }
|
|
80
|
+
: node;
|
|
81
|
+
},
|
|
82
|
+
};
|
|
12
83
|
export const createSource = ({ docs, config, baseUrl = "/docs", id, label, markdown, }) => {
|
|
13
84
|
const { defaultLanguage, languages } = getLanguages(config);
|
|
14
85
|
const i18n = defineI18n({
|
|
@@ -19,6 +90,9 @@ export const createSource = ({ docs, config, baseUrl = "/docs", id, label, markd
|
|
|
19
90
|
const source = loader({
|
|
20
91
|
i18n,
|
|
21
92
|
baseUrl,
|
|
93
|
+
pageTree: {
|
|
94
|
+
transformers: [badgePageTreeTransformer],
|
|
95
|
+
},
|
|
22
96
|
source: docs.toFumadocsSource(),
|
|
23
97
|
plugins: [lucideIconsPlugin()],
|
|
24
98
|
});
|
|
@@ -26,19 +100,18 @@ export const createSource = ({ docs, config, baseUrl = "/docs", id, label, markd
|
|
|
26
100
|
const segments = [...page.slugs, "image.png"];
|
|
27
101
|
return {
|
|
28
102
|
segments,
|
|
29
|
-
url: config.basePath
|
|
30
|
-
? `${config.basePath}/og/${segments.join("/")}`
|
|
31
|
-
: `/og/${segments.join("/")}`,
|
|
103
|
+
url: getPublicPath(`/og/${segments.join("/")}`, config.basePath),
|
|
32
104
|
};
|
|
33
105
|
};
|
|
34
106
|
const getPageMarkdown = async (page) => {
|
|
35
107
|
const data = page.data;
|
|
36
108
|
const processed = await data.getText("processed");
|
|
37
|
-
const { title, description, product, type, summary, prerequisites, related, internal, noindex, canonical, tags, keywords, excludeFrom, } = data;
|
|
109
|
+
const { title, description, badge, product, type, summary, prerequisites, related, internal, noindex, canonical, tags, keywords, excludeFrom, } = data;
|
|
38
110
|
const frontmatter = [
|
|
39
111
|
"---",
|
|
40
112
|
`title: ${title}`,
|
|
41
113
|
description && `description: ${description}`,
|
|
114
|
+
badge && `badge: ${JSON.stringify(badge)}`,
|
|
42
115
|
product && `product: ${product}`,
|
|
43
116
|
type && `type: ${type}`,
|
|
44
117
|
summary && `summary: ${summary}`,
|
|
@@ -55,13 +128,21 @@ export const createSource = ({ docs, config, baseUrl = "/docs", id, label, markd
|
|
|
55
128
|
.map((prerequisite) => ` - ${prerequisite}`)
|
|
56
129
|
.join("\n")}`,
|
|
57
130
|
related?.length &&
|
|
58
|
-
`related:\n${related
|
|
131
|
+
`related:\n${related
|
|
132
|
+
.map((entry) => ` - ${entry}`)
|
|
133
|
+
.join("\n")}`,
|
|
59
134
|
"---",
|
|
60
135
|
]
|
|
61
136
|
.filter(Boolean)
|
|
62
137
|
.join("\n");
|
|
138
|
+
const sitemapPath = "/sitemap.md";
|
|
139
|
+
const llmsPath = "/llms.txt";
|
|
140
|
+
const agentsPath = "/agents.md";
|
|
141
|
+
const sitemapLabel = getPublicPath(sitemapPath, config.basePath);
|
|
142
|
+
const llmsLabel = getPublicPath(llmsPath, config.basePath);
|
|
143
|
+
const agentsLabel = getPublicPath(agentsPath, config.basePath);
|
|
63
144
|
const agentDiscoveryLink = config.agent && config.agent.enabled !== false
|
|
64
|
-
?
|
|
145
|
+
? `\n\nFor agent-facing discovery, including API and MCP surfaces, see [${agentsLabel}](${agentsPath})`
|
|
65
146
|
: "";
|
|
66
147
|
const rendered = `${frontmatter}
|
|
67
148
|
|
|
@@ -71,15 +152,15 @@ ${processed}
|
|
|
71
152
|
|
|
72
153
|
---
|
|
73
154
|
|
|
74
|
-
For a semantic overview of all documentation, see [
|
|
155
|
+
For a semantic overview of all documentation, see [${sitemapLabel}](${sitemapPath})
|
|
75
156
|
|
|
76
|
-
For an index of all available documentation, see [
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
157
|
+
For an index of all available documentation, see [${llmsLabel}](${llmsPath})${agentDiscoveryLink}`;
|
|
158
|
+
const transformed = markdown?.transform
|
|
159
|
+
? await markdown.transform(rendered, {
|
|
160
|
+
page: page,
|
|
161
|
+
})
|
|
162
|
+
: rendered;
|
|
163
|
+
return prefixMarkdownLinks(transformed, config.basePath);
|
|
83
164
|
};
|
|
84
165
|
return {
|
|
85
166
|
baseUrl,
|
|
@@ -143,3 +224,39 @@ export const createVersionedSources = ({ config, current, versions, }) => {
|
|
|
143
224
|
currentVersion: current,
|
|
144
225
|
};
|
|
145
226
|
};
|
|
227
|
+
/**
|
|
228
|
+
* Collect the prefix-relative paths of every page in one version's sources.
|
|
229
|
+
* Pass the result to the version switcher (via `GeistdocsVersionSelect`'s
|
|
230
|
+
* `paths` prop) so switching never lands on a page that doesn't exist in the
|
|
231
|
+
* target version. Handles both URL shapes: loaders whose `baseUrl` already
|
|
232
|
+
* includes the version prefix, and loaders whose URLs get prefixed at render
|
|
233
|
+
* time (via `routePrefix` / `getPageUrl`).
|
|
234
|
+
*/
|
|
235
|
+
export const collectVersionPaths = ({ getPageUrl, lang, routePrefix, sources, }) => {
|
|
236
|
+
const bundles = Array.isArray(sources) ? sources : [sources];
|
|
237
|
+
const paths = new Set();
|
|
238
|
+
for (const bundle of bundles) {
|
|
239
|
+
for (const page of bundle.source.getPages(lang)) {
|
|
240
|
+
const url = getPageUrl ? getPageUrl({ page }) : page.url;
|
|
241
|
+
paths.add(stripVersionRoutePrefix(url, routePrefix));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return [...paths].sort();
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Build the `paths` prop for `GeistdocsVersionSelect` from
|
|
248
|
+
* `createVersionedSources` output: for each version, the prefix-relative
|
|
249
|
+
* paths of its pages plus its docs root as the fallback landing page.
|
|
250
|
+
*/
|
|
251
|
+
export const collectVersionSwitchPaths = ({ getPageUrl, lang, versions, }) => Object.fromEntries(versions.all.map((entry) => [
|
|
252
|
+
entry.id,
|
|
253
|
+
{
|
|
254
|
+
fallbackPath: stripVersionRoutePrefix(entry.source.baseUrl, entry.routePrefix),
|
|
255
|
+
paths: collectVersionPaths({
|
|
256
|
+
getPageUrl,
|
|
257
|
+
lang,
|
|
258
|
+
routePrefix: entry.routePrefix,
|
|
259
|
+
sources: entry.source,
|
|
260
|
+
}),
|
|
261
|
+
},
|
|
262
|
+
]));
|
package/dist/versions.d.ts
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
import type { GeistdocsVersionConfig, GeistdocsVersionsConfig } from "./config";
|
|
3
|
+
import { type GeistdocsVersionPaths } from "./internal/version-paths.js";
|
|
4
|
+
export type { GeistdocsVersionPaths } from "./internal/version-paths.js";
|
|
3
5
|
export interface GeistdocsRouteSelectItem {
|
|
4
6
|
description?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Landing path (relative to `routePrefix`) when neither the switched path
|
|
9
|
+
* nor any of its ancestors exist in `paths`.
|
|
10
|
+
*/
|
|
11
|
+
fallbackPath?: string;
|
|
5
12
|
href?: string;
|
|
6
13
|
icon?: ReactNode;
|
|
7
14
|
id: string;
|
|
8
15
|
label: string;
|
|
16
|
+
/**
|
|
17
|
+
* Paths (relative to `routePrefix`) that exist for this item. When
|
|
18
|
+
* provided, switching falls back to the nearest existing ancestor instead
|
|
19
|
+
* of landing on a page that doesn't exist in the target version.
|
|
20
|
+
*/
|
|
21
|
+
paths?: readonly string[];
|
|
9
22
|
routePrefix?: string;
|
|
10
23
|
}
|
|
11
24
|
interface ResolveRouteHrefOptions<Item extends GeistdocsRouteSelectItem> {
|
|
@@ -35,11 +48,18 @@ interface GeistdocsRouteSelectProps<Item extends GeistdocsRouteSelectItem> {
|
|
|
35
48
|
interface GeistdocsVersionSelectProps {
|
|
36
49
|
className?: string;
|
|
37
50
|
current?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Existing paths per version ID, relative to each version's `routePrefix`.
|
|
53
|
+
* Compute server-side with `collectVersionSwitchPaths` (or
|
|
54
|
+
* `collectVersionPaths`) from `@vercel/geistdocs/source`. When provided,
|
|
55
|
+
* switching to a version that lacks the current page lands on the nearest
|
|
56
|
+
* existing ancestor (or the version's `fallbackPath`) instead of a 404.
|
|
57
|
+
*/
|
|
58
|
+
paths?: Record<string, GeistdocsVersionPaths | readonly string[]>;
|
|
38
59
|
versions: GeistdocsVersionConfig[] | GeistdocsVersionsConfig;
|
|
39
60
|
}
|
|
40
61
|
export declare const resolveRouteHref: <Item extends GeistdocsRouteSelectItem>({ currentItem, item, pathname, }: ResolveRouteHrefOptions<Item>) => string;
|
|
41
62
|
export declare const resolveVersionHref: ({ currentVersion, pathname, version, }: ResolveVersionHrefOptions) => string;
|
|
42
63
|
export declare const GeistdocsRouteSelect: <Item extends GeistdocsRouteSelectItem>({ ariaLabel, className, current, getDescription, items, renderIcon, }: GeistdocsRouteSelectProps<Item>) => import("react/jsx-runtime").JSX.Element | null;
|
|
43
|
-
export declare const GeistdocsVersionSelect: ({ className, current, versions, }: GeistdocsVersionSelectProps) => import("react/jsx-runtime").JSX.Element;
|
|
44
|
-
export {};
|
|
64
|
+
export declare const GeistdocsVersionSelect: ({ className, current, paths, versions, }: GeistdocsVersionSelectProps) => import("react/jsx-runtime").JSX.Element;
|
|
45
65
|
//# sourceMappingURL=versions.d.ts.map
|
package/dist/versions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"versions.d.ts","sourceRoot":"","sources":["../src/versions.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