Skip to content

Commit

Permalink
fix(@dpc-sdp/ripple-tide-publication): fixed duplication side nav links
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdowdle committed Oct 6, 2023
1 parent 6676376 commit a08742e
Showing 1 changed file with 21 additions and 31 deletions.
52 changes: 21 additions & 31 deletions packages/ripple-tide-publication/utils/processMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

0 comments on commit a08742e

Please sign in to comment.