Skip to content

Commit 8c13671

Browse files
committed
docs: index API sub-entries in search
1 parent b8f3b66 commit 8c13671

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

apps/docs/build/generate-search-index.ts

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { readFileSync } from 'node:fs'
1+
import { existsSync, readFileSync } from 'node:fs'
22
import { glob } from 'node:fs/promises'
33
import { basename, dirname, relative, resolve } from 'node:path'
44
import { fileURLToPath } from 'node:url'
55

66
// Types
7+
import type { ApiData } from './generate-api'
78
import type { Plugin, ViteDevServer } from 'vite'
89

910
import { getApiNamesGrouped, toKebab } from './api-names'
@@ -96,33 +97,88 @@ function getTitleFromPath (filePath: string): string {
9697
.join(' ')
9798
}
9899

100+
const API_CACHE_FILE = resolve(__dirname, '../node_modules/.cache/api-cache.json')
101+
102+
function loadApiData (): ApiData | null {
103+
if (!existsSync(API_CACHE_FILE)) return null
104+
try {
105+
return JSON.parse(readFileSync(API_CACHE_FILE, 'utf8')) as ApiData
106+
} catch {
107+
return null
108+
}
109+
}
110+
99111
async function generateApiSearchDocuments (startId: number): Promise<SearchDocument[]> {
100112
const documents: SearchDocument[] = []
101113
const apiNames = await getApiNamesGrouped()
114+
const apiData = loadApiData()
102115
let id = startId
103116

104117
// Add component API documents
105118
for (const comp of apiNames.components) {
119+
const apiPath = `/api/${toKebab(comp.name)}`
120+
106121
documents.push({
107122
id: String(id++),
108123
title: `${comp.name} API`,
109124
category: 'API',
110-
path: `/api/${toKebab(comp.name)}`,
125+
path: apiPath,
111126
headings: ['Props', 'Events', 'Slots'],
112127
content: `API reference for ${comp.name} component. Props, events, and slots documentation.`,
113128
})
129+
130+
// Add individual entries for each sub-component (e.g. Dialog.Root, Dialog.Content)
131+
if (apiData) {
132+
for (const [name, api] of Object.entries(apiData.components)) {
133+
if (!name.startsWith(`${comp.name}.`)) continue
134+
135+
documents.push({
136+
id: String(id++),
137+
title: `${name} API`,
138+
category: 'API',
139+
path: apiPath,
140+
headings: ['Props', 'Events', 'Slots'],
141+
content: [
142+
...api.props.map(p => p.name),
143+
...api.events.map(e => e.name),
144+
...api.slots.map(s => s.name),
145+
].join(' '),
146+
})
147+
}
148+
}
114149
}
115150

116151
// Add composable API documents
117152
for (const comp of apiNames.composables) {
153+
const apiPath = `/api/${toKebab(comp.name)}`
154+
118155
documents.push({
119156
id: String(id++),
120157
title: `${comp.name} API`,
121158
category: 'API',
122-
path: `/api/${toKebab(comp.name)}`,
159+
path: apiPath,
123160
headings: ['Options', 'Properties', 'Methods'],
124161
content: `API reference for ${comp.name} composable. Options, properties, and methods documentation.`,
125162
})
163+
164+
// Add individual entries for each exported function (e.g. createTimelineContext → createTimeline API)
165+
if (apiData) {
166+
const api = apiData.composables[comp.name]
167+
if (api) {
168+
for (const fn of api.functions) {
169+
if (fn.name === comp.name) continue
170+
171+
documents.push({
172+
id: String(id++),
173+
title: `${fn.name} API`,
174+
category: 'API',
175+
path: apiPath,
176+
headings: ['Options', 'Properties', 'Methods'],
177+
content: fn.description ?? '',
178+
})
179+
}
180+
}
181+
}
126182
}
127183

128184
return documents

0 commit comments

Comments
 (0)