1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
export function normalizeDocPath(docPath) {
let p = String(docPath || "").trim();
p = p.replaceAll("\\", "/");
p = p.replace(/^\/+/, "");
p = p.replace(/\.\.\//g, "");
if (p === "" || p.endsWith("/")) p += "index";
if (!p.endsWith(".md")) p += ".md";
return p;
}
// Published docs live under /docs/ (llms.txt links them there), but doc paths
// are relative to that directory.
export function docPathFromPathname(pathname) {
const path = String(pathname || "")
.replace(/^\/+/, "")
.replace(/^docs(\/|$)/, "");
return normalizeDocPath(path);
}