parent
8f6ead0add
commit
9f98b30568
14 changed files with 165 additions and 58 deletions
@ -0,0 +1,26 @@ |
|||||||
|
import roadmaps from "../data/roadmaps"; |
||||||
|
|
||||||
|
export const getRequestedRoadmap = req => { |
||||||
|
// Considering it a new roadmap URL e.g. `/roadmaps/frontend`
|
||||||
|
const currentUrl = req.url.replace(/\/$/, ''); |
||||||
|
// Considering it a legacy URL e.g. converting `/frontend` to `roadmap.sh/roadmaps/frontend`
|
||||||
|
const legacyUrl = `/roadmaps${currentUrl}`; |
||||||
|
// 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 slugs in roadmaps list don't have versions
|
||||||
|
const newUrlWithoutVersion = currentUrl.replace(foundVersionRegex, ''); |
||||||
|
const legacyUrlWithoutVersion = legacyUrl.replace(foundVersionRegex, ''); |
||||||
|
|
||||||
|
const urlToSlugList = [ |
||||||
|
currentUrl, |
||||||
|
legacyUrl, |
||||||
|
newUrlWithoutVersion, |
||||||
|
legacyUrlWithoutVersion, |
||||||
|
]; |
||||||
|
|
||||||
|
return { |
||||||
|
...roadmaps.find(roadmap => urlToSlugList.includes(roadmap.slug)), |
||||||
|
version: foundVersion, |
||||||
|
}; |
||||||
|
}; |
@ -1,21 +0,0 @@ |
|||||||
import Roadmap from './roadmaps/[roadmap]'; |
|
||||||
import roadmapsList from "../data/roadmaps.json"; |
|
||||||
import { serverOnlyProps } from '../lib/server'; |
|
||||||
|
|
||||||
// Fallback page to handle the old roadmap pages implementation
|
|
||||||
const OldRoadmap = ({ roadmap }) => { |
|
||||||
if (roadmap) { |
|
||||||
return <Roadmap roadmap={ roadmap } /> |
|
||||||
} |
|
||||||
|
|
||||||
return <h1>404</h1> |
|
||||||
}; |
|
||||||
|
|
||||||
OldRoadmap.getInitialProps = serverOnlyProps(({ req }) => { |
|
||||||
return { |
|
||||||
roadmap: roadmapsList.find(roadmap => roadmap.slug === req.url), |
|
||||||
}; |
|
||||||
}); |
|
||||||
|
|
||||||
|
|
||||||
export default OldRoadmap; |
|
@ -0,0 +1,3 @@ |
|||||||
|
import OldRoadmap from './index'; |
||||||
|
|
||||||
|
export default OldRoadmap; |
@ -0,0 +1,22 @@ |
|||||||
|
import Error from 'next/error'; |
||||||
|
import Roadmap from '../roadmaps/[roadmap]/index'; |
||||||
|
import { serverOnlyProps } from '../../lib/server'; |
||||||
|
import { getRequestedRoadmap } from '../../lib/roadmap'; |
||||||
|
|
||||||
|
// Fallback page to handle the old roadmap pages implementation
|
||||||
|
const OldRoadmap = ({ roadmap }) => { |
||||||
|
if (roadmap) { |
||||||
|
return <Roadmap roadmap={ roadmap } /> |
||||||
|
} |
||||||
|
|
||||||
|
return <Error status={ 404 } />; |
||||||
|
}; |
||||||
|
|
||||||
|
OldRoadmap.getInitialProps = serverOnlyProps(({ req }) => { |
||||||
|
return { |
||||||
|
roadmap: getRequestedRoadmap(req), |
||||||
|
}; |
||||||
|
}); |
||||||
|
|
||||||
|
|
||||||
|
export default OldRoadmap; |
@ -1,25 +0,0 @@ |
|||||||
import roadmaps from "../../data/roadmaps"; |
|
||||||
import DefaultLayout from '../../layouts/default/index'; |
|
||||||
import PageHeader from '../../components/page-header/index'; |
|
||||||
import { serverOnlyProps } from '../../lib/server'; |
|
||||||
import RoadmapSummary from '../../components/roadmap-summary'; |
|
||||||
import PageFooter from '../../components/page-footer'; |
|
||||||
|
|
||||||
const Roadmap = ({ roadmap }) => { |
|
||||||
return ( |
|
||||||
<DefaultLayout> |
|
||||||
<PageHeader /> |
|
||||||
<RoadmapSummary roadmap={ roadmap } /> |
|
||||||
<PageFooter /> |
|
||||||
</DefaultLayout> |
|
||||||
); |
|
||||||
}; |
|
||||||
|
|
||||||
Roadmap.getInitialProps = serverOnlyProps(({ req }) => { |
|
||||||
const normalizedUrl = req.url.replace('roadmaps/', ''); |
|
||||||
return { |
|
||||||
roadmap: roadmaps.find(roadmap => roadmap.slug === normalizedUrl), |
|
||||||
}; |
|
||||||
}); |
|
||||||
|
|
||||||
export default Roadmap; |
|
@ -0,0 +1,3 @@ |
|||||||
|
import Roadmap from './index'; |
||||||
|
|
||||||
|
export default Roadmap; |
@ -0,0 +1,24 @@ |
|||||||
|
import DefaultLayout from '../../../layouts/default'; |
||||||
|
import { serverOnlyProps } from '../../../lib/server'; |
||||||
|
import PageHeader from '../../../components/page-header'; |
||||||
|
import PageFooter from '../../../components/page-footer'; |
||||||
|
import { getRequestedRoadmap } from '../../../lib/roadmap'; |
||||||
|
import RoadmapSummary from '../../../components/roadmap-summary'; |
||||||
|
|
||||||
|
const Roadmap = ({ roadmap }) => { |
||||||
|
return ( |
||||||
|
<DefaultLayout> |
||||||
|
<PageHeader /> |
||||||
|
<RoadmapSummary roadmap={ roadmap } /> |
||||||
|
<PageFooter /> |
||||||
|
</DefaultLayout> |
||||||
|
); |
||||||
|
}; |
||||||
|
|
||||||
|
Roadmap.getInitialProps = serverOnlyProps(({ req }) => { |
||||||
|
return { |
||||||
|
roadmap: getRequestedRoadmap(req), |
||||||
|
}; |
||||||
|
}); |
||||||
|
|
||||||
|
export default Roadmap; |
Loading…
Reference in new issue