-
Notifications
You must be signed in to change notification settings - Fork 14
/
pagesList.ts
81 lines (71 loc) · 2.58 KB
/
pagesList.ts
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { componentsList } from "./componentList";
type ComponentStatus = "Ready" | "Deprecated" | "Experimental";
export type LinkDetails = {
label: string;
path: string;
status: ComponentStatus;
};
export type LinksSectionDetails = {
label: string;
links: LinkDetails[];
};
type NavigationLinks = {
previousLink: LinkDetails | null;
nextLink: LinkDetails | null;
};
export const themeGeneratorLinks = [
"/theme-generator/opinionated-theme/",
"/theme-generator/advanced-theme/",
];
const overviewLinks: LinkDetails[] = [
{ label: "Introduction", path: "/overview/introduction", status: "Ready" },
{ label: "Releases", path: "/overview/releases", status: "Ready" },
];
const utilitiesLinks: LinkDetails[] = [
{
label: "Halstack Provider",
path: "/utilities/halstack-provider",
status: "Ready",
},
];
const principlesLinks: LinkDetails[] = [
{ label: "Color", path: "/principles/color", status: "Ready" },
{ label: "Layout", path: "/principles/layout", status: "Ready" },
{ label: "Localization", path: "/principles/localization", status: "Ready" },
{ label: "Spacing", path: "/principles/spacing", status: "Ready" },
{ label: "Themes", path: "/principles/themes", status: "Ready" },
{ label: "Typography", path: "/principles/typography", status: "Ready" },
];
const componentsLinks = componentsList as LinkDetails[];
export const LinksSections: LinksSectionDetails[] = [
{ label: "Overview", links: overviewLinks },
{ label: "Principles", links: principlesLinks },
{ label: "Utilities", links: utilitiesLinks },
{ label: "Components", links: componentsLinks },
];
const getCurrentLinkIndex = (links: LinkDetails[], currentPath: string) => {
let currentLinkIndex = -1;
let matchedWords = 0;
links.forEach((link, index) => {
if (currentPath.startsWith(link.path) && link.path.length > matchedWords) {
currentLinkIndex = index;
matchedWords = link.path.length;
}
});
return currentLinkIndex;
};
export const getNavigationLinks = (currentPath: string): NavigationLinks => {
const links = LinksSections.flatMap((section) => section.links);
const currentLinkIndex = getCurrentLinkIndex(links, currentPath);
if (currentLinkIndex === -1) {
return { previousLink: null, nextLink: null };
}
const nextLinkIndex = currentLinkIndex + 1;
const nextLinkExists = nextLinkIndex < links.length;
const previousLinkIndex = currentLinkIndex - 1;
const previousLinkExists = previousLinkIndex >= 0;
return {
previousLink: previousLinkExists ? links[previousLinkIndex] : null,
nextLink: nextLinkExists ? links[nextLinkIndex] : null,
};
};