@vercel/geistdocs 1.13.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/footer.d.ts +1 -1
- package/dist/footer.d.ts.map +1 -1
- package/dist/footer.js +1 -1
- 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 +1 -3
- package/dist/internal/search.d.ts.map +1 -1
- package/dist/internal/search.js +2 -1
- 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/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.d.ts +39 -2
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +111 -13
- package/dist/versions.d.ts +22 -2
- package/dist/versions.d.ts.map +1 -1
- package/dist/versions.js +26 -3
- package/docs/agents.md +1 -1
- package/docs/llms.txt +117 -2
- package/docs/manifest.json +1 -1
- package/docs/pages/configuration.md +23 -1
- 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/versioned-docs.md +68 -0
- package/package.json +1 -1
- package/template/AGENTS.md +2 -0
- package/template/app/[lang]/rss.xml/route.ts +7 -3
- package/template/content/docs/configuration.mdx +23 -1
- 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/versioned-docs.mdx +68 -0
- package/template/package.json +1 -1
package/dist/proxy.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type NextFetchEvent, type NextRequest } from "next/server";
|
|
2
|
-
import type
|
|
2
|
+
import { type GeistdocsConfig } from "./config";
|
|
3
3
|
export type DetectionMethod = "ua-match" | "signature-agent" | "heuristic" | null;
|
|
4
4
|
export interface TrackMarkdownRequestEvent {
|
|
5
5
|
acceptHeader: string | null;
|
|
@@ -21,6 +21,7 @@ export interface GeistdocsMarkdownRoute {
|
|
|
21
21
|
from: `/${string}`;
|
|
22
22
|
to: `/${string}` | ((context: {
|
|
23
23
|
defaultLanguage: string;
|
|
24
|
+
language: string;
|
|
24
25
|
path: string[];
|
|
25
26
|
pathname: string;
|
|
26
27
|
}) => `/${string}`);
|
|
@@ -28,10 +29,10 @@ export interface GeistdocsMarkdownRoute {
|
|
|
28
29
|
export interface CreateProxyOptions {
|
|
29
30
|
after?: GeistdocsProxyHook | GeistdocsProxyHook[];
|
|
30
31
|
before?: GeistdocsProxyHook | GeistdocsProxyHook[];
|
|
31
|
-
config: Pick<GeistdocsConfig, "content" | "defaultLanguage" | "translations">;
|
|
32
|
+
config: Pick<GeistdocsConfig, "basePath" | "content" | "defaultLanguage" | "translations">;
|
|
32
33
|
markdownRoutes?: GeistdocsMarkdownRoute[];
|
|
33
34
|
trackMarkdownRequest?: (event: TrackMarkdownRequestEvent) => Promise<void> | void;
|
|
34
35
|
}
|
|
35
|
-
export declare const createProxy: ({ after, before, config, markdownRoutes, trackMarkdownRequest, }: CreateProxyOptions) => (request: NextRequest, context: NextFetchEvent) => Promise<
|
|
36
|
+
export declare const createProxy: ({ after, before, config, markdownRoutes, trackMarkdownRequest, }: CreateProxyOptions) => (request: NextRequest, context: NextFetchEvent) => Promise<Response>;
|
|
36
37
|
export {};
|
|
37
38
|
//# sourceMappingURL=proxy.d.ts.map
|
package/dist/proxy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,WAAW,EAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,WAAW,EAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,eAAe,EAGrB,MAAM,UAAU,CAAC;AAElB,MAAM,MAAM,eAAe,GACvB,UAAU,GACV,iBAAiB,GACjB,WAAW,GACX,IAAI,CAAC;AAET,MAAM,WAAW,yBAAyB;IACxC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,WAAW,CAAC,EAAE,QAAQ,GAAG,mBAAmB,GAAG,eAAe,CAAC;IAC/D,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,cAAc,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,WAAW,CAAC;CACtB;AAED,KAAK,eAAe,GAAG,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC;AAEnD,MAAM,MAAM,kBAAkB,GAAG,CAC/B,OAAO,EAAE,qBAAqB,KAC3B,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,CAAC;AAEhD,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,IAAI,MAAM,EAAE,CAAC;IACnB,EAAE,EACE,IAAI,MAAM,EAAE,GACZ,CAAC,CAAC,OAAO,EAAE;QACT,eAAe,EAAE,MAAM,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;KAClB,KAAK,IAAI,MAAM,EAAE,CAAC,CAAC;CACzB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,kBAAkB,GAAG,kBAAkB,EAAE,CAAC;IAClD,MAAM,CAAC,EAAE,kBAAkB,GAAG,kBAAkB,EAAE,CAAC;IACnD,MAAM,EAAE,IAAI,CACV,eAAe,EACf,UAAU,GAAG,SAAS,GAAG,iBAAiB,GAAG,cAAc,CAC5D,CAAC;IACF,cAAc,CAAC,EAAE,sBAAsB,EAAE,CAAC;IAC1C,oBAAoB,CAAC,EAAE,CACrB,KAAK,EAAE,yBAAyB,KAC7B,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC3B;AA8JD,eAAO,MAAM,WAAW,GAAI,kEAMzB,kBAAkB,MAsOL,SAAS,WAAW,EAAE,SAAS,cAAc,sBA6C5D,CAAC"}
|
package/dist/proxy.js
CHANGED
|
@@ -3,6 +3,7 @@ import { defineI18n } from "fumadocs-core/i18n";
|
|
|
3
3
|
import { createI18nMiddleware } from "fumadocs-core/i18n/middleware";
|
|
4
4
|
import { isMarkdownPreferred } from "fumadocs-core/negotiation";
|
|
5
5
|
import { NextResponse, } from "next/server";
|
|
6
|
+
import { getPublicPath, normalizeBasePath, } from "./config";
|
|
6
7
|
const MDX_EXTENSION_PATTERN = /\.mdx?$/;
|
|
7
8
|
const PATH_TOKEN_PATTERN = /\*path|:path\*/g;
|
|
8
9
|
const PATH_WILDCARD_PATTERN = /\/\*path$/;
|
|
@@ -10,6 +11,13 @@ const DEFAULT_MARKDOWN_ROUTE = {
|
|
|
10
11
|
from: "/docs/*path",
|
|
11
12
|
to: "/[lang]/llms.mdx/*path",
|
|
12
13
|
};
|
|
14
|
+
const PACKAGE_ROUTE_PATHS = new Set([
|
|
15
|
+
"/.well-known/mcp.json",
|
|
16
|
+
"/agents.md",
|
|
17
|
+
"/llms.txt",
|
|
18
|
+
"/rss.xml",
|
|
19
|
+
"/sitemap.md",
|
|
20
|
+
]);
|
|
13
21
|
const TRAILING_SLASH_PATTERN = /\/$/;
|
|
14
22
|
const getLanguages = (config) => {
|
|
15
23
|
const defaultLanguage = config.defaultLanguage ?? "en";
|
|
@@ -58,6 +66,52 @@ const runHooks = async (hooks, proxyContext) => {
|
|
|
58
66
|
}
|
|
59
67
|
return null;
|
|
60
68
|
};
|
|
69
|
+
const getRoutePath = (route, pathname) => {
|
|
70
|
+
const hasWildcard = PATH_WILDCARD_PATTERN.test(route.from);
|
|
71
|
+
const routeBasePath = route.from.replace(PATH_WILDCARD_PATTERN, "");
|
|
72
|
+
const matches = hasWildcard
|
|
73
|
+
? pathname === routeBasePath || pathname.startsWith(`${routeBasePath}/`)
|
|
74
|
+
: pathname === route.from;
|
|
75
|
+
if (!matches) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
if (!(hasWildcard && pathname !== routeBasePath)) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
const path = pathname
|
|
82
|
+
.slice(routeBasePath.length + 1)
|
|
83
|
+
.split("/")
|
|
84
|
+
.filter(Boolean);
|
|
85
|
+
if (routeBasePath === "" && path.length === 1 && path[0] === "index") {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
return path;
|
|
89
|
+
};
|
|
90
|
+
const addBasePathToRedirect = (response, request, basePath) => {
|
|
91
|
+
const location = response.headers.get("location");
|
|
92
|
+
if (!location) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const target = new URL(location, request.url);
|
|
96
|
+
if (target.pathname === basePath ||
|
|
97
|
+
target.pathname.startsWith(`${basePath}/`)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
target.pathname = getPublicPath(target.pathname, basePath);
|
|
101
|
+
response.headers.set("location", target.toString());
|
|
102
|
+
};
|
|
103
|
+
const getLocalizedPathname = (pathname, languages, defaultLanguage) => {
|
|
104
|
+
const segments = pathname.split("/").filter(Boolean);
|
|
105
|
+
const language = segments[0];
|
|
106
|
+
if (!(language && languages.includes(language))) {
|
|
107
|
+
return { hasLanguagePrefix: false, language: defaultLanguage, pathname };
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
hasLanguagePrefix: true,
|
|
111
|
+
language,
|
|
112
|
+
pathname: `/${segments.slice(1).join("/")}`,
|
|
113
|
+
};
|
|
114
|
+
};
|
|
61
115
|
export const createProxy = ({ after, before, config, markdownRoutes, trackMarkdownRequest, }) => {
|
|
62
116
|
const routeMappings = markdownRoutes ??
|
|
63
117
|
inferMarkdownRoutes(config) ?? [DEFAULT_MARKDOWN_ROUTE];
|
|
@@ -67,7 +121,11 @@ export const createProxy = ({ after, before, config, markdownRoutes, trackMarkdo
|
|
|
67
121
|
languages,
|
|
68
122
|
hideLocale: "default-locale",
|
|
69
123
|
});
|
|
70
|
-
const
|
|
124
|
+
const configuredBasePath = normalizeBasePath(config.basePath);
|
|
125
|
+
const internationalizer = createI18nMiddleware({
|
|
126
|
+
...i18n,
|
|
127
|
+
format: (locale, path) => getPublicPath(`/${locale}${path}`, configuredBasePath),
|
|
128
|
+
});
|
|
71
129
|
const beforeHooks = normalizeHooks(before);
|
|
72
130
|
const afterHooks = normalizeHooks(after);
|
|
73
131
|
const trackRequest = (context, event) => {
|
|
@@ -76,66 +134,62 @@ export const createProxy = ({ after, before, config, markdownRoutes, trackMarkdo
|
|
|
76
134
|
}
|
|
77
135
|
context.waitUntil(Promise.resolve(trackMarkdownRequest(event)));
|
|
78
136
|
};
|
|
79
|
-
const resolveMarkdownRewrite = (pathname) => {
|
|
137
|
+
const resolveMarkdownRewrite = (pathname, language) => {
|
|
80
138
|
for (const route of routeMappings) {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
const matches = hasWildcard
|
|
84
|
-
? pathname === basePath || pathname.startsWith(`${basePath}/`)
|
|
85
|
-
: pathname === route.from;
|
|
86
|
-
if (!matches) {
|
|
139
|
+
const path = getRoutePath(route, pathname);
|
|
140
|
+
if (!path) {
|
|
87
141
|
continue;
|
|
88
142
|
}
|
|
89
|
-
const path = hasWildcard && pathname !== basePath
|
|
90
|
-
? pathname
|
|
91
|
-
.slice(basePath.length + 1)
|
|
92
|
-
.split("/")
|
|
93
|
-
.filter(Boolean)
|
|
94
|
-
: [];
|
|
95
143
|
if (typeof route.to === "function") {
|
|
96
|
-
return route.to({ defaultLanguage, path, pathname });
|
|
144
|
+
return route.to({ defaultLanguage, language, path, pathname });
|
|
97
145
|
}
|
|
98
|
-
const destination = route.to.replace("[lang]",
|
|
146
|
+
const destination = route.to.replace("[lang]", language);
|
|
99
147
|
const pathValue = path.join("/");
|
|
100
148
|
const rewritten = destination.replace(PATH_TOKEN_PATTERN, pathValue);
|
|
101
149
|
return rewritten.endsWith("/") ? rewritten.slice(0, -1) : rewritten;
|
|
102
150
|
}
|
|
103
151
|
return null;
|
|
104
152
|
};
|
|
105
|
-
const tryMarkdownRewrite = (request, context, pathname, options) => {
|
|
106
|
-
const result = resolveMarkdownRewrite(pathname);
|
|
153
|
+
const tryMarkdownRewrite = (request, context, pathname, language, options) => {
|
|
154
|
+
const result = resolveMarkdownRewrite(pathname, language);
|
|
107
155
|
if (!result) {
|
|
108
156
|
return null;
|
|
109
157
|
}
|
|
110
158
|
trackRequest(context, {
|
|
111
|
-
path: options?.trackPath ?? pathname,
|
|
159
|
+
path: getPublicPath(options?.trackPath ?? pathname, config.basePath),
|
|
112
160
|
userAgent: request.headers.get("user-agent"),
|
|
113
161
|
referer: request.headers.get("referer"),
|
|
114
162
|
acceptHeader: request.headers.get("accept"),
|
|
115
163
|
requestType: options?.requestType,
|
|
116
164
|
detectionMethod: options?.detectionMethod,
|
|
117
165
|
});
|
|
118
|
-
|
|
166
|
+
const rewriteUrl = request.nextUrl.clone();
|
|
167
|
+
if (configuredBasePath) {
|
|
168
|
+
rewriteUrl.basePath = configuredBasePath;
|
|
169
|
+
}
|
|
170
|
+
rewriteUrl.pathname = result;
|
|
171
|
+
return NextResponse.rewrite(rewriteUrl);
|
|
119
172
|
};
|
|
120
|
-
const isMdExtensionRequest = (pathname) => (pathname.endsWith(".md") || pathname.endsWith(".mdx")) &&
|
|
121
|
-
Boolean(resolveMarkdownRewrite(pathname.replace(MDX_EXTENSION_PATTERN, "")));
|
|
122
|
-
const handleMarkdownExtensionRequest = (request, context, pathname) => {
|
|
123
|
-
if (!isMdExtensionRequest(pathname)) {
|
|
173
|
+
const isMdExtensionRequest = (pathname, language) => (pathname.endsWith(".md") || pathname.endsWith(".mdx")) &&
|
|
174
|
+
Boolean(resolveMarkdownRewrite(pathname.replace(MDX_EXTENSION_PATTERN, ""), language));
|
|
175
|
+
const handleMarkdownExtensionRequest = (request, context, pathname, language, trackPath) => {
|
|
176
|
+
if (!isMdExtensionRequest(pathname, language)) {
|
|
124
177
|
return null;
|
|
125
178
|
}
|
|
126
|
-
return tryMarkdownRewrite(request, context, pathname.replace(MDX_EXTENSION_PATTERN, ""), {
|
|
179
|
+
return tryMarkdownRewrite(request, context, pathname.replace(MDX_EXTENSION_PATTERN, ""), language, {
|
|
127
180
|
requestType: "md-url",
|
|
128
|
-
trackPath
|
|
181
|
+
trackPath,
|
|
129
182
|
});
|
|
130
183
|
};
|
|
131
|
-
const handleAgentRewrite = (request, context, pathname) => {
|
|
184
|
+
const handleAgentRewrite = (request, context, pathname, language, trackPath) => {
|
|
132
185
|
const agentResult = isAIAgent(request);
|
|
133
186
|
if (!agentResult.detected || isMarkdownPreferred(request)) {
|
|
134
187
|
return null;
|
|
135
188
|
}
|
|
136
|
-
const response = tryMarkdownRewrite(request, context, pathname, {
|
|
189
|
+
const response = tryMarkdownRewrite(request, context, pathname, language, {
|
|
137
190
|
requestType: "agent-rewrite",
|
|
138
191
|
detectionMethod: agentResult.method,
|
|
192
|
+
trackPath,
|
|
139
193
|
});
|
|
140
194
|
if (response) {
|
|
141
195
|
return response;
|
|
@@ -144,11 +198,41 @@ export const createProxy = ({ after, before, config, markdownRoutes, trackMarkdo
|
|
|
144
198
|
headers: { "Content-Type": "text/markdown; charset=utf-8" },
|
|
145
199
|
});
|
|
146
200
|
};
|
|
147
|
-
const handlePreferredMarkdownRequest = (request, context) => isMarkdownPreferred(request)
|
|
148
|
-
? tryMarkdownRewrite(request, context,
|
|
201
|
+
const handlePreferredMarkdownRequest = (request, context, pathname, language, trackPath) => isMarkdownPreferred(request)
|
|
202
|
+
? tryMarkdownRewrite(request, context, pathname, language, {
|
|
149
203
|
requestType: "header-negotiated",
|
|
204
|
+
trackPath,
|
|
150
205
|
})
|
|
151
206
|
: null;
|
|
207
|
+
const handleMarkdownNegotiation = (request, context, pathname) => {
|
|
208
|
+
const localized = getLocalizedPathname(pathname, languages, defaultLanguage);
|
|
209
|
+
if ((localized.hasLanguagePrefix && localized.language === defaultLanguage) ||
|
|
210
|
+
PACKAGE_ROUTE_PATHS.has(localized.pathname)) {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
const extensionResponse = handleMarkdownExtensionRequest(request, context, localized.pathname, localized.language, pathname);
|
|
214
|
+
if (extensionResponse) {
|
|
215
|
+
return extensionResponse;
|
|
216
|
+
}
|
|
217
|
+
if (resolveMarkdownRewrite(localized.pathname, localized.language) &&
|
|
218
|
+
!localized.pathname.includes("/llms.mdx/")) {
|
|
219
|
+
const agentResponse = handleAgentRewrite(request, context, localized.pathname, localized.language, pathname);
|
|
220
|
+
if (agentResponse) {
|
|
221
|
+
return agentResponse;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return handlePreferredMarkdownRequest(request, context, localized.pathname, localized.language, pathname);
|
|
225
|
+
};
|
|
226
|
+
const handleI18nRequest = async (request, context) => {
|
|
227
|
+
const response = await internationalizer(request, context);
|
|
228
|
+
if (!response) {
|
|
229
|
+
return NextResponse.next();
|
|
230
|
+
}
|
|
231
|
+
if (configuredBasePath) {
|
|
232
|
+
addBasePathToRedirect(response, request, configuredBasePath);
|
|
233
|
+
}
|
|
234
|
+
return response;
|
|
235
|
+
};
|
|
152
236
|
return async (request, context) => {
|
|
153
237
|
const pathname = request.nextUrl.pathname;
|
|
154
238
|
const proxyContext = {
|
|
@@ -161,29 +245,23 @@ export const createProxy = ({ after, before, config, markdownRoutes, trackMarkdo
|
|
|
161
245
|
if (beforeResponse) {
|
|
162
246
|
return beforeResponse;
|
|
163
247
|
}
|
|
164
|
-
|
|
248
|
+
const localized = getLocalizedPathname(pathname, languages, defaultLanguage);
|
|
249
|
+
if (localized.pathname === "/llms.txt") {
|
|
165
250
|
trackRequest(context, {
|
|
166
|
-
path:
|
|
251
|
+
path: getPublicPath(pathname, config.basePath),
|
|
167
252
|
userAgent: request.headers.get("user-agent"),
|
|
168
253
|
referer: request.headers.get("referer"),
|
|
169
254
|
acceptHeader: request.headers.get("accept"),
|
|
170
255
|
});
|
|
171
256
|
}
|
|
172
|
-
const
|
|
173
|
-
if (
|
|
174
|
-
return
|
|
175
|
-
}
|
|
176
|
-
if (resolveMarkdownRewrite(pathname) && !pathname.includes("/llms.mdx/")) {
|
|
177
|
-
const response = handleAgentRewrite(request, context, pathname);
|
|
178
|
-
if (response) {
|
|
179
|
-
return response;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
const preferredMarkdownResponse = handlePreferredMarkdownRequest(request, context);
|
|
183
|
-
if (preferredMarkdownResponse) {
|
|
184
|
-
return preferredMarkdownResponse;
|
|
257
|
+
const markdownResponse = handleMarkdownNegotiation(request, context, pathname);
|
|
258
|
+
if (markdownResponse) {
|
|
259
|
+
return markdownResponse;
|
|
185
260
|
}
|
|
186
261
|
const afterResponse = await runHooks(afterHooks, proxyContext);
|
|
187
|
-
|
|
262
|
+
if (afterResponse) {
|
|
263
|
+
return afterResponse;
|
|
264
|
+
}
|
|
265
|
+
return handleI18nRequest(request, context);
|
|
188
266
|
};
|
|
189
267
|
};
|
package/dist/routes/agents.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
|
export interface CreateAgentsRouteOptions {
|
|
4
4
|
config: Pick<GeistdocsConfig, "agent" | "basePath" | "content" | "defaultLanguage" | "github" | "nav" | "title" | "translations" | "versions">;
|
|
5
5
|
transform?: (markdown: string, context: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/routes/agents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/routes/agents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,KAAK,eAAe,EAGrB,MAAM,WAAW,CAAC;AAQnB,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,IAAI,CACV,eAAe,EACb,OAAO,GACP,UAAU,GACV,SAAS,GACT,iBAAiB,GACjB,QAAQ,GACR,KAAK,GACL,OAAO,GACP,cAAc,GACd,UAAU,CACb,CAAC;IACF,SAAS,CAAC,EAAE,CACV,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,WAAW,CAAA;KAAE,KAC7C,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CAC/B;AAuRD,eAAO,MAAM,iBAAiB,GAAI,wBAG/B,wBAAwB;mBAId,WAAW,eACR;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC;YAAE,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE;;;;;CA2BtD,CAAC"}
|
package/dist/routes/agents.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { getPublicPath, } from "../config";
|
|
2
|
+
import { getDiscoveryLanguages, toPublicUrl, toSiteUrl, validateAgentDiscoveryConfig, } from "./discovery";
|
|
3
|
+
const getDefaultAgentInstructions = (config) => [
|
|
4
|
+
`Use ${getPublicPath("/sitemap.md", config.basePath)} to identify the most relevant documentation pages before answering broad questions.`,
|
|
5
|
+
`Use ${getPublicPath("/llms.txt", config.basePath)} when you need the complete documentation corpus as Markdown context.`,
|
|
5
6
|
"Fetch individual documentation pages with a .md or .mdx extension for focused page-level context.",
|
|
6
7
|
"Do not assume API, authentication, OpenAPI, or MCP support unless it is listed in this file.",
|
|
7
8
|
];
|
|
@@ -14,7 +15,7 @@ const renderList = (items) => items.map((item) => `- ${item}`).join("\n");
|
|
|
14
15
|
const getDocsLinks = (config, origin) => {
|
|
15
16
|
const contentLinks = (config.content ?? []).map((section) => ({
|
|
16
17
|
label: section.label,
|
|
17
|
-
href:
|
|
18
|
+
href: toPublicUrl({
|
|
18
19
|
basePath: config.basePath,
|
|
19
20
|
href: section.route,
|
|
20
21
|
origin,
|
|
@@ -27,22 +28,22 @@ const getDocsLinks = (config, origin) => {
|
|
|
27
28
|
return [
|
|
28
29
|
{
|
|
29
30
|
label: "Documentation",
|
|
30
|
-
href:
|
|
31
|
+
href: toPublicUrl({ basePath: config.basePath, href: "/docs", origin }),
|
|
31
32
|
description: "Primary human-readable documentation",
|
|
32
33
|
},
|
|
33
34
|
];
|
|
34
35
|
};
|
|
35
36
|
const getNavigationLinks = (nav, config, origin) => (nav ?? []).map((item) => ({
|
|
36
37
|
label: item.label,
|
|
37
|
-
href:
|
|
38
|
+
href: toPublicUrl({ basePath: config.basePath, href: item.href, origin }),
|
|
38
39
|
description: item.external ? "External navigation link" : undefined,
|
|
39
40
|
}));
|
|
40
41
|
const renderDocumentationSection = (config, origin) => [
|
|
41
42
|
"## Documentation Surfaces",
|
|
42
43
|
"",
|
|
43
44
|
...getDocsLinks(config, origin).map((link) => renderLink(link.label, link.href, link.description)),
|
|
44
|
-
renderLink("Full documentation context",
|
|
45
|
-
renderLink("Semantic documentation sitemap",
|
|
45
|
+
renderLink("Full documentation context", toPublicUrl({ basePath: config.basePath, href: "/llms.txt", origin }), "All configured documentation as Markdown"),
|
|
46
|
+
renderLink("Semantic documentation sitemap", toPublicUrl({ basePath: config.basePath, href: "/sitemap.md", origin }), "High-level documentation map for agent navigation"),
|
|
46
47
|
"- Page-level Markdown: append .md or .mdx to a documentation URL",
|
|
47
48
|
"",
|
|
48
49
|
];
|
|
@@ -85,7 +86,11 @@ const renderMcpSection = (mcp, config, origin) => {
|
|
|
85
86
|
? toSiteUrl(config, origin, mcp.manifestUrl)
|
|
86
87
|
: undefined;
|
|
87
88
|
const generatedManifestUrl = mcp?.servers?.length
|
|
88
|
-
?
|
|
89
|
+
? toPublicUrl({
|
|
90
|
+
basePath: config.basePath,
|
|
91
|
+
href: "/.well-known/mcp.json",
|
|
92
|
+
origin,
|
|
93
|
+
})
|
|
89
94
|
: undefined;
|
|
90
95
|
const links = [
|
|
91
96
|
manifestUrl && renderLink("MCP manifest", manifestUrl),
|
|
@@ -130,17 +135,23 @@ const renderVersionsSection = (config, origin) => {
|
|
|
130
135
|
...config.versions.items.map((version) => {
|
|
131
136
|
const marker = version.id === config.versions?.current ? " current" : "";
|
|
132
137
|
const href = version.href ?? version.routePrefix;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
138
|
+
if (!href) {
|
|
139
|
+
return `- ${version.label}${marker}${version.description ? `: ${version.description}` : ""}`;
|
|
140
|
+
}
|
|
141
|
+
const url = version.href
|
|
142
|
+
? toSiteUrl(config, origin, href)
|
|
143
|
+
: toPublicUrl({ basePath: config.basePath, href, origin });
|
|
144
|
+
return renderLink(`${version.label}${marker}`, url, version.description);
|
|
136
145
|
}),
|
|
137
146
|
"",
|
|
138
147
|
];
|
|
139
148
|
};
|
|
140
|
-
const renderInstructionsSection = (agent) => [
|
|
149
|
+
const renderInstructionsSection = (agent, config) => [
|
|
141
150
|
"## Agent Instructions",
|
|
142
151
|
"",
|
|
143
|
-
renderList(agent.instructions?.length
|
|
152
|
+
renderList(agent.instructions?.length
|
|
153
|
+
? agent.instructions
|
|
154
|
+
: getDefaultAgentInstructions(config)),
|
|
144
155
|
"",
|
|
145
156
|
];
|
|
146
157
|
const renderAgentsMarkdown = (config, request) => {
|
|
@@ -160,7 +171,7 @@ const renderAgentsMarkdown = (config, request) => {
|
|
|
160
171
|
...renderMcpSection(agent.mcp, config, origin),
|
|
161
172
|
...renderImportantLinksSection(agent, config, origin),
|
|
162
173
|
...renderVersionsSection(config, origin),
|
|
163
|
-
...renderInstructionsSection(agent),
|
|
174
|
+
...renderInstructionsSection(agent, config),
|
|
164
175
|
].join("\n");
|
|
165
176
|
};
|
|
166
177
|
export const createAgentsRoute = ({ config, transform, }) => {
|
package/dist/routes/chat.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type LanguageModel } from "ai";
|
|
2
|
-
import type
|
|
2
|
+
import { type GeistdocsConfig } from "../config";
|
|
3
3
|
import type { GeistdocsSourceBundle } from "../source";
|
|
4
4
|
type SourceBundle = GeistdocsSourceBundle;
|
|
5
5
|
interface ChatProxyConfig {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/routes/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,aAAa,EAQnB,MAAM,IAAI,CAAC;AAGZ,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/routes/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,aAAa,EAQnB,MAAM,IAAI,CAAC;AAGZ,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,WAAW,CAAC;AAEhE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,KAAK,YAAY,GAAG,qBAAqB,CAAC;AAyB1C,UAAU,eAAe;IACvB,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACnE,GAAG,EAAE,MAAM,CAAC;CACb;AAED,UAAU,sBAAsB;IAC9B,MAAM,EAAE,IAAI,CACV,eAAe,EACf,IAAI,GAAG,UAAU,GAAG,iBAAiB,GAAG,cAAc,CACvD,CAAC;IACF;;;;;OAKG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;CAC1B;AAqrBD,eAAO,MAAM,eAAe,GAAI,4CAM7B,sBAAsB;gBAIE,OAAO;;CA0IjC,CAAC"}
|
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) => {
|