-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathutils.js
More file actions
31 lines (26 loc) · 744 Bytes
/
utils.js
File metadata and controls
31 lines (26 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function uniquePath(path) {
const segments = path?.split("/").filter(Boolean);
for (let i = 0; i < segments.length; i++) {
if (segments.length === 2 && segments[i] === segments[i + 1]) {
return segments[0] + "/";
}
}
return path;
}
export function getValidPaths(items) {
return items?.flatMap((item) => {
const paths = [];
if (item?.label) {
if (item.label !== "Overview") {
const formattedTitle = `category/${item?.label.toLowerCase().replace(/\s+/g, "-")}`;
paths.push(formattedTitle);
}
}
if (item?.items) {
paths.push(...getValidPaths(item?.items));
} else if (typeof item === "string") {
paths.push(uniquePath(item));
}
return paths;
});
}