Skip to content

Commit

Permalink
fix: when building factored SideNav menu, don't drop final children
Browse files Browse the repository at this point in the history
At the end of the loop, we need to append the remaining new children,
if there are any.
  • Loading branch information
dmosberger committed Dec 19, 2024
1 parent b5c5436 commit a86cf38
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/services/MenuBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ import type { ContentItemModel, TagGroup, TagInfo, TagsInfoMap } from './types';

export const GROUP_DEPTH = 0;

function appendChildren(parent: ContentItemModel, children: ContentItemModel[], prefix: string) {
for (const child of MenuBuilder.factorByPrefix(children)) {
if (child.sidebarLabel.startsWith(prefix)) {
child.sidebarLabel = '…' + child.sidebarLabel.slice(prefix.length - 1);
}
parent.items.push(child);
}
}

export class MenuBuilder {
/**
* Builds page content structure based on tags
Expand Down Expand Up @@ -46,12 +55,7 @@ export class MenuBuilder {
newChildren.push(item);
} else {
if (newChildren.length > 0) {
for (const child of MenuBuilder.factorByPrefix(newChildren)) {
if (child.sidebarLabel.startsWith(prefix)) {
child.sidebarLabel = '…' + child.sidebarLabel.slice(prefix.length - 1);
}
parent!.items.push(child);
}
appendChildren(parent!, newChildren, prefix);
newChildren = [];
}

Expand All @@ -62,6 +66,7 @@ export class MenuBuilder {
} else parent = null;
}
}
if (newChildren.length > 0) appendChildren(parent!, newChildren, prefix);
return newItems;
}

Expand Down

0 comments on commit a86cf38

Please sign in to comment.