Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

Render this badge:

Substrate demo on Val Town

Use the middleware: https://www.val.town/v/substrate/substrateBadgeMiddleware

Or:

import substrateBadge from "https://esm.town/v/substrate/substrateBadge"; export default async function(req: Request): Promise<Response> { const badge = substrateBadge(import.meta.url); const html = ` <h1>Hello, world</h1> ${badge} `; return new Response(html, { headers: { "Content-Type": "text/html; charset=utf-8", }, }); }
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
49
50
51
52
53
54
55
56
57
// substrate + valtown badge
const left = 80;
const width = 160;
const height = 48; // width * 0.3;
const radius = 8;
const logotype = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 442 40" x="${left}" y="6" width="48" fill="#fff">
<path d="M92.182 67.387c3.89 0 7.064-1.082 9.524-3.248 2.459-2.164 3.689-5.046 3.689-8.644v-1.101H91.411c-2.57 0-4.589.551-6.056 1.652-1.47 1.101-2.202 2.642-2.202 4.624 0 1.982.771 3.598 2.312 4.845 1.542 1.249 3.78 1.872 6.717 1.872M89.76 78.618c-3.893
<path d="M13.903 22.458H0V33.91h13.903z" />
</svg>
`;
export const badge = `
<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
<rect width="${width}" height="${height}" fill="#111" rx="${radius}" ry="${radius}" />
<a href="https://substrate.run">
<text x="8" y="17" textAnchor="start" fill="#fff" style="font-family:system-ui,sans-serif;font-size:12px;font-weight:500;letter-spacing:-0.05em;">
Substrate
</text>
<text x="64" y="17" textAnchor="start" fill="#fff" style="font-family:system-ui,sans-serif;font-size:10px;letter-spacing:-0.05em;">
demo
</text>
</a>
<text x="8" y="36" textAnchor="start" fill="#fff" style="font-family:system-ui,sans-serif;font-size:10px;font-weight:500;letter-spacing:-0.05em;">
view source on
</text>
${logotype}
</svg>
`;
function getHREF(mod) {
const url = new URL(mod);
return `https://val.town${url.pathname}`;
}
export function getBadgeLink(url: string): string {
const href = getHREF(url);
return `<div>
<a href="${href}" target="_blank" style="text-decoration:none;color:inherit">${badge}</a>
<div>`;
}
function handler(req: Request): Response {
return new Response(badge, {
headers: {
"Content-Type": "image/svg+xml",
},
});
}
export default function htmlOrResponse(args: Request | string): string | Response {
if (typeof args === "string") return getBadgeLink(args);
if (args instanceof Request) return handler(args);
throw new Error("bad args");
}
substrate-substratebadge.web.val.run
July 10, 2024