Public
markdownBlogStarter
Viewing readonly version: 59View latest version
Script
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
const DIR_NAME = "posts";
const ESM_TOWM_PREFIX = import.meta.url.substring(0, import.meta.url.lastIndexOf("/"));
export interface Post {
relativePath: string;
esmPath: string;
content: string;
}
// Retrieves all posts in the posts/ folder
export 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}/post-${i}.md`;
const resp = await fetch(esmPath);
if (!resp.ok) {
return null;
}
const content = await resp.text();
return { relativePath, esmPath, content };
}
H
index.ts