forked from denoland/deno-gfm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
48 lines (43 loc) · 1.44 KB
/
main.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
43
44
45
46
47
48
import { listenAndServe } from "https://deno.land/std@0.110.0/http/server.ts";
import { CSS, render } from "../mod.ts";
import "https://esm.sh/prismjs@1.25.0/components/prism-javascript?no-check";
import "https://esm.sh/prismjs@1.25.0/components/prism-typescript?no-check";
import "https://esm.sh/prismjs@1.25.0/components/prism-bash?no-check";
import "https://esm.sh/prismjs@1.25.0/components/prism-powershell?no-check";
const CONTENT_PATH = new URL("./content.md", import.meta.url);
async function handler(_req: Request): Promise<Response> {
try {
const markdown = await Deno.readTextFile(CONTENT_PATH);
const body = render(markdown, "/");
const html = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
main {
max-width: 800px;
margin: 0 auto;
padding: 2rem 1rem;
}
${CSS}
</style>
</head>
<body data-color-mode="auto" data-light-theme="light" data-dark-theme="dark">
<main class="markdown-body">
${body}
</main>
</body>
</html>`;
return new Response(html, {
headers: {
"content-type": "text/html;charset=utf-8",
},
});
} catch (err) {
console.error(err);
return new Response(err.message, { status: 500 });
}
}
console.log("Server listening on http://localhost:8000");
listenAndServe(":8000", handler);