|
1
|
import { MenuItem, NavigationItem } from "types" |
|
2
|
import { navDropdownItems } from ".." |
|
3
|
|
|
4
|
type Options = { |
|
5
|
basePath: string |
|
6
|
} |
|
7
|
|
|
8
|
export function getNavDropdownItems({ basePath }: Options): NavigationItem[] { |
|
9
|
return navDropdownItems.map((item) => { |
|
10
|
const newItem = { |
|
11
|
...item, |
|
12
|
} |
|
13
|
|
|
14
|
if (newItem.link) { |
|
15
|
newItem.link = `${basePath}${newItem.link}` |
|
16
|
} |
|
17
|
|
|
18
|
if (newItem.type === "dropdown") { |
|
19
|
newItem.children = normalizeMenuItems({ |
|
20
|
basePath, |
|
21
|
items: newItem.children, |
|
22
|
}) |
|
23
|
} |
|
24
|
|
|
25
|
return newItem |
|
26
|
}) |
|
27
|
} |
|
28
|
|
|
29
|
export function normalizeMenuItems({ |
|
30
|
basePath, |
|
31
|
items, |
|
32
|
}: { |
|
33
|
basePath: string |
|
34
|
items: MenuItem[] |
|
35
|
}): MenuItem[] { |
|
36
|
return items.map((item) => { |
|
37
|
const newItem = { ...item } |
|
38
|
if (newItem.type !== "link" && newItem.type !== "sub-menu") { |
|
39
|
return newItem |
|
40
|
} |
|
41
|
|
|
42
|
if (newItem.link) { |
|
43
|
newItem.link = `${basePath}${newItem.link}` |
|
44
|
} |
|
45
|
|
|
46
|
if (newItem.type === "sub-menu") { |
|
47
|
newItem.items = normalizeMenuItems({ |
|
48
|
basePath, |
|
49
|
items: newItem.items, |
|
50
|
}) |
|
51
|
} |
|
52
|
|
|
53
|
return newItem |
|
54
|
}) |
|
55
|
} |