@vercel/geistdocs 2.0.2 → 2.2.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.
Files changed (56) hide show
  1. package/dist/cli/index.js +1 -1
  2. package/dist/components/link.d.ts +5 -0
  3. package/dist/components/link.d.ts.map +1 -0
  4. package/dist/components/link.js +4 -0
  5. package/dist/internal/docs-link-class-name.d.ts +2 -0
  6. package/dist/internal/docs-link-class-name.d.ts.map +1 -0
  7. package/dist/internal/docs-link-class-name.js +3 -0
  8. package/dist/internal/page-tree-visibility.d.ts +4 -0
  9. package/dist/internal/page-tree-visibility.d.ts.map +1 -0
  10. package/dist/internal/page-tree-visibility.js +42 -0
  11. package/dist/page-visibility.d.ts +7 -0
  12. package/dist/page-visibility.d.ts.map +1 -1
  13. package/dist/pages/docs.d.ts +25 -21
  14. package/dist/pages/docs.d.ts.map +1 -1
  15. package/dist/pages/docs.js +53 -17
  16. package/dist/proxy.d.ts +4 -1
  17. package/dist/proxy.d.ts.map +1 -1
  18. package/dist/proxy.js +42 -12
  19. package/dist/routes/chat.d.ts +4 -1
  20. package/dist/routes/chat.d.ts.map +1 -1
  21. package/dist/routes/chat.js +58 -25
  22. package/dist/routes/llms.d.ts +14 -10
  23. package/dist/routes/llms.d.ts.map +1 -1
  24. package/dist/routes/llms.js +50 -8
  25. package/dist/routes/search-export.d.ts +3 -1
  26. package/dist/routes/search-export.d.ts.map +1 -1
  27. package/dist/routes/search-export.js +4 -3
  28. package/dist/routes/search.d.ts +3 -1
  29. package/dist/routes/search.d.ts.map +1 -1
  30. package/dist/routes/search.js +4 -3
  31. package/dist/routes/sitemap.d.ts +3 -2
  32. package/dist/routes/sitemap.d.ts.map +1 -1
  33. package/dist/routes/sitemap.js +7 -4
  34. package/dist/source.d.ts +1 -0
  35. package/dist/source.d.ts.map +1 -1
  36. package/docs/agents.md +1 -1
  37. package/docs/llms.txt +114 -3
  38. package/docs/manifest.json +1 -1
  39. package/docs/pages/configuration.md +53 -0
  40. package/docs/pages/getting-started.md +8 -0
  41. package/docs/pages/llms-txt.md +2 -0
  42. package/docs/pages/md.md +4 -0
  43. package/docs/pages/packages.md +6 -2
  44. package/docs/pages/proxy.md +14 -0
  45. package/docs/pages/syntax.md +26 -0
  46. package/package.json +5 -1
  47. package/template/AGENTS.md +2 -1
  48. package/template/app/styles/geistdocs.css +2 -2
  49. package/template/content/docs/configuration.mdx +53 -0
  50. package/template/content/docs/getting-started.mdx +9 -0
  51. package/template/content/docs/llms-txt.mdx +2 -0
  52. package/template/content/docs/md.mdx +4 -0
  53. package/template/content/docs/packages.mdx +6 -2
  54. package/template/content/docs/proxy.mdx +14 -0
  55. package/template/content/docs/syntax.mdx +26 -0
  56. package/template/package.json +1 -1
@@ -1,6 +1,7 @@
1
1
  import { type LanguageModel } from "ai";
2
2
  import { type GeistdocsConfig } from "../config";
3
3
  import { type ChatMixedbreadOptions } from "../internal/chat-retrieval";
4
+ import { type GeistdocsPageFilter } from "../page-visibility";
4
5
  import type { GeistdocsSourceBundle } from "../source";
5
6
  type SourceBundle = GeistdocsSourceBundle;
6
7
  interface ChatProxyConfig {
@@ -25,6 +26,8 @@ interface CreateChatRouteOptions {
25
26
  * `config.ai.eveAgent`. Mutually exclusive with `proxy`.
26
27
  */
27
28
  eveAgent?: ChatEveAgentOptions;
29
+ /** Narrows the stable public corpus available to Ask AI. */
30
+ filterPage?: GeistdocsPageFilter;
28
31
  /**
29
32
  * Server-only Mixedbread overrides. Environment variables are used when
30
33
  * these values are omitted.
@@ -42,7 +45,7 @@ interface CreateChatRouteOptions {
42
45
  source?: SourceBundle;
43
46
  sources?: SourceBundle[];
44
47
  }
45
- export declare const createChatRoute: ({ config, eveAgent, mixedbread, model, proxy, source, sources, }: CreateChatRouteOptions) => {
48
+ export declare const createChatRoute: ({ config, eveAgent, filterPage, mixedbread, model, proxy, source, sources, }: CreateChatRouteOptions) => {
46
49
  POST: (req: Request) => Promise<Response>;
47
50
  maxDuration: 800;
48
51
  };
@@ -1 +1 @@
1
- {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/routes/chat.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,aAAa,EAQnB,MAAM,IAAI,CAAC;AAGZ,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,WAAW,CAAC;AAKhE,OAAO,EAEL,KAAK,qBAAqB,EAG3B,MAAM,4BAA4B,CAAC;AASpC,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,mBAAmB;IAC3B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACnE,qEAAqE;IACrE,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,UAAU,sBAAsB;IAC9B,MAAM,EAAE,IAAI,CACV,eAAe,EACf,IAAI,GAAG,UAAU,GAAG,iBAAiB,GAAG,QAAQ,GAAG,cAAc,CAClE,CAAC;IACF;;;OAGG;IACH,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B;;;OAGG;IACH,UAAU,CAAC,EAAE,qBAAqB,CAAC;IACnC;;;;;;OAMG;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;AA62BD,eAAO,MAAM,eAAe,GAAI,kEAQ7B,sBAAsB;gBAcE,OAAO;;CAkLjC,CAAC"}
1
+ {"version":3,"file":"chat.d.ts","sourceRoot":"","sources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LjC,CAAC"}
@@ -6,7 +6,7 @@ import { getPublicPath } from "../config";
6
6
  import { createSourceChunk, createSourceChunks, } from "../internal/chat/source-chunks";
7
7
  import { createChatDocumentSearch, } from "../internal/chat-retrieval";
8
8
  import { buildEveAgentTranscript, capLastUserMessageText, getEveAgentSessionHandle, resolveEveAgentUrl, runEveAgentTurn, } from "../internal/eve-agent";
9
- import { isPageVisibleForSurface } from "../page-visibility";
9
+ import { isPageVisibleForSurface, } from "../page-visibility";
10
10
  const DEFAULT_CHAT_MODEL = "openai/gpt-5.6-sol";
11
11
  const MAX_CONTEXT_CHARS = 1500;
12
12
  const MAX_EVE_AGENT_MESSAGE_CHARS = 4000;
@@ -79,10 +79,12 @@ const isChatRequestBody = (value) => typeof value === "object" &&
79
79
  Array.isArray(value.messages);
80
80
  const getPageData = (page) => page.data;
81
81
  const getStructuredContent = (page) => JSON.stringify(getPageData(page).structuredData?.contents ?? "");
82
- const createSearchServer = (sources, lang) => {
82
+ const isChatPageVisible = (page, lang, source, filterPage) => isPageVisibleForSurface(page, "chat") &&
83
+ (filterPage?.(page, { lang, source }) ?? true);
84
+ const createSearchServer = (sources, lang, filterPage) => {
83
85
  const indexes = sources.flatMap((source) => source.source
84
86
  .getPages(lang)
85
- .filter((page) => isPageVisibleForSurface(page, "chat"))
87
+ .filter((page) => isChatPageVisible(page, lang, source, filterPage))
86
88
  .map((page) => {
87
89
  const data = getPageData(page);
88
90
  const structuredData = data.structuredData ??
@@ -97,14 +99,18 @@ const createSearchServer = (sources, lang) => {
97
99
  }));
98
100
  return initAdvancedSearch({ indexes });
99
101
  };
100
- const resolveSearchResult = ({ basePath, content, lang, sources, url, }) => {
101
- const result = sources
102
- .map((source) => source.source.getPageByHref(url, { language: lang }))
103
- .find((entry) => entry?.page);
104
- if (!result?.page) {
102
+ const resolveSearchResult = ({ basePath, content, filterPage, lang, sources, url, }) => {
103
+ const match = sources
104
+ .map((source) => ({
105
+ result: source.source.getPageByHref(url, { language: lang }),
106
+ source,
107
+ }))
108
+ .find(({ result }) => result?.page);
109
+ if (!(match?.result?.page &&
110
+ isChatPageVisible(match.result.page, lang, match.source, filterPage))) {
105
111
  return null;
106
112
  }
107
- const { page } = result;
113
+ const { page } = match.result;
108
114
  const data = getPageData(page);
109
115
  return {
110
116
  title: data.title ?? page.url,
@@ -114,14 +120,15 @@ const resolveSearchResult = ({ basePath, content, lang, sources, url, }) => {
114
120
  url: getPublicPath(page.url, basePath),
115
121
  };
116
122
  };
117
- const searchDocsWithOrama = async ({ basePath, lang, limit, query, sources, }) => {
118
- const searchServer = createSearchServer(sources, lang);
123
+ const searchDocsWithOrama = async ({ basePath, filterPage, lang, limit, query, sources, }) => {
124
+ const searchServer = createSearchServer(sources, lang, filterPage);
119
125
  const results = await searchServer.search(query);
120
126
  const seenSlugs = new Set();
121
127
  return results
122
128
  .map(({ content, type, url }) => resolveSearchResult({
123
129
  basePath,
124
130
  content: type === "text" ? content : undefined,
131
+ filterPage,
125
132
  lang,
126
133
  sources,
127
134
  url,
@@ -136,15 +143,16 @@ const searchDocsWithOrama = async ({ basePath, lang, limit, query, sources, }) =
136
143
  })
137
144
  .slice(0, limit);
138
145
  };
139
- const createDocumentSearch = ({ config, mixedbread, sources, }) => {
146
+ const createDocumentSearch = ({ config, filterPage, mixedbread, sources, }) => {
140
147
  const fallback = ({ lang, limit, query }) => searchDocsWithOrama({
141
148
  basePath: config.basePath,
149
+ filterPage,
142
150
  lang,
143
151
  limit,
144
152
  query,
145
153
  sources,
146
154
  });
147
- return createChatDocumentSearch({
155
+ const search = createChatDocumentSearch({
148
156
  fallback,
149
157
  mixedbread: {
150
158
  ...mixedbread,
@@ -162,6 +170,18 @@ const createDocumentSearch = ({ config, mixedbread, sources, }) => {
162
170
  provider: config.ai?.retrieval,
163
171
  siteId: config.siteId,
164
172
  });
173
+ return async (input) => {
174
+ const documents = await search({ ...input, limit: input.limit * 3 });
175
+ return documents
176
+ .filter((document) => sources.some((source) => {
177
+ const result = source.source.getPageByHref(document.slug, {
178
+ language: input.lang,
179
+ });
180
+ return Boolean(result?.page &&
181
+ isChatPageVisible(result.page, input.lang, source, filterPage));
182
+ }))
183
+ .slice(0, input.limit);
184
+ };
165
185
  };
166
186
  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 ? "..." : ""}`;
167
187
  const getRouteCandidates = ({ basePath, currentRoute, lang, }) => {
@@ -170,18 +190,19 @@ const getRouteCandidates = ({ basePath, currentRoute, lang, }) => {
170
190
  const withoutLanguage = stripLanguagePrefix(withoutBasePath, lang);
171
191
  return Array.from(new Set([pathname, withoutBasePath, withoutLanguage]));
172
192
  };
173
- const findCurrentPage = ({ basePath, currentRoute, lang, sources, }) => {
193
+ const findCurrentPage = ({ basePath, currentRoute, filterPage, lang, sources, }) => {
174
194
  const candidates = getRouteCandidates({ basePath, currentRoute, lang });
175
195
  for (const source of sources) {
176
196
  for (const candidate of candidates) {
177
197
  const result = source.source.getPageByHref(candidate, { language: lang });
178
- if (result?.page && isPageVisibleForSurface(result.page, "chat")) {
198
+ if (result?.page &&
199
+ isChatPageVisible(result.page, lang, source, filterPage)) {
179
200
  return { page: result.page, source };
180
201
  }
181
202
  }
182
203
  const page = source.source
183
204
  .getPages(lang)
184
- .filter((entry) => isPageVisibleForSurface(entry, "chat"))
205
+ .filter((entry) => isChatPageVisible(entry, lang, source, filterPage))
185
206
  .find((entry) => candidates.includes(normalizePathname(entry.url)));
186
207
  if (page) {
187
208
  return { page, source };
@@ -189,7 +210,7 @@ const findCurrentPage = ({ basePath, currentRoute, lang, sources, }) => {
189
210
  }
190
211
  return null;
191
212
  };
192
- const getCurrentPageDoc = async ({ basePath, currentRoute, lang, pageContext, sources, }) => {
213
+ const getCurrentPageDoc = async ({ basePath, currentRoute, filterPage, lang, pageContext, sources, }) => {
193
214
  if (pageContext) {
194
215
  return {
195
216
  title: pageContext.title,
@@ -199,7 +220,13 @@ const getCurrentPageDoc = async ({ basePath, currentRoute, lang, pageContext, so
199
220
  url: pageContext.url,
200
221
  };
201
222
  }
202
- const result = findCurrentPage({ basePath, currentRoute, lang, sources });
223
+ const result = findCurrentPage({
224
+ basePath,
225
+ currentRoute,
226
+ filterPage,
227
+ lang,
228
+ sources,
229
+ });
203
230
  if (!result) {
204
231
  return null;
205
232
  }
@@ -213,7 +240,7 @@ const getCurrentPageDoc = async ({ basePath, currentRoute, lang, pageContext, so
213
240
  };
214
241
  };
215
242
  const isFirstUserMessage = (messages) => messages.filter((message) => message.role === "user").length === 1;
216
- const buildProxyMessages = async ({ actualMessages, config, currentRoute, defaultLanguage, languages, pageContext, routeSources, searchDocuments, }) => {
243
+ const buildProxyMessages = async ({ actualMessages, config, currentRoute, defaultLanguage, filterPage, languages, pageContext, routeSources, searchDocuments, }) => {
217
244
  if (!isFirstUserMessage(actualMessages)) {
218
245
  return { messages: actualMessages, sourceDocs: [] };
219
246
  }
@@ -231,6 +258,7 @@ const buildProxyMessages = async ({ actualMessages, config, currentRoute, defaul
231
258
  const currentPageDoc = await getCurrentPageDoc({
232
259
  basePath: config.basePath,
233
260
  currentRoute,
261
+ filterPage,
234
262
  lang,
235
263
  pageContext,
236
264
  sources: routeSources,
@@ -405,7 +433,7 @@ You are a helpful assistant specializing in answering questions strictly. If inf
405
433
  - Be friendly, clear, and specific.`;
406
434
  return [basePrompt, config.ai?.prompt].filter(Boolean).join("\n\n");
407
435
  };
408
- const createTools = (writer, sources, searchDocuments, defaultLanguage, basePath) => {
436
+ const createTools = (writer, sources, searchDocuments, defaultLanguage, basePath, filterPage) => {
409
437
  const log = (message) => {
410
438
  console.log(`[Geistdocs chat] ${message}`);
411
439
  };
@@ -461,7 +489,7 @@ const createTools = (writer, sources, searchDocuments, defaultLanguage, basePath
461
489
  const doc = sources
462
490
  .flatMap((source) => source.source
463
491
  .getPages(lang)
464
- .filter((page) => isPageVisibleForSurface(page, "chat"))
492
+ .filter((page) => isChatPageVisible(page, lang, source, filterPage))
465
493
  .map((page) => ({ page, source })))
466
494
  .find(({ page }) => page.url === sourceSlug || page.url.endsWith(sourceSlug));
467
495
  if (!doc) {
@@ -490,7 +518,7 @@ const createTools = (writer, sources, searchDocuments, defaultLanguage, basePath
490
518
  execute: ({ lang }) => {
491
519
  const pages = sources.flatMap((source) => source.source
492
520
  .getPages(lang)
493
- .filter((page) => isPageVisibleForSurface(page, "chat")));
521
+ .filter((page) => isChatPageVisible(page, lang, source, filterPage)));
494
522
  const docsList = pages
495
523
  .map((doc) => `- **${doc.data.title}** (${getPublicPath(doc.url, basePath)}): ${doc.data.description}`)
496
524
  .join("\n");
@@ -507,13 +535,14 @@ const createChatErrorResponse = (error, status) => new Response(JSON.stringify({
507
535
  status,
508
536
  headers: { "Content-Type": "application/json" },
509
537
  });
510
- const createEveAgentResponse = async ({ actualMessages, agentUrl, config, currentRoute, defaultLanguage, eveAgent, languages, messages, pageContext, req, routeSources, searchDocuments, }) => {
538
+ const createEveAgentResponse = async ({ actualMessages, agentUrl, config, currentRoute, defaultLanguage, eveAgent, filterPage, languages, messages, pageContext, req, routeSources, searchDocuments, }) => {
511
539
  const cappedMessages = capLastUserMessageText(actualMessages, MAX_EVE_AGENT_MESSAGE_CHARS);
512
540
  const { messages: contextMessages, sourceDocs } = await buildProxyMessages({
513
541
  actualMessages: cappedMessages,
514
542
  config,
515
543
  currentRoute,
516
544
  defaultLanguage,
545
+ filterPage,
517
546
  languages,
518
547
  pageContext,
519
548
  routeSources,
@@ -559,11 +588,12 @@ const resolveSources = (source, sources) => {
559
588
  }
560
589
  return resolvedSources;
561
590
  };
562
- export const createChatRoute = ({ config, eveAgent, mixedbread, model = DEFAULT_CHAT_MODEL, proxy, source, sources, }) => {
591
+ export const createChatRoute = ({ config, eveAgent, filterPage, mixedbread, model = DEFAULT_CHAT_MODEL, proxy, source, sources, }) => {
563
592
  const { defaultLanguage, languages } = getLanguages(config);
564
593
  const routeSources = resolveSources(source, sources);
565
594
  const searchDocuments = createDocumentSearch({
566
595
  config,
596
+ filterPage,
567
597
  mixedbread,
568
598
  sources: routeSources,
569
599
  });
@@ -593,6 +623,7 @@ export const createChatRoute = ({ config, eveAgent, mixedbread, model = DEFAULT_
593
623
  currentRoute,
594
624
  defaultLanguage,
595
625
  eveAgent,
626
+ filterPage,
596
627
  languages,
597
628
  messages,
598
629
  pageContext,
@@ -607,6 +638,7 @@ export const createChatRoute = ({ config, eveAgent, mixedbread, model = DEFAULT_
607
638
  config,
608
639
  currentRoute,
609
640
  defaultLanguage,
641
+ filterPage,
610
642
  languages,
611
643
  pageContext,
612
644
  routeSources,
@@ -648,6 +680,7 @@ export const createChatRoute = ({ config, eveAgent, mixedbread, model = DEFAULT_
648
680
  const contextDoc = await getCurrentPageDoc({
649
681
  basePath: config.basePath,
650
682
  currentRoute,
683
+ filterPage,
651
684
  lang: getRequestLanguage({
652
685
  basePath: config.basePath,
653
686
  currentRoute,
@@ -685,7 +718,7 @@ export const createChatRoute = ({ config, eveAgent, mixedbread, model = DEFAULT_
685
718
  model,
686
719
  messages: modelMessages,
687
720
  stopWhen: stepCountIs(10),
688
- tools: createTools(writer, routeSources, searchDocuments, defaultLanguage, config.basePath),
721
+ tools: createTools(writer, routeSources, searchDocuments, defaultLanguage, config.basePath, filterPage),
689
722
  system: createSystemPrompt(currentRoute ?? "/", config),
690
723
  prepareStep: ({ stepNumber }) => {
691
724
  if (stepNumber === 0) {
@@ -1,9 +1,10 @@
1
1
  import type { NextRequest } from "next/server";
2
2
  import { type GeistdocsConfig } from "../config.js";
3
+ import { type GeistdocsPageFilter } from "../page-visibility.js";
3
4
  import type { GeistdocsSourceBundle } from "../source.js";
4
5
  type SourceBundle = GeistdocsSourceBundle;
5
6
  type GeistdocsPage = NonNullable<ReturnType<SourceBundle["source"]["getPage"]>>;
6
- interface DocsMarkdownParams {
7
+ export interface DocsMarkdownParams extends Record<string, string | string[] | undefined> {
7
8
  lang: string;
8
9
  slug?: string[];
9
10
  }
@@ -14,9 +15,7 @@ interface MarkdownTransformContext {
14
15
  }
15
16
  type MarkdownTransform = (markdown: string, context: MarkdownTransformContext) => Promise<string> | string;
16
17
  interface CreateLlmsRouteOptions {
17
- filterPage?: (page: GeistdocsPage, context: {
18
- lang: string;
19
- }) => boolean;
18
+ filterPage?: GeistdocsPageFilter;
20
19
  source?: SourceBundle;
21
20
  sources?: SourceBundle[];
22
21
  transform?: MarkdownTransform;
@@ -29,7 +28,15 @@ export declare const createLlmsRoute: ({ filterPage, source, sources, transform,
29
28
  }) => Promise<Response>;
30
29
  revalidate: false;
31
30
  };
32
- export interface CreateDocsMarkdownRouteOptions {
31
+ export interface MarkdownPageAccessContext<Params extends DocsMarkdownParams = DocsMarkdownParams> {
32
+ params: Params;
33
+ request: Request;
34
+ source: SourceBundle;
35
+ }
36
+ export type MarkdownPageAccessFilter<Params extends DocsMarkdownParams = DocsMarkdownParams> = (page: GeistdocsPage, context: MarkdownPageAccessContext<Params>) => boolean | Promise<boolean>;
37
+ export interface CreateDocsMarkdownRouteOptions<Params extends DocsMarkdownParams = DocsMarkdownParams> {
38
+ /** Return false to serve the same response as a missing page. */
39
+ canViewPage?: MarkdownPageAccessFilter<Params>;
33
40
  config?: Pick<GeistdocsConfig, "basePath" | "defaultLanguage" | "siteUrl" | "translations">;
34
41
  filterStaticParams?: (params: DocsMarkdownParams) => boolean;
35
42
  /** Customize the agent-readable Markdown response for missing pages, or disable it. */
@@ -63,12 +70,9 @@ export interface MarkdownNotFoundOptions {
63
70
  */
64
71
  status?: 200 | 404 | 410;
65
72
  }
66
- export declare const createDocsMarkdownRoute: ({ config, filterStaticParams, notFound: notFoundOptions, source, sources, transform, }: CreateDocsMarkdownRouteOptions) => {
73
+ export declare const createDocsMarkdownRoute: <Params extends DocsMarkdownParams = DocsMarkdownParams>({ canViewPage, config, filterStaticParams, notFound: notFoundOptions, source, sources, transform, }: CreateDocsMarkdownRouteOptions<Params>) => {
67
74
  GET: (request: Request, { params }: {
68
- params: Promise<{
69
- lang: string;
70
- slug?: string[];
71
- }>;
75
+ params: Promise<Params>;
72
76
  }) => Promise<Response>;
73
77
  generateStaticParams: ({ params, }?: {
74
78
  params?: Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"llms.d.ts","sourceRoot":"","sources":["../../src/routes/llms.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,cAAc,CAAC;AAStB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAE1D,KAAK,YAAY,GAAG,qBAAqB,CAAC;AAC1C,KAAK,aAAa,GAAG,WAAW,CAAC,UAAU,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAehF,UAAU,kBAAkB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,UAAU,wBAAwB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,YAAY,CAAC;CACtB;AAED,KAAK,iBAAiB,GAAG,CACvB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,wBAAwB,KAC9B,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;AAE9B,UAAU,sBAAsB;IAC9B,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC;IACzE,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,SAAS,CAAC,EAAE,iBAAiB,CAAC;CAC/B;AAqOD,eAAO,MAAM,eAAe,GAAI,6CAK7B,sBAAsB;gBAIf,WAAW,cACL;QAAE,MAAM,EAAE,OAAO,C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,MAAM,EAAE,CAAA;KAAE,KAAK,MAAM,CAAC;IACzE,oDAAoD;IACpD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,MAAM,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;CAC1B;AAED,eAAO,MAAM,uBAAuB,GAClC,MAAM,SAAS,kBAAkB,GAAG,kBAAkB,EACtD,qGAQC,8BAA8B,CAAC,MAAM,CAAC;mBAkN5B,OAAO,cACJ;QAAE,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;KAAE;yCAwEtC;QACD,MAAM,CAAC,EAAE,OAAO,CAAC;YAAE,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KACrC;;CAgBF,CAAC"}
@@ -4,10 +4,12 @@ import { getPublicPath, normalizeBasePath, withBasePath, } from "../config.js";
4
4
  import { resolveAgentProductContext } from "../internal/agent-product.js";
5
5
  import { resolvePageMarkdownUrl } from "../internal/markdown-url.js";
6
6
  import { findSmartNotFoundSuggestions, renderSmartNotFoundMarkdown, } from "../internal/smart-not-found.js";
7
- import { isPageVisibleForSurface } from "../page-visibility.js";
7
+ import { isPageVisibleForSurface, } from "../page-visibility.js";
8
8
  const INDEX_MARKDOWN_PATTERN = /\/index\.md$/;
9
9
  const MARKDOWN_PATTERN = /\.md$/;
10
10
  const MARKDOWN_CACHE_CONTROL = "public, max-age=0, s-maxage=86400, stale-while-revalidate=604800";
11
+ const DEFAULT_MAX_SUGGESTIONS = 5;
12
+ const SUGGESTION_ACCESS_CANDIDATE_MULTIPLIER = 3;
11
13
  const resolveSources = (source, sources, caller) => {
12
14
  const resolvedSources = sources ?? (source ? [source] : []);
13
15
  if (resolvedSources.length === 0) {
@@ -138,7 +140,7 @@ export const createLlmsRoute = ({ filterPage, source, sources, transform, }) =>
138
140
  const scanned = await Promise.all(routeSources.flatMap((entry) => entry.source
139
141
  .getPages(lang)
140
142
  .filter((page) => isPageVisibleForSurface(page, "llms") &&
141
- (filterPage?.(page, { lang }) ?? true))
143
+ (filterPage?.(page, { lang, source: entry }) ?? true))
142
144
  .map(async (page) => {
143
145
  const rendered = await entry.getPageMarkdown(page);
144
146
  return transform
@@ -157,7 +159,7 @@ export const createLlmsRoute = ({ filterPage, source, sources, transform, }) =>
157
159
  revalidate: false,
158
160
  };
159
161
  };
160
- export const createDocsMarkdownRoute = ({ config, filterStaticParams, notFound: notFoundOptions = {}, source, sources, transform, }) => {
162
+ export const createDocsMarkdownRoute = ({ canViewPage, config, filterStaticParams, notFound: notFoundOptions = {}, source, sources, transform, }) => {
161
163
  const routeSources = resolveSources(source, sources, "createDocsMarkdownRoute");
162
164
  const routingConfig = {
163
165
  ...(routeSources[0].routingConfig ?? {}),
@@ -217,6 +219,7 @@ export const createDocsMarkdownRoute = ({ config, filterStaticParams, notFound:
217
219
  description: data.description ?? data.summary,
218
220
  keywords: data.keywords,
219
221
  path,
222
+ page,
220
223
  scope: getPageScope(path, page.slugs.length),
221
224
  source: entry,
222
225
  url,
@@ -254,13 +257,34 @@ export const createDocsMarkdownRoute = ({ config, filterStaticParams, notFound:
254
257
  ? routeSources.filter((source) => mappedSources.has(source))
255
258
  : baseUrlMatches;
256
259
  };
257
- const createSmartNotFoundResponse = ({ pathContext, }) => {
260
+ const createSmartNotFoundResponse = async ({ pathContext, request, params, }) => {
258
261
  const { localePrefix, localizedPath, requestedPath } = pathContext;
259
262
  const suggestionPages = selectSuggestionPages(localizedPath, getSuggestionPages(pathContext.lang));
260
- const suggestions = findSmartNotFoundSuggestions(localizedPath, suggestionPages, {
261
- limit: smartNotFoundOptions.maxSuggestions,
263
+ const maxSuggestions = Number.isFinite(smartNotFoundOptions.maxSuggestions)
264
+ ? Math.max(0, Math.floor(smartNotFoundOptions.maxSuggestions ?? 0))
265
+ : DEFAULT_MAX_SUGGESTIONS;
266
+ const rankedSuggestions = findSmartNotFoundSuggestions(localizedPath, suggestionPages, {
267
+ limit: maxSuggestions * SUGGESTION_ACCESS_CANDIDATE_MULTIPLIER,
262
268
  minScore: smartNotFoundOptions.minScore,
263
269
  });
270
+ const pagesByUrl = new Map(suggestionPages.map((page) => [page.url, page]));
271
+ const access = await Promise.all(rankedSuggestions.map(async (suggestion) => {
272
+ const candidate = pagesByUrl.get(suggestion.url);
273
+ return {
274
+ suggestion,
275
+ visible: !candidate ||
276
+ ((await canViewPage?.(candidate.page, {
277
+ params,
278
+ request,
279
+ source: candidate.source,
280
+ })) ??
281
+ true),
282
+ };
283
+ }));
284
+ const suggestions = access
285
+ .filter(({ visible }) => visible)
286
+ .map(({ suggestion }) => suggestion)
287
+ .slice(0, maxSuggestions);
264
288
  const allPagesUrl = getPublicPath(joinPath(localePrefix, "/llms.txt"), routingConfig.basePath);
265
289
  return createNotFoundResponse(requestedPath, {
266
290
  headers: {
@@ -272,11 +296,12 @@ export const createDocsMarkdownRoute = ({ config, filterStaticParams, notFound:
272
296
  requestedPath,
273
297
  suggestions,
274
298
  }),
275
- status: smartNotFoundOptions.status === 410 ? 410 : 404,
299
+ status: !canViewPage && smartNotFoundOptions.status === 410 ? 410 : 404,
276
300
  });
277
301
  };
278
302
  const GET = async (request, { params }) => {
279
- const { slug, lang } = await params;
303
+ const resolvedParams = await params;
304
+ const { slug, lang } = resolvedParams;
280
305
  const pathContext = notFoundOptions
281
306
  ? getRequestedPathContext({ lang, slug })
282
307
  : undefined;
@@ -290,9 +315,26 @@ export const createDocsMarkdownRoute = ({ config, filterStaticParams, notFound:
290
315
  }
291
316
  return createSmartNotFoundResponse({
292
317
  pathContext,
318
+ request,
319
+ params: resolvedParams,
293
320
  });
294
321
  }
295
322
  const { page, source: pageSource } = result;
323
+ const canView = (await canViewPage?.(page, {
324
+ params: resolvedParams,
325
+ request,
326
+ source: pageSource,
327
+ })) ?? true;
328
+ if (!canView) {
329
+ if (!pathContext) {
330
+ notFound();
331
+ }
332
+ return createSmartNotFoundResponse({
333
+ pathContext,
334
+ request,
335
+ params: resolvedParams,
336
+ });
337
+ }
296
338
  const rendered = await pageSource.getPageMarkdown(page);
297
339
  const pageData = page.data;
298
340
  const canonicalPath = withBasePath(pageData.canonical ?? page.url, routingConfig.basePath);
@@ -1,11 +1,13 @@
1
1
  import { type GeistdocsConfig } from "../config";
2
+ import { type GeistdocsPageFilter } from "../page-visibility";
2
3
  import type { GeistdocsSourceBundle } from "../source";
3
4
  interface CreateSearchExportRouteOptions {
4
5
  config: Pick<GeistdocsConfig, "ai" | "basePath" | "defaultLanguage" | "siteId" | "translations">;
6
+ filterPage?: GeistdocsPageFilter;
5
7
  source?: GeistdocsSourceBundle;
6
8
  sources?: GeistdocsSourceBundle[];
7
9
  }
8
- export declare const createSearchExportRoute: ({ config, source, sources, }: CreateSearchExportRouteOptions) => {
10
+ export declare const createSearchExportRoute: ({ config, filterPage, source, sources, }: CreateSearchExportRouteOptions) => {
9
11
  GET: () => Promise<Response>;
10
12
  };
11
13
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"search-export.d.ts","sourceRoot":"","sources":["../../src/routes/search-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,WAAW,CAAC;AAOhE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,UAAU,8BAA8B;IACtC,MAAM,EAAE,IAAI,CACV,eAAe,EACf,IAAI,GAAG,UAAU,GAAG,iBAAiB,GAAG,QAAQ,GAAG,cAAc,CAClE,CAAC;IACF,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,OAAO,CAAC,EAAE,qBAAqB,EAAE,CAAC;CACnC;AAwBD,eAAO,MAAM,uBAAuB,GAAI,8BAIrC,8BAA8B;;CAyChC,CAAC"}
1
+ {"version":3,"file":"search-export.d.ts","sourceRoot":"","sources":["../../src/routes/search-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,WAAW,CAAC;AAMhE,OAAO,EACL,KAAK,mBAAmB,EAEzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,UAAU,8BAA8B;IACtC,MAAM,EAAE,IAAI,CACV,eAAe,EACf,IAAI,GAAG,UAAU,GAAG,iBAAiB,GAAG,QAAQ,GAAG,cAAc,CAClE,CAAC;IACF,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,OAAO,CAAC,EAAE,qBAAqB,EAAE,CAAC;CACnC;AAwBD,eAAO,MAAM,uBAAuB,GAAI,0CAKrC,8BAA8B;;CA6ChC,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { getPublicPath } from "../config";
2
2
  import { GEISTDOCS_SEARCH_EXPORT_VERSION, } from "../internal/search-export";
3
- import { isPageVisibleForSurface } from "../page-visibility";
3
+ import { isPageVisibleForSurface, } from "../page-visibility";
4
4
  const resolveSources = (source, sources) => {
5
5
  const resolvedSources = sources ?? (source ? [source] : []);
6
6
  if (resolvedSources.length === 0) {
@@ -12,14 +12,15 @@ const getLanguages = (config) => {
12
12
  const defaultLanguage = config.defaultLanguage ?? "en";
13
13
  return Array.from(new Set([defaultLanguage, ...Object.keys(config.translations ?? {})]));
14
14
  };
15
- export const createSearchExportRoute = ({ config, source, sources, }) => {
15
+ export const createSearchExportRoute = ({ config, filterPage, source, sources, }) => {
16
16
  const routeSources = resolveSources(source, sources);
17
17
  const GET = async () => {
18
18
  const documents = await Promise.all(getLanguages(config).flatMap((locale) => routeSources.flatMap((entry, sourceIndex) => {
19
19
  const sourceId = entry.id ?? `source-${sourceIndex + 1}`;
20
20
  return entry.source
21
21
  .getPages(locale)
22
- .filter((page) => isPageVisibleForSurface(page, "chat"))
22
+ .filter((page) => isPageVisibleForSurface(page, "chat") &&
23
+ (filterPage?.(page, { lang: locale, source: entry }) ?? true))
23
24
  .map(async (page) => ({
24
25
  content: await entry.getPageMarkdown(page),
25
26
  description: page.data.description ?? "",
@@ -1,13 +1,15 @@
1
1
  import type { GeistdocsConfig } from "../config";
2
+ import { type GeistdocsPageFilter } from "../page-visibility";
2
3
  import { type GeistdocsSourceBundle } from "../source";
3
4
  type SourceBundle = GeistdocsSourceBundle;
4
5
  type SearchSource = SourceBundle["source"];
5
6
  type SearchSourceInput = SearchSource | SourceBundle;
6
7
  interface CreateSearchRouteOptions {
7
8
  config: Pick<GeistdocsConfig, "defaultLanguage" | "translations">;
9
+ filterPage?: GeistdocsPageFilter<ReturnType<SearchSource["getPages"]>[number], SearchSourceInput>;
8
10
  source?: SearchSourceInput;
9
11
  sources?: SearchSourceInput[];
10
12
  }
11
- export declare const createSearchRoute: ({ config, source, sources, }: CreateSearchRouteOptions) => (request: Request) => Promise<Response>;
13
+ export declare const createSearchRoute: ({ config, filterPage, source, sources, }: CreateSearchRouteOptions) => (request: Request) => Promise<Response>;
12
14
  export {};
13
15
  //# sourceMappingURL=search.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/routes/search.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,EAAE,KAAK,qBAAqB,EAA2B,MAAM,WAAW,CAAC;AAEhF,KAAK,YAAY,GAAG,qBAAqB,CAAC;AAC1C,KAAK,YAAY,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;AAC3C,KAAK,iBAAiB,GAAG,YAAY,GAAG,YAAY,CAAC;AAIrD,UAAU,wBAAwB;IAChC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,iBAAiB,GAAG,cAAc,CAAC,CAAC;IAClE,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAC/B;AAgFD,eAAO,MAAM,iBAAiB,GAAI,8BAI/B,wBAAwB,4CAwE1B,CAAC"}
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/routes/search.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EACL,KAAK,mBAAmB,EAEzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,qBAAqB,EAA2B,MAAM,WAAW,CAAC;AAEhF,KAAK,YAAY,GAAG,qBAAqB,CAAC;AAC1C,KAAK,YAAY,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;AAC3C,KAAK,iBAAiB,GAAG,YAAY,GAAG,YAAY,CAAC;AAIrD,UAAU,wBAAwB;IAChC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,iBAAiB,GAAG,cAAc,CAAC,CAAC;IAClE,UAAU,CAAC,EAAE,mBAAmB,CAC9B,UAAU,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,EAC5C,iBAAiB,CAClB,CAAC;IACF,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAC/B;AAgFD,eAAO,MAAM,iBAAiB,GAAI,0CAK/B,wBAAwB,4CA4E1B,CAAC"}
@@ -3,7 +3,7 @@ import { createTokenizer as createTokenizerMandarin } from "@orama/tokenizers/ma
3
3
  import { defineI18n } from "fumadocs-core/i18n";
4
4
  import { findPath } from "fumadocs-core/page-tree";
5
5
  import { createI18nSearchAPI, } from "fumadocs-core/search/server";
6
- import { isPageVisibleForSurface } from "../page-visibility";
6
+ import { isPageVisibleForSurface, } from "../page-visibility";
7
7
  import { isGeistdocsSourceBundle } from "../source";
8
8
  const getLanguages = (config) => {
9
9
  const defaultLanguage = config.defaultLanguage ?? "en";
@@ -48,7 +48,7 @@ const getBreadcrumbs = (pageTree, url) => {
48
48
  }
49
49
  return breadcrumbs.length > 0 ? breadcrumbs : undefined;
50
50
  };
51
- export const createSearchRoute = ({ config, source, sources, }) => {
51
+ export const createSearchRoute = ({ config, filterPage, source, sources, }) => {
52
52
  const translations = config.translations ?? {};
53
53
  const routeSources = resolveSources(source, sources);
54
54
  const { defaultLanguage, languages } = getLanguages(config);
@@ -86,7 +86,8 @@ export const createSearchRoute = ({ config, source, sources, }) => {
86
86
  const getIndexes = () => languages.flatMap((locale) => routeSources.flatMap((source) => {
87
87
  const pageTree = getPageTree(source, locale);
88
88
  return getPages(source, locale)
89
- .filter((page) => isPageVisibleForSurface(page, "search"))
89
+ .filter((page) => isPageVisibleForSurface(page, "search") &&
90
+ (filterPage?.(page, { lang: locale, source }) ?? true))
90
91
  .map((page) => {
91
92
  const data = page.data;
92
93
  return {
@@ -1,6 +1,6 @@
1
1
  import type { NextRequest } from "next/server";
2
2
  import { type GeistdocsConfig } from "../config";
3
- import { type GeistdocsPageVisibilityData } from "../page-visibility";
3
+ import { type GeistdocsPageFilter, type GeistdocsPageVisibilityData } from "../page-visibility";
4
4
  import { type GeistdocsSourceBundle } from "../source";
5
5
  interface SitemapPage {
6
6
  data: {
@@ -25,6 +25,7 @@ interface SitemapSection {
25
25
  }
26
26
  interface CreateSitemapMarkdownRouteOptions {
27
27
  config: Pick<GeistdocsConfig, "basePath" | "defaultLanguage" | "translations">;
28
+ filterPage?: GeistdocsPageFilter<SitemapPage, SitemapSourceInput>;
28
29
  source?: SitemapSourceInput;
29
30
  sources?: SitemapSection[];
30
31
  title?: string;
@@ -32,7 +33,7 @@ interface CreateSitemapMarkdownRouteOptions {
32
33
  lang: string;
33
34
  }) => Promise<string> | string;
34
35
  }
35
- export declare const createSitemapMarkdownRoute: ({ config, source, sources, title, transform, }: CreateSitemapMarkdownRouteOptions) => {
36
+ export declare const createSitemapMarkdownRoute: ({ config, filterPage, source, sources, title, transform, }: CreateSitemapMarkdownRouteOptions) => {
36
37
  GET: (_req: NextRequest, { params }: {
37
38
  params: Promise<{
38
39
  lang: string;
@@ -1 +1 @@
1
- {"version":3,"file":"sitemap.d.ts","sourceRoot":"","sources":["../../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AAG,cAAc,CAChD,CAAC;IACF,UAAU,CAAC,EAAE,mBAAmB,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC;IAClE,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;AA8MD,eAAO,MAAM,0BAA0B,GAAI,4DAOxC,iCAAiC;gBAK1B,WAAW,cACL;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE;;;;;;CA6DpD,CAAC"}
@@ -125,11 +125,14 @@ const resolveSitemapSections = (source, sources) => {
125
125
  }
126
126
  return sections;
127
127
  };
128
- const getSectionPages = (source, lang, basePath) => {
128
+ const getSectionPages = (source, lang, basePath, filterPage) => {
129
129
  const pages = (isGeistdocsSourceBundle(source)
130
130
  ? source.source.getPages(lang)
131
131
  : source.getPages(lang));
132
- return pages.map((page) => ({
132
+ return pages
133
+ .filter((page) => isPageVisibleForSurface(page, "sitemap") &&
134
+ (filterPage?.(page, { lang, source }) ?? true))
135
+ .map((page) => ({
133
136
  ...page,
134
137
  data: {
135
138
  ...page.data,
@@ -141,7 +144,7 @@ const getSectionPages = (source, lang, basePath) => {
141
144
  };
142
145
  const getSectionTitle = (section) => section.title ??
143
146
  (isGeistdocsSourceBundle(section.source) ? section.source.label : undefined);
144
- export const createSitemapMarkdownRoute = ({ config, source, sources, title = "Documentation Sitemap", transform, }) => {
147
+ export const createSitemapMarkdownRoute = ({ config, filterPage, source, sources, title = "Documentation Sitemap", transform, }) => {
145
148
  const languages = getLanguages(config);
146
149
  const sections = resolveSitemapSections(source, sources);
147
150
  const GET = async (_req, { params }) => {
@@ -164,7 +167,7 @@ It is not intended to replace individual docs.
164
167
  `;
165
168
  const body = sections
166
169
  .map((section) => {
167
- const pages = getSectionPages(section.source, lang, config.basePath).filter((page) => isPageVisibleForSurface(page, "sitemap"));
170
+ const pages = getSectionPages(section.source, lang, config.basePath, filterPage);
168
171
  const tree = buildTree(pages);
169
172
  const renderedTree = tree
170
173
  .map((node) => renderNode(node, 0))