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.
76 lines
1.7 KiB
76 lines
1.7 KiB
import type { MarkdownFileType } from './file'; |
|
|
|
export interface AuthorFrontmatter { |
|
name: string; |
|
imageUrl: string; |
|
employment?: { |
|
title: string; |
|
company: string; |
|
}; |
|
social: { |
|
twitter: string; |
|
github: string; |
|
linkedin: string; |
|
website: string; |
|
}; |
|
} |
|
|
|
export type AuthorFileType = MarkdownFileType<AuthorFrontmatter> & { |
|
id: string; |
|
}; |
|
|
|
function authorPathToId(filePath: string): string { |
|
const fileName = filePath.split('/').pop() || ''; |
|
|
|
return fileName.replace('.md', ''); |
|
} |
|
|
|
/** |
|
* Gets the IDs of all the authors available on the website |
|
* |
|
* @returns string[] Array of author IDs |
|
*/ |
|
export async function getAuthorIds() { |
|
const authorFiles = import.meta.glob<AuthorFileType>( |
|
'/src/data/authors/*.md', |
|
{ |
|
eager: true, |
|
}, |
|
); |
|
|
|
return Object.keys(authorFiles).map(authorPathToId); |
|
} |
|
|
|
export async function getAllAuthors(): Promise<AuthorFileType[]> { |
|
const authorFilesMap: Record<string, AuthorFileType> = |
|
import.meta.glob<AuthorFileType>('/src/data/authors/*.md', { |
|
eager: true, |
|
}); |
|
|
|
const authorFiles = Object.values(authorFilesMap); |
|
|
|
return authorFiles.map((authorFile) => ({ |
|
...authorFile, |
|
id: authorPathToId(authorFile.file), |
|
})); |
|
} |
|
|
|
export async function getAuthorById(id: string): Promise<AuthorFileType> { |
|
const authorFilesMap: Record<string, AuthorFileType> = |
|
import.meta.glob<AuthorFileType>('/src/data/authors/*.md', { |
|
eager: true, |
|
}); |
|
|
|
const authorFile = Object.values(authorFilesMap).find((authorFile) => { |
|
return authorPathToId(authorFile.file) === id; |
|
}); |
|
|
|
if (!authorFile) { |
|
throw new Error(`Author with ID ${id} not found`); |
|
} |
|
|
|
return { |
|
...authorFile, |
|
id: authorPathToId(authorFile.file), |
|
}; |
|
}
|
|
|