@@ -44,8 +44,9 @@ interface PageInfo {
4444}
4545
4646// Section configuration - defines structure and ordering
47- const SECTIONS : Record < string , { order : number , hasSubcategories : boolean , rootPath ?: string } > = {
48- introduction : { order : 0 , hasSubcategories : false , rootPath : '/' } ,
47+ // rootPath: string = custom link, undefined = default to /${section}, null = no link
48+ const SECTIONS : Record < string , { order : number , hasSubcategories : boolean , rootPath ?: string | null } > = {
49+ introduction : { order : 0 , hasSubcategories : false , rootPath : null } ,
4950 guide : { order : 2 , hasSubcategories : true } ,
5051 components : { order : 4 , hasSubcategories : true } ,
5152 composables : { order : 6 , hasSubcategories : true } ,
@@ -131,6 +132,40 @@ function comparePages (a: PageInfo, b: PageInfo) {
131132 return a . name . localeCompare ( b . name )
132133}
133134
135+ async function buildApiSection ( ) : Promise < NavItemLink > {
136+ const apiNames = await getApiNamesGrouped ( )
137+
138+ // Group components by their folder (Avatar, Selection, etc.)
139+ const componentGroups = new Map < string , { name : string , slug : string } [ ] > ( )
140+ for ( const comp of apiNames . components ) {
141+ const group = comp . group || 'Other'
142+ if ( ! componentGroups . has ( group ) ) componentGroups . set ( group , [ ] )
143+ componentGroups . get ( group ) ! . push ( { name : comp . name , slug : comp . slug } )
144+ }
145+
146+ return {
147+ name : 'API' ,
148+ to : '/api' ,
149+ children : [
150+ {
151+ name : 'Components' ,
152+ children : Array . from ( componentGroups . entries ( ) )
153+ . toSorted ( ( a , b ) => a [ 0 ] . localeCompare ( b [ 0 ] ) )
154+ . flatMap ( ( [ , items ] ) =>
155+ items . toSorted ( ( a , b ) => a . name . localeCompare ( b . name ) )
156+ . map ( item => ( { name : item . name , to : `/api/${ item . slug } ` } ) ) ,
157+ ) ,
158+ } ,
159+ {
160+ name : 'Composables' ,
161+ children : apiNames . composables
162+ . toSorted ( ( a , b ) => a . name . localeCompare ( b . name ) )
163+ . map ( item => ( { name : item . name , to : `/api/${ item . slug } ` } ) ) ,
164+ } ,
165+ ] ,
166+ }
167+ }
168+
134169function createPageInfo ( relPath : string , file : string , name : string , frontmatter : Frontmatter ) : PageInfo {
135170 return {
136171 path : relPath ,
@@ -209,11 +244,10 @@ async function generateNav (): Promise<NavItem[]> {
209244 }
210245
211246 const sectionName = titleCase ( section )
212- const sectionItem : NavItemLink = {
213- name : sectionName ,
214- to : config . rootPath ?? `/${ section } ` ,
215- children : [ ] ,
216- }
247+ // Create NavItemCategory (no link) if rootPath is null, otherwise NavItemLink
248+ const sectionItem : NavItemLink | NavItemCategory = config . rootPath === null
249+ ? { name : sectionName , children : [ ] }
250+ : { name : sectionName , to : config . rootPath ?? `/${ section } ` , children : [ ] }
217251
218252 if ( config . hasSubcategories ) {
219253 // Group by subcategory
@@ -265,38 +299,7 @@ async function generateNav (): Promise<NavItem[]> {
265299 }
266300
267301 // Add API section
268- const apiNames = await getApiNamesGrouped ( )
269-
270- // Group components by their folder (Avatar, Selection, etc.)
271- const componentGroups = new Map < string , { name : string , slug : string } [ ] > ( )
272- for ( const comp of apiNames . components ) {
273- const group = comp . group || 'Other'
274- if ( ! componentGroups . has ( group ) ) componentGroups . set ( group , [ ] )
275- componentGroups . get ( group ) ! . push ( { name : comp . name , slug : comp . slug } )
276- }
277-
278- const apiSection : NavItemLink = {
279- name : 'API' ,
280- to : '/api' ,
281- children : [
282- {
283- name : 'Components' ,
284- children : Array . from ( componentGroups . entries ( ) )
285- . toSorted ( ( a , b ) => a [ 0 ] . localeCompare ( b [ 0 ] ) )
286- . flatMap ( ( [ , items ] ) =>
287- items . toSorted ( ( a , b ) => a . name . localeCompare ( b . name ) )
288- . map ( item => ( { name : item . name , to : `/api/${ item . slug } ` } ) ) ,
289- ) ,
290- } ,
291- {
292- name : 'Composables' ,
293- children : apiNames . composables
294- . toSorted ( ( a , b ) => a . name . localeCompare ( b . name ) )
295- . map ( item => ( { name : item . name , to : `/api/${ item . slug } ` } ) ) ,
296- } ,
297- ] ,
298- }
299-
302+ const apiSection = await buildApiSection ( )
300303 nav . push ( { divider : true } , apiSection )
301304
302305 return nav
0 commit comments