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
import { fetch } from "https://esm.town/v/std/fetch";
export async function renderGithubReadme(req: express.Request, res: express.Response) {
try {
const { repo } = req.query as {
repo: string;
};
const markdown = await fetch(`https://api.github.com/repos/${repo}/readme`)
.then((res) => res.json()).then(({ content }) => atob(content));
const html = await fetch("https://api.github.com/markdown", {
method: "POST",
headers: {
"Accept": "Accept: application/vnd.github+json",
"Content-Type": "text/x-markdown",
},
body: JSON.stringify({ text: markdown, mode: "gfm", context: repo }),
}).then((res) => res.text());
res.send(
`<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://raw.githubusercontent.com/sindresorhus/github-markdown-css/main/github-markdown.css">
<style>
.markdown-body {
box-sizing: border-box;
min-width: 200px;
max-width: 980px;
margin: 0 auto;
padding: 45px;
}
@media (max-width: 767px) {
.markdown-body {
padding: 15px;
}
}
</style>
<article class="markdown-body">
${html}
</article>`,
);
}
catch (error) {
res.status(500);
res.send(`An error occured: ${error}`);
}
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023