Skip to content

Commit

Permalink
fix: collapsed=true
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Nov 22, 2024
1 parent df3f3fb commit 3c68fbd
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 3c68fbd

Please sign in to comment.