MCPcopy Index your code
hub / github.com/adobe/react-spectrum / buildPageIndex

Function buildPageIndex

packages/dev/mcp/shared/src/page-manager.ts:13–47  ·  view source on GitHub ↗
(library: Library)

Source from the content-addressed store, hash-verified

11
12// Build an index of pages for the given library from the CDN's llms.txt.
13export async function buildPageIndex(library: Library): Promise<PageInfo[]> {
14 if (pageIndexLoaded.has(library)) {
15 return Array.from(pageCache.values()).filter(p => p.key.startsWith(`${library}/`));
16 }
17
18 const pages: PageInfo[] = [];
19
20 // Read llms.txt to enumerate available pages without downloading them all.
21 const baseUrl = getLibraryBaseUrl(library);
22 const llmsUrl = `${baseUrl}/llms.txt`;
23 const txt = await fetchText(llmsUrl);
24 const re = /^\s*-\s*\[([^\]]+)\]\(([^)]+)\)(?:\s*:\s*(.*))?\s*$/;
25 for (const line of txt.split(/\r?\n/)) {
26 const m = line.match(re);
27 if (!m) {
28 continue;
29 }
30 const display = (m[1] || '').trim();
31 const href = (m[2] || '').trim();
32 const description = (m[3] || '').trim() || undefined;
33 if (!href || !/\.md$/i.test(href)) {
34 continue;
35 }
36 const hrefWithoutExt = href.replace(/\.md$/i, '').replace(/\\/g, '/');
37 const key = `${library}/${hrefWithoutExt}`;
38 const name = display || path.basename(hrefWithoutExt);
39 const filePath = `${baseUrl}/${hrefWithoutExt}.md`;
40 const info: PageInfo = {key, name, description, filePath, sections: []};
41 pages.push(info);
42 pageCache.set(info.key, info);
43 }
44
45 pageIndexLoaded.add(library);
46 return pages.sort((a, b) => a.key.localeCompare(b.key));
47}
48
49export async function ensureParsedPage(info: PageInfo): Promise<PageInfo> {
50 if (info.sections && info.sections.length > 0 && info.description !== undefined) {

Callers 2

resolvePageRefFunction · 0.85
registerLibraryDocsToolsFunction · 0.85

Calls 8

getLibraryBaseUrlFunction · 0.85
fetchTextFunction · 0.85
pushMethod · 0.80
hasMethod · 0.65
filterMethod · 0.65
addMethod · 0.65
sortMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected