import type { InferPageType } from 'fumadocs-core/source'; import { remarkInclude } from 'fumadocs-mdx/config'; import { remark } from 'remark'; import remarkGfm from 'remark-gfm'; import remarkMdx from 'remark-mdx'; import { apiSource, source } from './source'; const processor = remark() .use(remarkMdx) // needed for Fumadocs MDX .use(remarkInclude) .use(remarkGfm); export async function getLLMText(page: InferPageType | InferPageType) { try { // Remove the Fumadocs generated comment before processing let content = page.data.content; // Remove the specific Fumadocs comment that appears in generated API docs content = content.replace( /\{\s*\/\*\s*This file was generated by Fumadocs\. Do not edit this file directly\. Any changes should be made by running the generation command again\.\s*\*\/\s*\}/g, '' ); const processed = await processor.process({ path: page.data._file.absolutePath, value: content, }); return `# ${page.data.title} URL: ${page.url} Source: ${page.data._file.absolutePath} ${page.data.description || ''} ${processed.value}`; } catch (error) { console.error('Error processing LLM text for page:', page.url, error); // Return a basic fallback content instead of throwing return `# ${page.data.title} URL: ${page.url} Source: ${page.data._file.absolutePath} ${page.data.description || ''} Error: Could not process content for this page.`; } }