pomdtr-valshot.web.val.run
Readme

Val Shot

Usage

https://pomdtr-valshot.web.val.run/v/<author>/<val>

Example

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
import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
import { gfm } from "https://esm.town/v/pomdtr/gfm";
import { readme } from "https://esm.town/v/pomdtr/readme";
import { Hono } from "npm:hono";
import ky from "npm:ky";
const router = new Hono();
const { author, name } = extractValInfo(import.meta.url);
router.get("/", async c => {
return c.html(gfm(await readme(author, name)));
});
router.get("/v/:author/:name", async (c) => {
const params = c.req.param();
const query = c.req.query();
const code = await fetchValCode(`${params.author}/${params.name}`);
const imageURL = await createScreenshot(code, query.theme);
return Response.redirect(imageURL);
});
export default router.fetch;
export async function createScreenshot(code: string, theme: string = "dark-plus"): Promise<URL> {
const apiUrl = "https://sourcecodeshots.com/api/image/permalink";
const { url } = await ky.post(apiUrl, {
json: {
code,
settings: { language: "tsx", theme },
},
}).json();
return new URL(url);
}
async function fetchValCode(alias: string): Promise<string> {
const prefixUrl = "https://api.val.town/v1/alias";
const { code } = await ky.get(alias, { prefixUrl }).json();
return code;
}
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!
March 4, 2024