diff --git a/packages/cli/docs-resolver/src/DocsDefinitionResolver.ts b/packages/cli/docs-resolver/src/DocsDefinitionResolver.ts index 2eaae53ba25..b746fb5f25c 100644 --- a/packages/cli/docs-resolver/src/DocsDefinitionResolver.ts +++ b/packages/cli/docs-resolver/src/DocsDefinitionResolver.ts @@ -488,37 +488,38 @@ export class DocsDefinitionResolver { const children = await Promise.all(items.map((item) => this.toNavigationChild(id, item, parentSlug))); - const sidebarRootChildren: FernNavigation.V1.SidebarRootChild[] = []; + const grouped: FernNavigation.V1.SidebarRootChild[] = []; children.forEach((child) => { - switch (child.type) { - case "apiReference": - case "section": - sidebarRootChildren.push(child); - return; - case "changelog": - case "link": - case "page": { - let last = sidebarRootChildren[sidebarRootChildren.length - 1]; - if (last?.type !== "sidebarGroup") { - last = { - id: this.#idgen.get(`${id}/group`), - type: "sidebarGroup", - children: [] - }; - sidebarRootChildren.push(last); - } - last.children.push(child); - return; - } - default: - assertNever(child); + if (child.type === "apiReference") { + grouped.push(child); + return; + } + + if (child.type === "section" && !child.collapsed) { + grouped.push(child); + return; } + + const lastChild = grouped.length > 0 ? grouped[grouped.length - 1] : undefined; + let sidebarGroup: FernNavigation.V1.SidebarGroupNode; + if (lastChild?.type === "sidebarGroup") { + sidebarGroup = lastChild; + } else { + sidebarGroup = { + id: this.#idgen.get(`${id}/group`), + type: "sidebarGroup", + children: [] + }; + grouped.push(sidebarGroup); + } + + sidebarGroup.children.push(child); }); return { type: "sidebarRoot", id, - children: sidebarRootChildren + children: grouped }; }