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
import { stopDeparturesSingleCountdown } from "https://esm.town/v/kognise/stopDeparturesSingleCountdown";
import { stopIds } from "https://esm.town/v/kognise/stopIds";
export async function workBusesGui(
req: express.Request,
res: express.Response,
) {
const currentKey = req.path.slice(1);
let departures;
if (stopIds[currentKey]) {
departures = await stopDeparturesSingleCountdown(
stopIds[currentKey],
);
}
return res.send(`
<!DOCTYPE html>
<html>
<head>
<title>bus departures</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/light.css">
</head>
<body>
<nav>
${
Object.keys(stopIds).map((key) => `
${
currentKey === key
? `<strong>${key}</strong>`
: `<a href="/${key}">${key}</a>`
}
`).join(" &middot; ")
}
</nav>
${
departures
? `
<h1>bus departures from ${currentKey}</h1>
<ul>
${
departures.map((departure) => `
<li>
${(departure.countdown / 1000 / 60).toFixed(0)} min
${departure.is_real_time ? "(live)" : "(scheduled)"}
</li>
`).join("")
}
</ul>
`
: `
Select a location!
👆 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.