* Add empty projects listing and cards * Projects page header * Projects listing and filtering * Add project detail page * Add a task tracker CLI project * UI changes * Add projects for expense and task tracker * Add new projects * Add blogging platform API project * Project page UI changes * Add todo list api project * Add todo list api project * Add a project idea for weather service * Add expense tracker API project * Add more details to expense tracker * Add markdown note taking app idea * Add URL shortener service project * Add broadcast server project * Add ecommerce project idea * Add project on other roadmaps * Add workout tracker project * Add image processing project idea * Add movie reservation system ap * Add movie reservation system project * Add realtime leader board system project * Add details for a database backup utility * Add project contribution docs * Fix UI of the discover page
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
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 = import.meta.glob<LinkGroupFileType>(
|
|
'/src/data/link-groups/*.md',
|
|
{
|
|
eager: true,
|
|
},
|
|
);
|
|
|
|
return Object.values(linkGroups).map((linkGroupFile) => ({
|
|
...linkGroupFile,
|
|
id: linkGroupPathToId(linkGroupFile.file),
|
|
}));
|
|
}
|
|
|
|
export async function getLinkGroupById(
|
|
groupId: string,
|
|
): Promise<LinkGroupFileType> {
|
|
const linkGroup = await import(`../data/link-groups/${groupId}.md`);
|
|
|
|
return {
|
|
...linkGroup,
|
|
id: linkGroupPathToId(linkGroup.file),
|
|
};
|
|
}
|