computer-scienceangular-roadmapbackend-roadmapblockchain-roadmapdba-roadmapdeveloper-roadmapdevops-roadmapfrontend-roadmapgo-roadmaphactoberfestjava-roadmapjavascript-roadmapnodejs-roadmappython-roadmapqa-roadmapreact-roadmaproadmapstudy-planvue-roadmapweb3-roadmap
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.
95 lines
2.2 KiB
95 lines
2.2 KiB
import type { MarkdownFileType } from './file'; |
|
import { getRoadmapById, type RoadmapFileType } from './roadmap.ts'; |
|
|
|
export const projectDifficulties = [ |
|
'beginner', |
|
'intermediate', |
|
'advanced', |
|
] as const; |
|
export type ProjectDifficultyType = (typeof projectDifficulties)[number]; |
|
|
|
export interface ProjectFrontmatter { |
|
title: string; |
|
description: string; |
|
isNew: boolean; |
|
sort: number; |
|
difficulty: ProjectDifficultyType; |
|
nature: string; |
|
skills: string[]; |
|
seo: { |
|
title: string; |
|
description: string; |
|
keywords: string[]; |
|
ogImageUrl: string; |
|
}; |
|
roadmapIds: string[]; |
|
} |
|
|
|
export type ProjectFileType = MarkdownFileType<ProjectFrontmatter> & { |
|
id: string; |
|
roadmaps: RoadmapFileType[]; |
|
}; |
|
|
|
/** |
|
* Generates id from the given project file |
|
* @param filePath Markdown file path |
|
* |
|
* @returns unique project identifier |
|
*/ |
|
function projectPathToId(filePath: string): string { |
|
const fileName = filePath.split('/').pop() || ''; |
|
|
|
return fileName.replace('.md', ''); |
|
} |
|
|
|
export async function getProjectsByRoadmapId( |
|
roadmapId: string, |
|
): Promise<ProjectFileType[]> { |
|
const projects = await getAllProjects(); |
|
|
|
return projects.filter((project) => |
|
project.frontmatter?.roadmapIds?.includes(roadmapId), |
|
); |
|
} |
|
|
|
let tempProjects: ProjectFileType[] = []; |
|
|
|
/** |
|
* Gets all the projects sorted by the publishing date |
|
* @returns Promisifed project files |
|
*/ |
|
export async function getAllProjects(): Promise<ProjectFileType[]> { |
|
if (tempProjects.length) { |
|
return tempProjects; |
|
} |
|
|
|
const projects = import.meta.glob<ProjectFileType>( |
|
'/src/data/projects/*.md', |
|
{ |
|
eager: true, |
|
}, |
|
); |
|
|
|
tempProjects = Object.values(projects).map((projectFile) => ({ |
|
...projectFile, |
|
id: projectPathToId(projectFile.file), |
|
})); |
|
|
|
return tempProjects; |
|
} |
|
|
|
export async function getProjectById( |
|
groupId: string, |
|
): Promise<ProjectFileType> { |
|
const project = await import(`../data/projects/${groupId}.md`); |
|
const roadmapIds = project.frontmatter.roadmapIds || []; |
|
const roadmaps = await Promise.all( |
|
roadmapIds.map((roadmapId: string) => getRoadmapById(roadmapId)), |
|
); |
|
|
|
return { |
|
...project, |
|
roadmaps: roadmaps, |
|
id: projectPathToId(project.file), |
|
}; |
|
}
|
|
|