Skip to content

Commit 72e3819

Browse files
fix(docs): replace file:UUID patterns with URLs from filesV2 in LLM markdown routes (#6164)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]>
1 parent 1ec5b25 commit 72e3819

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

packages/fern-docs/bundle/src/server/getMarkdownForPath.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createPruneKey } from "@fern-api/docs-loader";
22
import type { DocsLoader } from "@fern-api/docs-server/docs-loader";
33
import { slugToHref } from "@fern-api/docs-utils";
4+
import type { FileData } from "@fern-api/docs-utils/types/file-data";
45
import { ApiDefinition, FernNavigation } from "@fern-api/fdr-sdk";
56
import type { EndpointDefinition } from "@fern-api/fdr-sdk/api-definition";
67
import { slugjoin } from "@fern-api/fdr-sdk/navigation";
@@ -56,6 +57,20 @@ function shouldIncludeLanguage(language: string, sdkLanguageFilter?: SdkLanguage
5657
return allowedLanguages.includes(language.toLowerCase());
5758
}
5859

60+
/**
61+
* Replaces file:UUID patterns in markdown with their corresponding URLs from filesV2.
62+
* This handles patterns like `file:abc123-def456-...` and replaces them with the actual file URL.
63+
*/
64+
function replaceFileReferences(markdown: string, files: Record<string, FileData>): string {
65+
return markdown.replace(/file:([a-f0-9-]+)/gi, (match, fileId) => {
66+
const fileData = files[fileId];
67+
if (fileData?.src) {
68+
return fileData.src;
69+
}
70+
return match;
71+
});
72+
}
73+
5974
function generateEndpointSections(
6075
endpoint: EndpointDefinition,
6176
apiDefinition?: ApiDefinition.ApiDefinition,
@@ -183,15 +198,18 @@ export async function getMarkdownForPath(
183198
return undefined;
184199
}
185200

186-
const page = await runAsyncSpan("docs.loader.getPage", () => loader.getPage(pageId), {
187-
"fern.docs.pageId": pageId
188-
});
201+
const [page, files] = await Promise.all([
202+
runAsyncSpan("docs.loader.getPage", () => loader.getPage(pageId), {
203+
"fern.docs.pageId": pageId
204+
}),
205+
runAsyncSpan("docs.loader.getFiles", () => loader.getFiles(), {})
206+
]);
189207
if (!page) {
190208
return undefined;
191209
}
192210

193211
const contentType = pageId.endsWith(".mdx") ? "mdx" : "markdown";
194-
const content = runSyncSpan(
212+
let content = runSyncSpan(
195213
"docs.convertToMarkdown",
196214
() =>
197215
convertToLlmTxtMarkdown(page.markdown, node.title, contentType === "mdx" ? "mdx" : "md", userRoles),
@@ -201,6 +219,8 @@ export async function getMarkdownForPath(
201219
}
202220
);
203221

222+
content = replaceFileReferences(content, files);
223+
204224
return {
205225
content,
206226
contentType

0 commit comments

Comments
 (0)