2020-01-18 22:47:48 +04:00
|
|
|
import roadmaps from "content/roadmaps";
|
2019-10-31 23:45:09 +04:00
|
|
|
|
|
|
|
export const getRequestedRoadmap = req => {
|
2019-12-01 15:01:22 +04:00
|
|
|
const normalizedUrl = req.url.replace(/\/$/, '');
|
|
|
|
const foundRoadmap = roadmaps.find(roadmap => normalizedUrl.startsWith(roadmap.url));
|
2019-11-01 02:27:06 +04:00
|
|
|
if (!foundRoadmap) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-10-31 23:49:30 +04:00
|
|
|
|
2019-12-01 15:01:22 +04:00
|
|
|
const roadmapPages = Object.values(foundRoadmap.sidebar || {})
|
|
|
|
.reduce((acc, menuPages) => {
|
|
|
|
return [
|
|
|
|
...acc,
|
|
|
|
...menuPages
|
|
|
|
]
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const foundPage = roadmapPages.find(page => page.url === normalizedUrl) || {};
|
2019-10-31 23:45:09 +04:00
|
|
|
return {
|
2019-10-31 23:49:30 +04:00
|
|
|
...foundRoadmap,
|
2019-12-01 15:01:22 +04:00
|
|
|
// 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
|
|
|
|
},
|
2019-10-31 23:45:09 +04:00
|
|
|
};
|
2019-11-06 18:20:09 +04:00
|
|
|
};
|