(library: Library, pageName: string)
| 61 | } |
| 62 | |
| 63 | export async function resolvePageRef(library: Library, pageName: string): Promise<PageInfo> { |
| 64 | await buildPageIndex(library); |
| 65 | |
| 66 | if (pageCache.has(pageName)) { |
| 67 | return pageCache.get(pageName)!; |
| 68 | } |
| 69 | |
| 70 | const baseUrl = getLibraryBaseUrl(library); |
| 71 | |
| 72 | if (pageName.includes('/')) { |
| 73 | const normalized = pageName.replace(/\\/g, '/'); |
| 74 | const prefix = normalized.split('/', 1)[0]; |
| 75 | if (prefix !== library) { |
| 76 | throw new Error(`Page '${pageName}' is not in the '${library}' library.`); |
| 77 | } |
| 78 | const maybe = pageCache.get(normalized); |
| 79 | if (maybe) { |
| 80 | return maybe; |
| 81 | } |
| 82 | const filePath = `${baseUrl}/${normalized}.md`; |
| 83 | const stub: PageInfo = { |
| 84 | key: normalized, |
| 85 | name: path.basename(normalized), |
| 86 | description: undefined, |
| 87 | filePath, |
| 88 | sections: [] |
| 89 | }; |
| 90 | pageCache.set(stub.key, stub); |
| 91 | return stub; |
| 92 | } |
| 93 | |
| 94 | const key = `${library}/${pageName}`; |
| 95 | const maybe = pageCache.get(key); |
| 96 | if (maybe) { |
| 97 | return maybe; |
| 98 | } |
| 99 | const filePath = `${baseUrl}/${key}.md`; |
| 100 | const stub: PageInfo = {key, name: pageName, description: undefined, filePath, sections: []}; |
| 101 | pageCache.set(stub.key, stub); |
| 102 | return stub; |
| 103 | } |
no test coverage detected