diff --git a/.zed/settings.json b/.zed/settings.json new file mode 100644 index 0000000..4c14413 --- /dev/null +++ b/.zed/settings.json @@ -0,0 +1,5 @@ +{ + "file_types": { + "HTML": ["**/*.handlebars"] + } +} diff --git a/index.ts b/index.ts index ce19598..d8e55b6 100644 --- a/index.ts +++ b/index.ts @@ -1,6 +1,6 @@ import Handlebars from "handlebars"; import { Database } from "bun:sqlite"; -import { differenceInDays, startOfToday, startOfDay, format } from "date-fns"; +import { differenceInDays, startOfToday, startOfDay, format, formatDate, subDays } from "date-fns"; import { tz } from "@date-fns/tz"; const db = new Database("database.db"); @@ -31,16 +31,26 @@ Bun.serve({ const allCollisions = db.query("SELECT * FROM service_alerts WHERE is_collision ORDER BY date ASC").all() - const last60Days = new Array(60).fill(false) + let last60Days = new Array<{ collision: boolean; renderedDate: string; }>(60).fill({ + collision: false, + renderedDate: "", + }) + + last60Days = last60Days.map((v, index) => { + return { + ...v, + renderedDate: format(subDays(new Date(), index), "LLL d, yyyy", { in: tz("America/Denver") }), + } + }) 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) { + if (difference >= 60) { continue } - last60Days[difference] = true + last60Days[difference].collision = true } last60Days.reverse() diff --git a/templates/home.handlebars b/templates/home.handlebars index 1c79d93..4de4efa 100644 --- a/templates/home.handlebars +++ b/templates/home.handlebars @@ -29,20 +29,33 @@
{{ latestCollision.content }}
-
+
{{#each last90Days }} - {{#if this}} -
+ {{#if collision}} +
{{else}} -
+
{{/if}} {{/each}}
-
60 days ago
-
Today
+
60 days ago
+
+
Today
+ +