Public
markdownBlogStarter
Viewing readonly version: 39View latest version
HTTP
99
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
const DIR_NAME = "posts";
const ESM_TOWM_PREFIX = import.meta.url.substring(0, import.meta.url.lastIndexOf("/"));
interface Post {
relativePath: string;
esmPath: string;
content: string;
}
// Retrieves all posts in the posts/ folder
async function getPosts(): Promise<Post[]> {
// Looks for all posts in the posts folder
const posts = [];
let i = 1;
let post = await getPost(1);
while (post && i < 100) {
posts.push(post);
i++;
post = await getPost(i);
}
return posts;
}
async function getPost(i: number): Promise<Post | null> {
const relativePath = `${DIR_NAME}/${i}.md`;
const esmPath = `${ESM_TOWM_PREFIX}/${DIR_NAME}/${i}.md`;
return { relativePath, esmPath };
const resp = await fetch(esmPath);
if (!resp.ok) {
return null;
}
const content = await resp.text();
}
const posts = await getPosts();
H
index.ts