diff --git a/.changeset/real-trains-perform.md b/.changeset/real-trains-perform.md new file mode 100644 index 0000000000..d76b47a87a --- /dev/null +++ b/.changeset/real-trains-perform.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Fix page group not expanded by default diff --git a/packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx b/packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx index 4875633ac9..38879c41dd 100644 --- a/packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx +++ b/packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx @@ -1,4 +1,4 @@ -import { getPagePath, hasPageVisibleDescendant } from '@/lib/pages'; +import { getPagePaths, hasPageVisibleDescendant } from '@/lib/pages'; import { tcls } from '@/lib/tailwind'; import { type RevisionPage, @@ -27,7 +27,7 @@ export async function PageDocumentItem(props: {
  • pathname === currentPagePath); if (!descendants) { return ( @@ -37,7 +37,9 @@ export function ToggleableLinkItem( return ( currentPagePath.startsWith(`${pathname}/`)) + } > {({ descendants, toggler }) => ( <> diff --git a/packages/gitbook/src/lib/pages.ts b/packages/gitbook/src/lib/pages.ts index 49227f41ff..150800ca52 100644 --- a/packages/gitbook/src/lib/pages.ts +++ b/packages/gitbook/src/lib/pages.ts @@ -120,6 +120,20 @@ export function getPagePath( return page.path; } +/** + * Get all possible paths for a page. + */ +export function getPagePaths( + rootPages: Revision['pages'], + page: RevisionPageDocument | RevisionPageGroup +): string[] { + const path = getPagePath(rootPages, page); + if (path === page.path) { + return [path]; + } + return [path, page.path]; +} + /** * Test if a page has at least one descendant. */