@@ -10,6 +10,7 @@ export type DocsGroup = {
1010 label : string ;
1111 items : {
1212 slug : string ;
13+ name : string ;
1314 body : string ;
1415 title : string ;
1516 description ?: string ;
@@ -28,30 +29,55 @@ export async function getGroupedDocs(): Promise<DocsGroup[]> {
2829
2930 const groups = [ ] ;
3031 for ( const { label, items : sidebarItems } of sidebarConfig ) {
31- const items = [ ] ;
32+ const group = { label , items : [ ] } ;
3233 for ( const sidebarItem of sidebarItems ) {
33- if (
34- typeof sidebarItem === 'object' &&
35- sidebarItem != null &&
36- 'slug' in sidebarItem
37- ) {
38- const doc = atlas . get ( sidebarItem . slug ) ;
39- if ( doc != null && doc . body != null ) {
40- items . push ( {
41- slug : doc . id ,
42- body : doc . body ,
43- title : doc . data . title ,
44- description : doc . data . description ,
45- } ) ;
46- } else {
47- console . warn ( `Warning: Could not find ${ sidebarItem . label } :` ) ;
34+ if ( typeof sidebarItem === 'object' && sidebarItem != null ) {
35+ if ( 'slug' in sidebarItem ) {
36+ // Handle normal pages, which have a "slug" attribute
37+ tryPushDoc ( group . items , sidebarItem . slug , sidebarItem . label ) ;
38+ continue ;
39+ } else if ( 'items' in sidebarItem && Array . isArray ( sidebarItem . items ) ) {
40+ // Handle API pages, which have an "items" array
41+ if ( sidebarItem . items . length > 0 ) {
42+ const item = sidebarItem . items [ 0 ] ;
43+ if ( typeof item === 'object' && item != null && 'link' in item ) {
44+ const hashIndex = item . link . lastIndexOf ( '#' ) ;
45+ if ( hashIndex !== - 1 ) {
46+ // Remove the leading slash and the URL hash
47+ tryPushDoc (
48+ group . items ,
49+ item . link . slice ( 1 , hashIndex ) ,
50+ sidebarItem . label ,
51+ ) ;
52+ continue ;
53+ }
54+ }
55+ }
4856 }
57+ console . warn (
58+ `Warning: Failed to identify sidebar style of ${ sidebarItem . label } :` ,
59+ ) ;
4960 }
5061 }
51- groups . push ( { label , items } ) ;
62+ groups . push ( group ) ;
5263 }
5364
5465 return groups ;
66+
67+ function tryPushDoc ( items : DocsGroup [ 'items' ] , slug : string , name ?: string ) {
68+ const doc = atlas . get ( slug ) ;
69+ if ( doc != null && doc . body != null ) {
70+ items . push ( {
71+ slug : doc . id ,
72+ name : name ?? doc . data . title ,
73+ body : doc . body ,
74+ title : doc . data . title ,
75+ description : doc . data . description ,
76+ } ) ;
77+ } else {
78+ console . warn ( `Warning: Could not find ${ slug } :` ) ;
79+ }
80+ }
5581}
5682
5783export const GET : APIRoute = async ( ) => {
0 commit comments