Roadmap to becoming a developer in 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
813 B

import roadmaps from "storage/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
},
};
};