forked from roadmapsh/deprecated-version
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink-group.ts
42 lines (35 loc) · 1.01 KB
/
link-group.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
}