mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-02-24 19:42:51 +01:00
29 lines
813 B
JavaScript
29 lines
813 B
JavaScript
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
|
|
},
|
|
};
|
|
};
|