Skip to content

Commit 6d56df7

Browse files
authored
Treat pages without visible TOC items as no-toc (#3783)
1 parent 4534ea8 commit 6d56df7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

.changeset/slow-boxes-go.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Treat pages without visible TOC items as `no-toc`

packages/gitbook/src/components/PageBody/PageBody.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ export function PageBody(props: {
4646
const language = getSpaceLanguage(context);
4747
const updatedAt = page.updatedAt ?? page.createdAt;
4848

49+
const hasVisibleTOCItems =
50+
context.revision.pages.filter(
51+
(page) => page.type !== 'document' || (page.type === 'document' && !page.hidden)
52+
).length > 0;
53+
4954
return (
5055
<CurrentPageProvider page={{ spaceId: context.space.id, pageId: page.id }}>
5156
<main
@@ -56,7 +61,9 @@ export function PageBody(props: {
5661
'break-anywhere',
5762
pageWidthWide ? 'page-width-wide 3xl:px-8' : 'page-width-default',
5863
siteWidthWide ? 'site-width-wide' : 'site-width-default',
59-
page.layout.tableOfContents ? 'page-has-toc' : 'page-no-toc'
64+
page.layout.tableOfContents && hasVisibleTOCItems
65+
? 'page-has-toc'
66+
: 'page-no-toc'
6067
)}
6168
>
6269
<PreservePageLayout siteWidthWide={siteWidthWide} />

0 commit comments

Comments
 (0)