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
import { html } from "https://esm.town/v/postpostscript/html";
import { getValEndpointFromUrl } from "https://esm.town/v/postpostscript/meta";
import { alias } from "https://esm.town/v/stevekrouse/alias?v=0";
const ENDPOINT = getValEndpointFromUrl(import.meta.url);
export function profileImageUrl(username: string) {
return `${ENDPOINT}/${username}`;
}
export function ProfileImage(
username: string,
className = "profile-image",
) {
return html`<img src="${profileImageUrl(username)}" class="${className}" alt="${username}'s profile picture'" />`;
}
export function Profile(username: string) {
return html`
<span
class="profile-image"
style="
background: url('${profileImageUrl(username)}') no-repeat center;
background-size: cover;
margin: 0.6em 0.2em -0.6em 0.2em;
width: 2em;
height: 2em;
border-radius: 2em;
display: inline-block;
"
aria-label="${username}'s profile picture'">
</span>
`;
}
export default async function(req: Request) {
const { pathname } = new URL(req.url);
if (pathname.length <= 1) {
return Response.json({
validPathname: "`@handle` or `handle`",
});
}
const { profileImageUrl } = await alias({
username: pathname.replace(/^\/(@)?/, "").split("/")[0],
});
return Response.redirect(profileImageUrl, 302);
}