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
import { html } from "https://esm.town/v/postpostscript/html";
export async function randomLike() {
const { data } = await fetch("https://api.val.town/v1/me/likes", {
headers: {
Authorization: `Bearer ${Deno.env.get("valtown")}`,
},
}).then(res => res.json());
return data.sort(() => Math.random() > 0.5 ? 1 : -1)[0];
}
export async function randomLikeLink() {
try {
const { author: { username }, name } = await randomLike();
return html`
<a href="https://val.town/v/${username}/${name}" target="_blank">
@${username}/${name}
</a>
`;
} catch (e) {
console.log("randomLikeLink could not find like", e);
}
return html`Couldn't find one!`;
}
export async function recommends() {
return html`
Check out a random Val I've liked!
${await randomLikeLink()}
`;
}
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.