forked from solidjs/solid-docs-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
52 lines (45 loc) · 1.48 KB
/
index.ts
File metadata and controls
52 lines (45 loc) · 1.48 KB
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
43
44
45
46
47
48
49
50
51
52
import { DocFile, LessonFile, LessonLookup, ResourceMetadata } from "./types";
export { DocFile, LessonFile, LessonLookup, ResourceMetadata };
function noThrow<T>(x: Promise<T>): Promise<T | undefined> {
return x.catch(() => undefined);
}
export async function getApi(lang: string): Promise<DocFile | undefined> {
return await noThrow(import(`../langs/${lang}/api/api.md`));
}
export async function getDoc(
lang: string,
resource?: string
): Promise<DocFile | undefined> {
return await noThrow(import(`../langs/${lang}/guides/${resource}.md`));
}
export async function getGuideDirectory(
lang: string
): Promise<ResourceMetadata[] | undefined> {
const directory = await noThrow(
import(`../langs/${lang}/guides/directory.json`)
);
return directory?.default;
}
export async function getTutorial(
lang: string,
lesson: string
): Promise<LessonFile | undefined> {
const [lessonFiles, solved, markdown] = await Promise.all([
noThrow(import(`../langs/${lang}/tutorials/${lesson}/lesson.json`)),
noThrow(import(`../langs/${lang}/tutorials/${lesson}/solved.json`)),
noThrow(import(`../langs/${lang}/tutorials/${lesson}/lesson.md`)),
]);
return {
lesson: lessonFiles?.default,
solved: solved?.default,
markdown: markdown?.default,
};
}
export async function getTutorialDirectory(
lang: string
): Promise<LessonLookup[] | undefined> {
const directory = await noThrow(
import(`../langs/${lang}/tutorials/directory.json`)
);
return directory?.default;
}