vladimyr/valshot

Forks

Forked 2 times

Val Shot

Generate val source code screenshot using sourcecodeshots.com

⚠️ This service is offered for personal use under a reasonable usage policy as stated here: https://sourcecodeshots.com/docs

📣 Special thanks to @pomdtr for their help and contributions!

Usage

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

Example

Readme
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
// SPDX-License-Identifier: 0BSD
import { fetchVal } from "https://esm.town/v/vladimyr/fetchVal";
import { serveReadme } from "https://esm.town/v/vladimyr/serveReadme";
import { toHonoHandler } from "https://esm.town/v/vladimyr/toHonoHandler";
import { Hono } from "npm:hono";
import ky from "npm:ky";
const router = new Hono();
// router.get("/", toHonoHandler(serveReadme(import.meta.url)));
router.get("/", async (c) => {
// const { author, name } = c.req.param();
const query = c.req.query();
const res = await fetch(
"https://raw.githubusercontent.com/burningion/dab-and-tpose-controlled-lights/master/src/dab-tpose-controller.py",
);
const code = await res.text();
const imageURL = await createScreenshot(code, query.theme);
return c.redirect(imageURL.href);
});
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: "python", theme },
},
}).json();
return new URL(url);
}

Val Shot

Usage

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

Example

Readme
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;
}
1
Next