forked from roadmapsh/deprecated-version
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroadmap.js
28 lines (25 loc) · 813 Bytes
/
roadmap.js
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
import roadmaps from "content/roadmaps";
export const getRequestedRoadmap = req => {
const normalizedUrl = req.url.replace(/\/$/, '');
const foundRoadmap = roadmaps.find(roadmap => normalizedUrl.startsWith(roadmap.url));
if (!foundRoadmap) {
return null;
}
const roadmapPages = Object.values(foundRoadmap.sidebar || {})
.reduce((acc, menuPages) => {
return [
...acc,
...menuPages
]
}, []);
const foundPage = roadmapPages.find(page => page.url === normalizedUrl) || {};
return {
...foundRoadmap,
// Use the current page data or that of the found roadmap i.e. show the summary
page: {
title: foundPage.title || foundRoadmap.title,
url: foundPage.url || foundRoadmap.url,
path: foundPage.path || foundRoadmap.path
},
};
};