new things

This commit is contained in:
cjdenio committed 2026-04-17 12:02:34 -06:00
1 parent d17beb7351
commit a5459b23c6
2 files changed
+54 -9

No files matched your search

+35 -7
View File
@@ -7,6 +7,13 @@ const db = new Database("database.db");
await Bun.cron("./scripts/sync-rss.js", "*/5 * * * *", "rss-sync"); await Bun.cron("./scripts/sync-rss.js", "*/5 * * * *", "rss-sync");
interface ServiceAlert {
id: string
date: string
is_collision: number
content: string
}
Bun.serve({ Bun.serve({
routes: { routes: {
"/": async () => { "/": async () => {
@@ -16,24 +23,45 @@ Bun.serve({
).text(), ).text(),
); );
const latestCollision = await db const latestCollision = db
.query( .query<ServiceAlert, []>(
"SELECT * FROM service_alerts WHERE is_collision ORDER BY date DESC LIMIT 1;", "SELECT * FROM service_alerts WHERE is_collision ORDER BY date DESC LIMIT 1;",
) )
.get(); .get()!;
const allCollisions = db.query<ServiceAlert, []>("SELECT * FROM service_alerts WHERE is_collision ORDER BY date ASC").all()
const last60Days = new Array(60).fill(false)
for (const collision of allCollisions) {
const collisionDay = startOfDay(new Date(collision.date), { in: tz("America/Denver") })
const difference = differenceInDays(startOfToday({ in: tz("America/Denver") }), collisionDay)
if (difference > 60) {
continue
}
last60Days[difference] = true
}
last60Days.reverse()
return new Response( return new Response(
homeTemplate({ homeTemplate({
daysSince: differenceInDays( daysSince: differenceInDays(
startOfToday({ in: tz("America/Denver") }), startOfToday({ in: tz("America/Denver") }),
startOfDay(new Date(latestCollision.date), { in: tz("America/Denver") }), startOfDay(new Date(latestCollision.date), {
in: tz("America/Denver"),
}),
), ),
latestCollision: { latestCollision: {
...latestCollision, ...latestCollision,
formattedDate: format(new Date( formattedDate: format(
latestCollision.date, new Date(latestCollision.date),
), "LLL d, yyyy", { in: tz("America/Denver") }), "LLL d, yyyy",
{ in: tz("America/Denver") },
),
}, },
last90Days: last60Days,
}), }),
{ {
headers: { "Content-Type": "text/html" }, headers: { "Content-Type": "text/html" },
+19 -2
View File
@@ -4,8 +4,9 @@
<title>IT HAS BEEN {{ daysSince }} DAYS SINCE A CAR HIT A UTA TRAIN</title> <title>IT HAS BEEN {{ daysSince }} DAYS SINCE A CAR HIT A UTA TRAIN</title>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script> <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head> </head>
<body class="py-10"> <body class="py-10 px-5">
<div <div
class="max-w-96 bg-blue-950 text-white mx-auto rounded-lg p-8 space-y-4 mb-10" class="max-w-96 bg-blue-950 text-white mx-auto rounded-lg p-8 space-y-4 mb-10"
> >
@@ -23,9 +24,25 @@
</p> </p>
</div> </div>
<div class="max-w-96 mx-auto font-sans overflow-hidden"> <div class="max-w-96 mx-auto font-sans overflow-hidden mb-10">
<div class="bg-gray-200 border border-gray-500 rounded-t-lg px-2">{{ latestCollision.formattedDate }}</div> <div class="bg-gray-200 border border-gray-500 rounded-t-lg px-2">{{ latestCollision.formattedDate }}</div>
<pre class="font-sans text-wrap border border-gray-500 border-t-0 rounded-b-lg p-2">{{ latestCollision.content }}</pre> <pre class="font-sans text-wrap border border-gray-500 border-t-0 rounded-b-lg p-2">{{ latestCollision.content }}</pre>
</div> </div>
<div class="flex justify-between max-w-96 mx-auto h-8">
{{#each last90Days }}
{{#if this}}
<div class="h-full w-0.5 sm:w-1 bg-red-400"></div>
{{else}}
<div class="h-full w-0.5 sm:w-1 bg-green-400"></div>
{{/if}}
{{/each}}
</div>
<div class="max-w-96 mx-auto flex justify-between">
<div class="text-gray-600 text-sm">60 days ago</div>
<div class="text-gray-600 text-sm">Today</div>
</div>
</body> </body>
</html> </html>