mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-22 18:43:29 +00:00
Fix table of content displaying arrow next to page with only hidden pages (#2825)
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user