11import { getSectionURL , getSiteSpaceURL } from '@/lib/sites' ;
22import type { SiteSection , SiteSectionGroup , SiteSpace } from '@gitbook/api' ;
33import type { GitBookSiteContext , SiteSections } from '@v2/lib/context' ;
4+ import assertNever from 'assert-never' ;
45
56export type ClientSiteSections = {
67 list : ( ClientSiteSection | ClientSiteSectionGroup ) [ ] ;
@@ -27,20 +28,32 @@ export function encodeClientSiteSections(context: GitBookSiteContext, sections:
2728 const clientSections : ( ClientSiteSection | ClientSiteSectionGroup ) [ ] = [ ] ;
2829
2930 for ( const item of list ) {
30- if ( item . object === 'site-section-group' ) {
31- clientSections . push ( {
32- id : item . id ,
33- title : item . title ,
34- icon : item . icon ,
35- object : item . object ,
36- sections : item . sections
31+ switch ( item . object ) {
32+ case 'site-section-group' : {
33+ const sections = item . sections
3734 . filter ( ( section ) => shouldIncludeSection ( context , section ) )
38- . map ( ( section ) => encodeSection ( context , section ) ) ,
39- } ) ;
40- } else {
41- if ( shouldIncludeSection ( context , item ) ) {
35+ . map ( ( section ) => encodeSection ( context , section ) ) ;
36+
37+ // Skip empty groups
38+ if ( sections . length === 0 ) {
39+ continue ;
40+ }
41+
42+ clientSections . push ( {
43+ id : item . id ,
44+ title : item . title ,
45+ icon : item . icon ,
46+ object : item . object ,
47+ sections,
48+ } ) ;
49+ continue ;
50+ }
51+ case 'site-section' : {
4252 clientSections . push ( encodeSection ( context , item ) ) ;
53+ continue ;
4354 }
55+ default :
56+ assertNever ( item , 'Unknown site section object type' ) ;
4457 }
4558 }
4659
0 commit comments