@@ -16,7 +16,7 @@ import { type RenderTemplate, UrlMapping } from "../../models/UrlMapping";
16
16
import type { PageEvent } from "../../events" ;
17
17
import type { MarkedPlugin } from "../../plugins" ;
18
18
import { DefaultThemeRenderContext } from "./DefaultThemeRenderContext" ;
19
- import { JSX } from "../../../utils" ;
19
+ import { filterMap , JSX } from "../../../utils" ;
20
20
import { classNames , getDisplayName , getHierarchyRoots , toStyleClass } from "../lib" ;
21
21
import { icons } from "./partials/icon" ;
22
22
@@ -319,20 +319,29 @@ export class DefaultTheme extends Theme {
319
319
320
320
function toNavigation (
321
321
element : ReflectionCategory | ReflectionGroup | DeclarationReflection | DocumentReflection ,
322
- ) : NavigationElement {
322
+ ) : NavigationElement | undefined {
323
+ const children = getNavigationElements ( element ) ;
323
324
if ( element instanceof ReflectionCategory || element instanceof ReflectionGroup ) {
325
+ if ( ! children ?. length ) {
326
+ return ;
327
+ }
328
+
324
329
return {
325
330
text : element . title ,
326
- children : getNavigationElements ( element ) ,
331
+ children,
327
332
} ;
328
333
}
329
334
335
+ if ( ! element . hasOwnDocument ) {
336
+ return ;
337
+ }
338
+
330
339
return {
331
340
text : getDisplayName ( element ) ,
332
341
path : element . url ,
333
342
kind : element . kind ,
334
343
class : classNames ( { deprecated : element . isDeprecated ( ) } , theme . getReflectionClasses ( element ) ) ,
335
- children : getNavigationElements ( element ) ,
344
+ children : children ?. length ? children : undefined ,
336
345
} ;
337
346
}
338
347
@@ -345,14 +354,14 @@ export class DefaultTheme extends Theme {
345
354
| DocumentReflection ,
346
355
) : undefined | NavigationElement [ ] {
347
356
if ( parent instanceof ReflectionCategory ) {
348
- return parent . children . map ( toNavigation ) ;
357
+ return filterMap ( parent . children , toNavigation ) ;
349
358
}
350
359
351
360
if ( parent instanceof ReflectionGroup ) {
352
361
if ( shouldShowCategories ( parent . owningReflection , opts ) && parent . categories ) {
353
- return parent . categories . map ( toNavigation ) ;
362
+ return filterMap ( parent . categories , toNavigation ) ;
354
363
}
355
- return parent . children . map ( toNavigation ) ;
364
+ return filterMap ( parent . children , toNavigation ) ;
356
365
}
357
366
358
367
if ( leaves . includes ( parent . getFullName ( ) ) ) {
@@ -364,28 +373,28 @@ export class DefaultTheme extends Theme {
364
373
}
365
374
366
375
if ( parent . isDocument ( ) ) {
367
- return parent . children ?. map ( toNavigation ) ;
376
+ return filterMap ( parent . children , toNavigation ) ;
368
377
}
369
378
370
379
if ( ! parent . kindOf ( ReflectionKind . SomeModule | ReflectionKind . Project ) ) {
371
380
// Tricky: Non-module children don't show up in the navigation pane,
372
381
// but any documents added by them should.
373
- return parent . documents ?. map ( toNavigation ) ;
382
+ return filterMap ( parent . documents , toNavigation ) ;
374
383
}
375
384
376
385
if ( parent . categories && shouldShowCategories ( parent , opts ) ) {
377
- return parent . categories . map ( toNavigation ) ;
386
+ return filterMap ( parent . categories , toNavigation ) ;
378
387
}
379
388
380
389
if ( parent . groups && shouldShowGroups ( parent , opts ) ) {
381
- return parent . groups . map ( toNavigation ) ;
390
+ return filterMap ( parent . groups , toNavigation ) ;
382
391
}
383
392
384
393
if ( opts . includeFolders && parent . childrenIncludingDocuments ?. some ( ( child ) => child . name . includes ( "/" ) ) ) {
385
394
return deriveModuleFolders ( parent . childrenIncludingDocuments ) ;
386
395
}
387
396
388
- return parent . childrenIncludingDocuments ?. map ( toNavigation ) ;
397
+ return filterMap ( parent . childrenIncludingDocuments , toNavigation ) ;
389
398
}
390
399
391
400
function deriveModuleFolders ( children : Array < DeclarationReflection | DocumentReflection > ) {
@@ -414,12 +423,14 @@ export class DefaultTheme extends Theme {
414
423
415
424
// Note: This might end up putting a module within another module if we document
416
425
// both foo/index.ts and foo/bar.ts.
417
- for ( const child of children ) {
418
- const parts = child . name . split ( "/" ) ;
419
- const collection = resolveOrCreateParents ( parts ) ;
426
+ for ( const child of children . filter ( ( c ) => c . hasOwnDocument ) ) {
420
427
const nav = toNavigation ( child ) ;
421
- nav . text = parts [ parts . length - 1 ] ;
422
- collection . push ( nav ) ;
428
+ if ( nav ) {
429
+ const parts = child . name . split ( "/" ) ;
430
+ const collection = resolveOrCreateParents ( parts ) ;
431
+ nav . text = parts [ parts . length - 1 ] ;
432
+ collection . push ( nav ) ;
433
+ }
423
434
}
424
435
425
436
// Now merge single-possible-paths together so we don't have folders in our navigation
0 commit comments