parent
0d62847053
commit
3fef4cad05
23 changed files with 384 additions and 685 deletions
@ -1 +1,2 @@ |
||||
/// <reference types="astro/client" />
|
||||
/// <reference path="content.d.ts" />
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,7 @@ |
||||
import type { APIRoute } from 'astro'; |
||||
|
||||
export const prerender = true; |
||||
|
||||
export async function getStaticPaths() { |
||||
const roadmapJsons = import.meta.glob('/src/data/roadmaps/**/*.json', { |
||||
eager: true, |
@ -1,37 +1,59 @@ |
||||
--- |
||||
import { |
||||
getRoadmapTopicFiles, |
||||
type RoadmapTopicFileType, |
||||
} from '../../lib/roadmap-topic'; |
||||
|
||||
export async function getStaticPaths() { |
||||
const topicPathMapping = await getRoadmapTopicFiles(); |
||||
|
||||
return Object.keys(topicPathMapping).map((topicSlug) => { |
||||
const topicDetails = topicPathMapping[topicSlug]; |
||||
const roadmapId = topicDetails.roadmapId; |
||||
const topicId = topicSlug.replace(`/${roadmapId}/`, ''); |
||||
|
||||
return { |
||||
params: { |
||||
topicId, |
||||
roadmapId, |
||||
}, |
||||
props: topicDetails, |
||||
}; |
||||
}); |
||||
} |
||||
import fs from 'node:fs'; |
||||
import path from 'node:path'; |
||||
import matter from 'gray-matter'; |
||||
import MarkdownIt from 'markdown-it'; |
||||
|
||||
export const prerender = false; |
||||
|
||||
const { topicId, roadmapId } = Astro.params; |
||||
|
||||
export const partial = true; |
||||
if (!topicId || !roadmapId) { |
||||
return Astro.redirect('/404'); |
||||
} |
||||
|
||||
const { topicId } = Astro.params; |
||||
const { file, url, roadmapId, roadmap, heading } = |
||||
Astro.props as RoadmapTopicFileType; |
||||
// Handle nested paths by joining the segments |
||||
const topicPath = Array.isArray(topicId) ? topicId.join('/') : topicId; |
||||
|
||||
// Construct the path to the markdown file |
||||
const contentPath = path.join( |
||||
process.cwd(), |
||||
'src', |
||||
'data', |
||||
'roadmaps', |
||||
roadmapId, |
||||
'content', |
||||
`${topicPath}.md`, |
||||
); |
||||
|
||||
// Check if file exists |
||||
if (!fs.existsSync(contentPath)) { |
||||
return Astro.redirect('/404'); |
||||
} |
||||
|
||||
const fileWithoutBasePath = file.file?.replace(/.+?\/src\/data/, '/src/data'); |
||||
// 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( |
||||
process.cwd(), |
||||
'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 = new MarkdownIt(); |
||||
const htmlContent = md.render(content); |
||||
--- |
||||
|
||||
<div data-github-url={gitHubUrl}></div> |
||||
|
||||
<file.Content /> |
||||
<Fragment set:html={htmlContent} /> |
||||
|
Loading…
Reference in new issue