Fix table of content displaying arrow next to page with only hidden pages (#2825)

This commit is contained in:
Samy Pessé
2025-02-10 16:24:27 +01:00
committed by GitHub
parent d5aaccd2c4
commit 5576906914
4 changed files with 24 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'gitbook': patch
---
Fix table of content displaying arrow next to page with only hidden pages
@@ -6,7 +6,7 @@ import {
} from '@gitbook/api';
import { getPageHref } from '@/lib/links';
import { getPagePath } from '@/lib/pages';
import { getPagePath, hasPageVisibleDescendant } from '@/lib/pages';
import { ContentRefContext } from '@/lib/references';
import { tcls } from '@/lib/tailwind';
@@ -39,7 +39,7 @@ export async function PageDocumentItem(props: {
},
}}
descendants={
page.pages && page.pages.length ? (
hasPageVisibleDescendant(page) ? (
<PagesList
rootPages={rootPages}
pages={page.pages}
@@ -1,5 +1,6 @@
import { RevisionPage, RevisionPageDocument, RevisionPageGroup } from '@gitbook/api';
import { hasPageVisibleDescendant } from '@/lib/pages';
import { ContentRefContext } from '@/lib/references';
import { tcls } from '@/lib/tailwind';
@@ -47,7 +48,7 @@ export function PageGroupItem(props: {
<TOCPageIcon page={page} />
{page.title}
</div>
{page.pages && page.pages.length ? (
{hasPageVisibleDescendant(page) ? (
<PagesList
rootPages={rootPages}
pages={page.pages}
+15
View File
@@ -121,6 +121,21 @@ export function getPagePath(
return page.path;
}
/**
* Test if a page has at least one descendant.
*/
export function hasPageVisibleDescendant(page: RevisionPageGroup | RevisionPageDocument): boolean {
return (
page.pages.length > 0 &&
page.pages.some(
(child) =>
(child.type === RevisionPageType.Link ||
child.type === RevisionPageType.Document) &&
!child.hidden,
)
);
}
/**
* Resolve the first page document in a list of pages.
*/