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

fav

Turn an emoji into an SVG favicon.

Inspired by Lea's tweet.

Usage

<link rel="icon" href="https://karkowg-fav.web.val.run?emoji=🧨" />

Alternatively, you can use Wes Bos' fav.farm.

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
/** @jsxImportSource https://esm.sh/preact */
import { isEmoji } from "https://esm.town/v/karkowg/emojis";
import { html } from "https://esm.town/v/stevekrouse/html?v=5";
import { render } from "npm:preact-render-to-string";
function FavIcon({ emoji }: { emoji: string }) {
return (
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 100 100">
<text y=".9em" fontSize={90}>
{emoji}
</text>
</svg>
);
}
export default async function(req: Request): Promise<Response> {
const url = new URL(req.url);
let emoji = url.searchParams.get("emoji");
emoji = isEmoji(emoji) ? emoji : "🦕";
return html(render(<FavIcon emoji={emoji} />), {
headers: {
"Content-Type": "image/svg+xml",
"Cache-Control": `public, max-age=${60 * 60 * 24}, s-maxage=${60 * 60 * 24 * 7}`,
},
});
}
karkowg-fav.web.val.run
July 19, 2024