diff --git a/packages/ripple-tide-publication/utils/processMenu.ts b/packages/ripple-tide-publication/utils/processMenu.ts index 697da7d791..ced1940112 100644 --- a/packages/ripple-tide-publication/utils/processMenu.ts +++ b/packages/ripple-tide-publication/utils/processMenu.ts @@ -17,37 +17,27 @@ const parseChildren = (node: indexNode, route: RouteRecord): indexNode[] => { ) } -const transformNode = (node: indexNode, route: RouteRecord): indexNode[] => { - const parent: indexNode = { - text: node.text, - url: node.url, - id: node.id, - active: node.url === route.path, - items: undefined - } - - return [parent, ...parseChildren(node, route)] +const processMenu = (res: indexNode, route: RouteRecord): indexNode[] => { + return [ + { + text: res.text, + url: res.url, + id: res.id, + active: res.url === route.path, + items: undefined + }, + ...((res.items || []).map( + (child: indexNode): indexNode => ({ + text: child.text, + url: child.url, + id: child.id, + active: route.path.includes(child.url), + items: + // Group chapter together (child with its children) + child.items ? parseChildren(child, route) : undefined + }) + ) as any[]) + ] } -const processMenu = (res: indexNode, route: RouteRecord): indexNode[] => [ - { - text: res.text, - url: res.url, - id: res.id, - active: res.url === route.path, - items: undefined - }, - ...((res.items || []).map( - (child: indexNode): indexNode => ({ - text: child.text, - url: child.url, - id: child.id, - active: route.path.includes(child.url), - items: - // Group chapter together (child with its children) - child.items ? transformNode(child, route) : undefined - }) - ) as any[]) -] - export { type indexNode, processMenu }