11import { createPruneKey } from "@fern-api/docs-loader" ;
22import type { DocsLoader } from "@fern-api/docs-server/docs-loader" ;
33import { slugToHref } from "@fern-api/docs-utils" ;
4+ import type { FileData } from "@fern-api/docs-utils/types/file-data" ;
45import { ApiDefinition , FernNavigation } from "@fern-api/fdr-sdk" ;
56import type { EndpointDefinition } from "@fern-api/fdr-sdk/api-definition" ;
67import { 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 ( / f i l e : ( [ a - f 0 - 9 - ] + ) / gi, ( match , fileId ) => {
66+ const fileData = files [ fileId ] ;
67+ if ( fileData ?. src ) {
68+ return fileData . src ;
69+ }
70+ return match ;
71+ } ) ;
72+ }
73+
5974function 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