Skip to content

Commit

Permalink
fix: collapsed=true (#5259)
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity authored Nov 23, 2024
1 parent bcc0a17 commit 6882b7a
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions packages/cli/docs-resolver/src/DocsDefinitionResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}

Expand Down

0 comments on commit 6882b7a

Please sign in to comment.