1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-02-24 11:33:09 +01:00

122 lines
3.4 KiB
TypeScript
Raw Normal View History

2021-09-04 19:14:02 +02:00
import { Box, Button, Container, Link, Stack } from '@chakra-ui/react';
2021-09-05 22:52:18 +02:00
import { ArrowBackIcon, AtSignIcon, DownloadIcon } from '@chakra-ui/icons';
import { GlobalHeader } from '../../components/global-header';
import { OpensourceBanner } from '../../components/opensource-banner';
import { UpdatesBanner } from '../../components/updates-banner';
import { Footer } from '../../components/footer';
import { PageHeader } from '../../components/page-header';
import { getAllRoadmaps, getRoadmapById, RoadmapType } from '../../lib/roadmap';
import MdRenderer from '../../components/md-renderer';
import Helmet from '../../components/helmet';
2021-08-16 18:15:54 +02:00
2021-08-29 21:29:14 +02:00
type RoadmapProps = {
roadmap: RoadmapType;
};
2021-08-16 18:15:54 +02:00
2021-12-02 17:46:27 +01:00
function RoadmapResources(props: RoadmapProps) {
2021-08-29 21:29:14 +02:00
const { roadmap } = props;
2021-09-05 22:52:18 +02:00
if (!roadmap.resourcesPath) {
2021-08-29 21:29:14 +02:00
return null;
2021-08-16 18:15:54 +02:00
}
2021-08-19 14:36:08 +02:00
2021-08-29 21:29:14 +02:00
// Remove trailing slashes
2021-09-05 22:52:18 +02:00
const normalizedPath = roadmap.resourcesPath.replace(/^\//, '');
const RoadmapContent = require(`../../content/${normalizedPath}`).default;
2021-08-29 21:29:14 +02:00
return (
<Container maxW={'container.md'} position='relative'>
<MdRenderer>
<RoadmapContent />
</MdRenderer>
</Container>
);
}
2021-08-16 18:15:54 +02:00
2021-08-29 21:29:14 +02:00
export default function Roadmap(props: RoadmapProps) {
const { roadmap } = props;
2021-08-19 14:36:08 +02:00
2021-08-16 18:15:54 +02:00
return (
<Box bg='white' minH='100vh'>
2021-08-20 17:06:26 +02:00
<GlobalHeader />
2021-09-04 22:58:58 +02:00
<Helmet
title={roadmap?.seo?.title || roadmap.title}
description={roadmap?.seo?.description || roadmap.description}
keywords={roadmap?.seo.keywords || []}
/>
2021-08-16 18:15:54 +02:00
<Box mb='60px'>
<PageHeader
2021-09-04 19:14:02 +02:00
title={roadmap.title}
subtitle={roadmap.description}
2021-08-16 18:15:54 +02:00
>
<Stack mt='20px' isInline>
2021-09-05 21:17:51 +02:00
<Button d={['none', 'flex']} as={Link} href={'/roadmaps'} size='xs' py='14px' px='10px'
leftIcon={<ArrowBackIcon />}
colorScheme='teal' variant='solid' _hover={{ textDecoration: 'none' }}>
All Roadmaps
</Button>
2021-09-04 19:14:02 +02:00
{roadmap.pdfUrl && (
<Button as={Link}
href={roadmap.pdfUrl}
target='_blank'
size='xs'
py='14px'
px='10px'
leftIcon={<DownloadIcon />}
colorScheme='yellow'
variant='solid'
_hover={{ textDecoration: 'none' }}>
Download PDF
</Button>
)}
2021-09-05 21:17:51 +02:00
<Button as={Link} href={'/signup'} size='xs' py='14px' px='10px' leftIcon={<AtSignIcon />}
2021-09-04 19:14:02 +02:00
colorScheme='yellow' variant='solid' _hover={{ textDecoration: 'none' }}>
2021-08-16 18:15:54 +02:00
Subscribe
</Button>
</Stack>
</PageHeader>
2021-08-29 21:29:14 +02:00
2021-12-02 17:46:27 +01:00
<RoadmapResources roadmap={roadmap} />
2021-08-16 18:15:54 +02:00
</Box>
<OpensourceBanner />
<UpdatesBanner />
<Footer />
</Box>
);
}
2021-08-29 21:29:14 +02:00
type StaticPathItem = {
params: {
roadmap: string
}
};
export async function getStaticPaths() {
const roadmaps = getAllRoadmaps();
const paramsList: StaticPathItem[] = roadmaps.map(roadmap => ({
params: { 'roadmap': roadmap.id }
}));
return {
paths: paramsList,
fallback: false
};
}
type ContextType = {
params: {
roadmap: string
}
};
export async function getStaticProps(context: ContextType) {
const roadmapId: string = context?.params?.roadmap;
return {
props: {
roadmap: getRoadmapById(roadmapId)
}
};
}