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.
40 lines
1015 B
40 lines
1015 B
2 years ago
|
import type { MarkdownFileType } from './file';
|
||
|
|
||
|
export interface LinkGroupFrontmatter {
|
||
|
[key: string]: string;
|
||
|
}
|
||
|
|
||
|
export type LinkGroupFileType = MarkdownFileType<LinkGroupFrontmatter> & {
|
||
|
id: string;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Generates id from the given linkGroup file
|
||
|
* @param filePath Markdown file path
|
||
|
*
|
||
|
* @returns unique linkGroup identifier
|
||
|
*/
|
||
|
function linkGroupPathToId(filePath: string): string {
|
||
|
const fileName = filePath.split('/').pop() || '';
|
||
|
|
||
|
return fileName.replace('.md', '');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Gets all the linkGroups sorted by the publishing date
|
||
|
* @returns Promisifed linkGroup files
|
||
|
*/
|
||
|
export async function getAllLinkGroups(): Promise<LinkGroupFileType[]> {
|
||
|
const linkGroups = await import.meta.glob<LinkGroupFileType>('/src/link-groups/*.md', {
|
||
|
eager: true,
|
||
|
});
|
||
|
|
||
|
const linkGroupFiles = Object.values(linkGroups);
|
||
|
const enrichedLinkGroups = linkGroupFiles.map((linkGroupFile) => ({
|
||
|
...linkGroupFile,
|
||
|
id: linkGroupPathToId(linkGroupFile.file),
|
||
|
}));
|
||
|
|
||
|
return enrichedLinkGroups;
|
||
|
}
|