diff --git a/src/components/GridRoadmapItem.astro b/src/components/GridRoadmapItem.astro index fe2cb6d2c..d7ffb1542 100644 --- a/src/components/GridRoadmapItem.astro +++ b/src/components/GridRoadmapItem.astro @@ -1,11 +1,12 @@ --- -import type { RoadmapFrontmatter } from '../lib/roadmap'; +import type { RoadmapFileType } from '../lib/roadmap'; export interface Props { - roadmap: RoadmapFrontmatter; + roadmap: RoadmapFileType; } const { roadmap } = Astro.props; +const frontmatter = roadmap.frontmatter; --- {roadmap.title}{frontmatter.title} {frontmatter.description} { - roadmap.isNew && ( + frontmatter.isNew && ( New diff --git a/src/lib/File.ts b/src/lib/File.ts index 2b111a240..47da512c7 100644 --- a/src/lib/File.ts +++ b/src/lib/File.ts @@ -1,7 +1,7 @@ export interface MarkdownFileType> { frontmatter: T; file: string; - url: string; + url?: string; Content: any; getHeadings: () => { depth: number; diff --git a/src/lib/roadmap.ts b/src/lib/roadmap.ts index 27ad0f8f5..d3da51030 100644 --- a/src/lib/roadmap.ts +++ b/src/lib/roadmap.ts @@ -1,9 +1,10 @@ import type { MarkdownFileType } from "./File"; -type RoadmapFileType = MarkdownFileType; +export type RoadmapFileType = MarkdownFileType & { + id: string; +}; export interface RoadmapFrontmatter { - id: string; jsonUrl: string; pdfUrl: string; order: number; @@ -30,6 +31,12 @@ export interface RoadmapFrontmatter { tags: string[]; } +function roadmapPathToId(filePath: string):string { + const fileName = filePath.split("/").pop() || ""; + + return fileName.replace(".md", ""); +} + /** * Gets the IDs of all the roadmaps available on the website * @@ -40,11 +47,7 @@ export async function getRoadmapIds() { eager: true, }); - return Object.keys(roadmapFiles).map((filePath) => { - const fileName = filePath.split("/").pop() || ""; - - return fileName.replace(".md", ""); - }); + return Object.keys(roadmapFiles).map(roadmapPathToId); } /** @@ -61,8 +64,13 @@ export async function getRoadmapsByTag(tag: string): Promise } ); - const roadmapFiles: MarkdownFileType[] = Object.values(roadmapFilesMap); - const filteredRoadmaps = roadmapFiles.filter(roadmapFile => roadmapFile.frontmatter.tags.includes(tag)); + const roadmapFiles = Object.values(roadmapFilesMap); + const filteredRoadmaps = roadmapFiles + .filter((roadmapFile) => roadmapFile.frontmatter.tags.includes(tag)) + .map((roadmapFile) => ({ + ...roadmapFile, + id: roadmapPathToId(roadmapFile.file), + })); return filteredRoadmaps.sort( (a, b) => a.frontmatter.order - b.frontmatter.order diff --git a/src/pages/roadmaps.astro b/src/pages/roadmaps.astro index e48ac8cd0..8828a3ba3 100644 --- a/src/pages/roadmaps.astro +++ b/src/pages/roadmaps.astro @@ -20,13 +20,13 @@ const skillRoadmaps = await getRoadmapsByTag('skill-roadmap');
{ roleRoadmaps.map((roleRoadmap) => ( - + )) } { skillRoadmaps.map((skillRoadmap) => ( - + )) }