mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-08-28 19:49:50 +02:00
Add topics page
This commit is contained in:
2
scripts/migrate-content.sh
Normal file
2
scripts/migrate-content.sh
Normal file
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env bash
|
||||
|
@@ -24,7 +24,7 @@ import Loader from "./Loader.astro";
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div id='topic-content' class='-mt-2'></div>
|
||||
<div id='topic-content' class='prose prose-h1:mt-7 prose-h1:mb-1.5 prose-p:mt-0'></div>
|
||||
</div>
|
||||
<div class="bg-gray-900 bg-opacity-50 dark:bg-opacity-80 fixed inset-0 z-30"></div>
|
||||
</div>
|
||||
|
@@ -23,16 +23,49 @@ export interface RoadmapFrontmatter {
|
||||
changefreq: string;
|
||||
};
|
||||
tags: string[];
|
||||
};
|
||||
}
|
||||
|
||||
export async function getRoadmapIds() {
|
||||
const roadmapFiles = await import.meta.glob<string>('/src/roadmaps/*/*.md', {
|
||||
const roadmapFiles = await import.meta.glob<string>("/src/roadmaps/*/*.md", {
|
||||
eager: true,
|
||||
});
|
||||
|
||||
return Object.keys(roadmapFiles).map(filePath => {
|
||||
const fileName = filePath.split('/').pop() || '';
|
||||
return Object.keys(roadmapFiles).map((filePath) => {
|
||||
const fileName = filePath.split("/").pop() || "";
|
||||
|
||||
return fileName.replace('.md', '');
|
||||
return fileName.replace(".md", "");
|
||||
});
|
||||
}
|
||||
|
||||
export interface TopicFileType {
|
||||
frontMatter: Record<string, string>;
|
||||
file: string;
|
||||
url: string;
|
||||
Content: any;
|
||||
};
|
||||
|
||||
export async function getTopicPathMapping() {
|
||||
const contentFiles = await import.meta.glob<string>(
|
||||
"/src/roadmaps/*/content/**/*.md", {
|
||||
eager: true
|
||||
}
|
||||
);
|
||||
|
||||
const mapping: Record<string, TopicFileType> = {};
|
||||
|
||||
Object.keys(contentFiles).forEach((filePath) => {
|
||||
// => Sample Paths
|
||||
// /src/roadmaps/vue/content/102-ecosystem/102-ssr/101-nuxt-js.md
|
||||
// /src/roadmaps/vue/content/102-ecosystem/102-ssr/index.md
|
||||
const url = filePath
|
||||
.replace("/src/roadmaps/", "") // Remove the base `/src/roadmaps` from path
|
||||
.replace("/content", "") // Remove the `/[roadmapName]/content`
|
||||
.replace(/\/\d+-/g, "/") // Remove ordering info `/101-ecosystem`
|
||||
.replace(/\/index\.md$/, "") // Make the `/index.md` to become the parent folder only
|
||||
.replace(/\.md$/, ""); // Remove `.md` from the end of file
|
||||
|
||||
mapping[url] = contentFiles[filePath] as any;
|
||||
});
|
||||
|
||||
return mapping;
|
||||
}
|
||||
|
27
src/pages/[...topicId].astro
Normal file
27
src/pages/[...topicId].astro
Normal file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
import MarkdownContent from "../components/MarkdownContent/MarkdownContent.astro";
|
||||
import BaseLayout from "../layouts/BaseLayout.astro";
|
||||
import { getTopicPathMapping, TopicFileType } from "../lib/roadmap";
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const topicPathMapping = await getTopicPathMapping();
|
||||
|
||||
console.log(topicPathMapping);
|
||||
|
||||
return Object.keys(topicPathMapping).map((topicSlug) => ({
|
||||
params: { topicId: topicSlug },
|
||||
props: topicPathMapping[topicSlug],
|
||||
}));
|
||||
}
|
||||
|
||||
const { topicId } = Astro.params;
|
||||
const props: TopicFileType = Astro.props as any;
|
||||
---
|
||||
|
||||
<BaseLayout title="What is this">
|
||||
<MarkdownContent>
|
||||
<main id="main-content">
|
||||
<props.Content />
|
||||
</main>
|
||||
</MarkdownContent>
|
||||
</BaseLayout>
|
@@ -1,6 +1,6 @@
|
||||
---
|
||||
import InteractiveRoadamp from "../components/InteractiveRoadmap/InteractiveRoadmap.astro";
|
||||
import MarkdownRoadmap from "../components/MarkdownRoadmap/MarkdownRoadmap.astro";
|
||||
import MarkdownContent from "../components/MarkdownContent/MarkdownContent.astro";
|
||||
import RoadmapHeader from "../components/RoadmapHeader.astro";
|
||||
import BaseLayout from "../layouts/BaseLayout.astro";
|
||||
import { getRoadmapIds, RoadmapFrontmatter } from "../lib/roadmap";
|
||||
@@ -41,7 +41,7 @@ const frontmatter = file.frontmatter as RoadmapFrontmatter;
|
||||
)
|
||||
}
|
||||
|
||||
<MarkdownRoadmap>
|
||||
<MarkdownContent>
|
||||
<file.Content />
|
||||
</MarkdownRoadmap>
|
||||
</MarkdownContent>
|
||||
</BaseLayout>
|
||||
|
Reference in New Issue
Block a user