MCPcopy
hub / github.com/colinhacks/zod / getLLMText

Function getLLMText

packages/docs/loaders/get-llm-text.ts:14–43  ·  view source on GitHub ↗
(page: InferPageType<typeof source>)

Source from the content-addressed store, hash-verified

12const processor = remark().use(remarkMdx).use(remarkInclude).use(remarkGfm).use(remarkStringify);
13
14export async function getLLMText(page: InferPageType<typeof source>): Promise<string> {
15 // Resolve file path relative to project root to handle ISR correctly
16 // During ISR on Vercel, absolutePath might not be correct, so we resolve it ourselves
17 // process.cwd() is already packages/docs during build/ISR
18 const relativePath = page.file.path;
19 const resolvedPath = path.join(process.cwd(), "content", relativePath);
20
21 // Try resolved path first, fallback to absolutePath if it doesn't exist
22 let filePath: string;
23 let fileContent: Buffer;
24 try {
25 filePath = resolvedPath;
26 fileContent = await fs.readFile(filePath);
27 } catch {
28 // If the resolved path doesn't work, try the absolutePath as fallback
29 filePath = page.data._file.absolutePath;
30 fileContent = await fs.readFile(filePath);
31 }
32
33 const { content } = matter(fileContent.toString());
34
35 const processed = await processor.process({
36 path: filePath,
37 value: content,
38 });
39
40 return `# ${page.data.title}
41
42${processed}`;
43}

Callers 2

GETFunction · 0.90
PageFunction · 0.90

Calls 2

toStringMethod · 0.80
processMethod · 0.80

Tested by

no test coverage detected