Relevant page loading on detail page
This commit is contained in:
@ -11,15 +11,19 @@ import siteConfig from "storage/site";
|
|||||||
|
|
||||||
const DetailedRoadmap = ({ roadmap }) => {
|
const DetailedRoadmap = ({ roadmap }) => {
|
||||||
const [menuActive, setMenuState] = useState(false);
|
const [menuActive, setMenuState] = useState(false);
|
||||||
|
const {
|
||||||
|
sidebar = {},
|
||||||
|
page: currentPage = {}
|
||||||
|
} = roadmap;
|
||||||
|
|
||||||
const roadmapPages = Object.keys(roadmap.sidebar || {}).map(groupTitle => {
|
const roadmapPages = Object.keys(sidebar || {}).map(groupTitle => {
|
||||||
return (
|
return (
|
||||||
<div className='links-group'>
|
<div className='links-group'>
|
||||||
<h3>{ groupTitle }</h3>
|
<h3>{ groupTitle }</h3>
|
||||||
<ul>
|
<ul>
|
||||||
{ roadmap.sidebar[groupTitle].map(page => {
|
{ sidebar[groupTitle].map(page => {
|
||||||
return (
|
return (
|
||||||
<li>
|
<li className={classNames({ active: page.url === currentPage.url })}>
|
||||||
<a href={ page.url }>
|
<a href={ page.url }>
|
||||||
<span className="bullet"></span>
|
<span className="bullet"></span>
|
||||||
{ page.title }
|
{ page.title }
|
||||||
@ -61,7 +65,7 @@ const DetailedRoadmap = ({ roadmap }) => {
|
|||||||
<div className="container">
|
<div className="container">
|
||||||
<SidebarButton onClick={() => setMenuState((prevMenuActive) => !prevMenuActive)}>
|
<SidebarButton onClick={() => setMenuState((prevMenuActive) => !prevMenuActive)}>
|
||||||
<FontAwesomeIcon icon={ faBars } />
|
<FontAwesomeIcon icon={ faBars } />
|
||||||
Getting Job Ready
|
{ currentPage.title }
|
||||||
</SidebarButton>
|
</SidebarButton>
|
||||||
</div>
|
</div>
|
||||||
<MobileSidebarWrap className={classNames({ visible: menuActive })}>
|
<MobileSidebarWrap className={classNames({ visible: menuActive })}>
|
||||||
|
@ -126,6 +126,14 @@ export const Sidebar = styled.div`
|
|||||||
transform: translateX(-4px);
|
transform: translateX(-4px);
|
||||||
transition: background 0.5s ease;
|
transition: background 0.5s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.active a {
|
||||||
|
color: #101010;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.active .bullet {
|
||||||
|
background: #101010;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
@ -1,27 +1,28 @@
|
|||||||
import roadmaps from "storage/roadmaps";
|
import roadmaps from "storage/roadmaps";
|
||||||
|
|
||||||
export const getRequestedRoadmap = req => {
|
export const getRequestedRoadmap = req => {
|
||||||
// Considering it a new roadmap URL e.g. `/roadmaps/frontend`
|
const normalizedUrl = req.url.replace(/\/$/, '');
|
||||||
const currentUrl = req.url.replace(/\/$/, '');
|
const foundRoadmap = roadmaps.find(roadmap => normalizedUrl.startsWith(roadmap.url));
|
||||||
// Get the roadmap version out of the URL e.g. `/roadmaps/frontend/2019`
|
|
||||||
const [foundVersion = ''] = currentUrl.match(/(\d+|latest)$/) || ['latest'];
|
|
||||||
const foundVersionRegex = new RegExp(`\/?${foundVersion}$`);
|
|
||||||
// Remove version from the URL because urls in roadmaps list don't have versions
|
|
||||||
const urlWithoutVersion = currentUrl.replace(foundVersionRegex, '');
|
|
||||||
|
|
||||||
const urlToSlugList = [
|
|
||||||
currentUrl,
|
|
||||||
urlWithoutVersion,
|
|
||||||
];
|
|
||||||
|
|
||||||
const foundRoadmap = roadmaps.find(roadmap => urlToSlugList.includes(roadmap.url));
|
|
||||||
if (!foundRoadmap) {
|
if (!foundRoadmap) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const roadmapPages = Object.values(foundRoadmap.sidebar || {})
|
||||||
|
.reduce((acc, menuPages) => {
|
||||||
|
return [
|
||||||
|
...acc,
|
||||||
|
...menuPages
|
||||||
|
]
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const foundPage = roadmapPages.find(page => page.url === normalizedUrl) || {};
|
||||||
return {
|
return {
|
||||||
...foundRoadmap,
|
...foundRoadmap,
|
||||||
version: foundVersion,
|
// Use the current page data or that of the found roadmap i.e. show the summary
|
||||||
picture: (foundRoadmap.picture || '').replace('{version}', foundVersion),
|
page: {
|
||||||
|
title: foundPage.title || foundRoadmap.title,
|
||||||
|
url: foundPage.url || foundRoadmap.url,
|
||||||
|
path: foundPage.path || foundRoadmap.path
|
||||||
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -6,7 +6,7 @@ import { serverOnlyProps } from 'lib/server';
|
|||||||
import { getRequestedRoadmap } from 'lib/roadmap';
|
import { getRequestedRoadmap } from 'lib/roadmap';
|
||||||
import Helmet from 'components/helmet';
|
import Helmet from 'components/helmet';
|
||||||
import RoadmapSummary from 'components/roadmap-summary';
|
import RoadmapSummary from 'components/roadmap-summary';
|
||||||
import DetailedRoadmap from '../../components/detailed-roadmap';
|
import DetailedRoadmap from 'components/detailed-roadmap';
|
||||||
|
|
||||||
const Roadmap = ({ roadmap }) => {
|
const Roadmap = ({ roadmap }) => {
|
||||||
if (!roadmap) {
|
if (!roadmap) {
|
||||||
|
Reference in New Issue
Block a user