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.
 
 
 
 
 

81 lines
1.9 KiB

---
import fs from 'node:fs';
import path from 'node:path';
import matter from 'gray-matter';
import MarkdownIt from 'markdown-it-async';
import { fileURLToPath } from 'node:url';
export const prerender = false;
const { topicId, roadmapId } = Astro.params;
if (!topicId || !roadmapId) {
return Astro.redirect('/404');
}
// Handle nested paths by joining the segments
const topicPath = Array.isArray(topicId) ? topicId.join('/') : topicId;
// Get the project root directory
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const projectRoot = path.resolve(__dirname, '../../..');
// Construct the path to the markdown file
let contentPath = path.join(
projectRoot,
'src',
'data',
'roadmaps',
roadmapId,
'content',
`${topicPath}.md`,
);
console.log(contentPath);
// Check if file exists
if (!fs.existsSync(contentPath)) {
const indexFilePath = path.join(
projectRoot,
'src',
'data',
'roadmaps',
roadmapId,
'content',
`${topicPath}/index.md`,
);
if (!fs.existsSync(indexFilePath)) {
return Astro.redirect('/404');
}
contentPath = indexFilePath;
}
// Read and parse the markdown file
const fileContent = fs.readFileSync(contentPath, 'utf-8');
const { data: frontmatter, content } = matter(fileContent);
// Get the roadmap metadata
const roadmapPath = path.join(
projectRoot,
'src',
'data',
'roadmaps',
roadmapId,
`${roadmapId}.md`,
);
const roadmapContent = fs.readFileSync(roadmapPath, 'utf-8');
const { data: roadmapData } = matter(roadmapContent);
const fileWithoutBasePath = contentPath.replace(/.+?\/src\/data/, '/src/data');
const gitHubUrl = `https://github.com/kamranahmedse/developer-roadmap/tree/master${fileWithoutBasePath}`;
const md = MarkdownIt();
const htmlContent = await md.renderAsync(content);
---
<div data-github-url={gitHubUrl}></div>
<Fragment set:html={htmlContent} />