Treat pages without visible TOC items as no-toc (#3783)

This commit is contained in:
Zeno Kapitein
2025-11-05 08:40:15 +01:00
committed by GitHub
parent 4534ea83c3
commit 6d56df7c10
2 changed files with 13 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"gitbook": patch
---
Treat pages without visible TOC items as `no-toc`
@@ -46,6 +46,11 @@ export function PageBody(props: {
const language = getSpaceLanguage(context);
const updatedAt = page.updatedAt ?? page.createdAt;
const hasVisibleTOCItems =
context.revision.pages.filter(
(page) => page.type !== 'document' || (page.type === 'document' && !page.hidden)
).length > 0;
return (
<CurrentPageProvider page={{ spaceId: context.space.id, pageId: page.id }}>
<main
@@ -56,7 +61,9 @@ export function PageBody(props: {
'break-anywhere',
pageWidthWide ? 'page-width-wide 3xl:px-8' : 'page-width-default',
siteWidthWide ? 'site-width-wide' : 'site-width-default',
page.layout.tableOfContents ? 'page-has-toc' : 'page-no-toc'
page.layout.tableOfContents && hasVisibleTOCItems
? 'page-has-toc'
: 'page-no-toc'
)}
>
<PreservePageLayout siteWidthWide={siteWidthWide} />