Skip to content

Commit 0f6037e

Browse files
committed
chore(dev-hub) fix
1 parent bf6a66b commit 0f6037e

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

apps/developer-hub/src/lib/get-llm-text.ts

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,50 @@ export async function getLLMText(page: Page) {
1414
// eslint-disable-next-line no-console
1515
console.error("🔥 getLLMText EXECUTED at", new Date().toISOString());
1616

17-
const cwd = process.cwd();
18-
const abs = page.absolutePath;
17+
// Resolve a readable MDX path in this Lambda:
18+
// 1) app-relative (when Vercel Root Directory is apps/developer-hub)
19+
// 2) repo-relative (monorepo root)
20+
// 3) absolutePath provided by Fumadocs (works locally)
1921
const pathArray: string[] = Array.isArray(page.path)
2022
? page.path
2123
: [page.path];
22-
const repoRel = path.join(
23-
cwd,
24+
const appRelTry = path.join(process.cwd(), "content", "docs", ...pathArray);
25+
const repoRelTry = path.join(
26+
process.cwd(),
2427
"apps",
2528
"developer-hub",
2629
"content",
2730
"docs",
2831
...pathArray,
2932
);
30-
const appRel = path.join(cwd, "content", "docs", ...pathArray);
33+
const absTry = page.absolutePath;
34+
35+
let mdxPath: string | undefined;
36+
if (existsSync(appRelTry)) {
37+
mdxPath = appRelTry;
38+
} else if (existsSync(repoRelTry)) {
39+
mdxPath = repoRelTry;
40+
} else if (absTry && existsSync(absTry)) {
41+
mdxPath = absTry;
42+
}
3143

3244
// eslint-disable-next-line no-console
33-
console.error("🧪[LLM] url=", page.url);
34-
// eslint-disable-next-line no-console
35-
console.error("🧪[LLM] cwd=", cwd);
36-
// eslint-disable-next-line no-console
37-
console.error("🧪[LLM] abs=", abs, "exists=", abs ? existsSync(abs) : false);
38-
// eslint-disable-next-line no-console
39-
console.error("🧪[LLM] repoRel=", repoRel, "exists=", existsSync(repoRel));
40-
// eslint-disable-next-line no-console
41-
console.error("🧪[LLM] appRel=", appRel, "exists=", existsSync(appRel));
45+
console.error("🧪[LLM] chosenPath=", mdxPath);
46+
47+
if (!mdxPath) {
48+
throw new Error(
49+
`MDX file not found at any known path:
50+
appRel=${appRelTry},
51+
repoRel=${repoRelTry},
52+
abs=${absTry}`,
53+
);
54+
}
4255

4356
// eslint-disable-next-line no-console
44-
console.error(`Getting LLM text for ${page.absolutePath}`);
57+
console.error(`Getting LLM text for ${mdxPath}`);
4558
const processed = await processor.process({
46-
path: page.absolutePath,
47-
value: await readFile(page.absolutePath, "utf8"),
59+
path: mdxPath,
60+
value: await readFile(mdxPath, "utf8"),
4861
});
4962

5063
return `# ${page.data.title ?? "Untitled"}

0 commit comments

Comments
 (0)