Skip to content

Commit 5256579

Browse files
committed
review
1 parent c04ce67 commit 5256579

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/gitbook/src/lib/context.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,9 @@ function parseSiteSectionsAndGroups(structure: SiteStructure, siteSectionId: str
437437
const sectionsAndGroups = getSiteStructureSections(structure);
438438
const visibleSectionsAndGroups = filterSectionsAndGroupsWithHiddenSiteSpaces(sectionsAndGroups);
439439
const section = parseCurrentSection(structure, siteSectionId);
440-
assert(section, `couldn't find section "${siteSectionId}" in site structure`);
441-
return { list: visibleSectionsAndGroups, current: section } satisfies SiteSections;
440+
const current = section && !sectionHasOnlyHiddenSiteSpaces(section) ? section : null;
441+
assert(current, `couldn't find section "${siteSectionId}" in site structure`);
442+
return { list: visibleSectionsAndGroups, current } satisfies SiteSections;
442443
}
443444

444445
function parseCurrentSection(structure: SiteStructure, siteSectionId: string) {
@@ -449,21 +450,25 @@ function parseCurrentSection(structure: SiteStructure, siteSectionId: string) {
449450
type SectionOrGroup = SiteSection | SiteSectionGroup;
450451

451452
/**
452-
* Filter out sections and groups with hidden site spaces.
453+
* Filter out sections where all site spaces are hidden and groups that become empty after filtering.
453454
*/
454455
function filterSectionsAndGroupsWithHiddenSiteSpaces(
455456
sectionsOrGroups: SectionOrGroup[]
456457
): SectionOrGroup[] {
457458
return sectionsOrGroups
458459
.map((entry) => {
459460
if (entry.object === 'site-section') {
460-
return sectionHasHiddenSiteSpace(entry) ? null : entry;
461+
return sectionHasOnlyHiddenSiteSpaces(entry) ? null : entry;
461462
}
462463

463464
const visibleChildren: SectionOrGroup[] = filterSectionsAndGroupsWithHiddenSiteSpaces(
464465
entry.children
465466
);
466467

468+
if (visibleChildren.length === 0) {
469+
return null;
470+
}
471+
467472
return {
468473
...entry,
469474
children: visibleChildren,
@@ -472,6 +477,6 @@ function filterSectionsAndGroupsWithHiddenSiteSpaces(
472477
.filter((entry): entry is SiteSection | SiteSectionGroup => Boolean(entry));
473478
}
474479

475-
function sectionHasHiddenSiteSpace(section: SiteSection) {
480+
function sectionHasOnlyHiddenSiteSpaces(section: SiteSection) {
476481
return section.siteSpaces.every((siteSpace) => siteSpace.hidden);
477482
}

0 commit comments

Comments
 (0)