From d404993583f5e3143660fbfbf5191d9d33f1b403 Mon Sep 17 00:00:00 2001 From: Oliver Bryan Date: Fri, 6 Feb 2026 00:13:56 +0000 Subject: [PATCH] populate days --- src/assets/current-day.png | Bin 0 -> 174 bytes src/assets/empty-day.png | Bin 0 -> 174 bytes src/assets/past-day.png | Bin 0 -> 174 bytes src/index.ts | 52 ++++++++++++++++++++++++++++++++----- 4 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 src/assets/current-day.png create mode 100644 src/assets/empty-day.png create mode 100644 src/assets/past-day.png diff --git a/src/assets/current-day.png b/src/assets/current-day.png new file mode 100644 index 0000000000000000000000000000000000000000..e510d5bdef81ca406a9a6a125c41f213769bad74 GIT binary patch literal 174 zcmeAS@N?(olHy`uVBq!ia0vp^8X(NU1|)m_?Z^dEjKx9jP7LeL$-D$|GCW-zLn2z= z-q^_55WvIs@Q82Do%5b|&L0abVS3o!olqDrTj4&7{UulI@3Q5aJHJ|3&x}@+|J&3! z1q?&{{|j8M+waJ%i3V4`I27`<^z~Gzx+~15PH`R9JILGyw3ETp)z4*}Q$iB}PiH=Q literal 0 HcmV?d00001 diff --git a/src/assets/empty-day.png b/src/assets/empty-day.png new file mode 100644 index 0000000000000000000000000000000000000000..cf6b9299c1d03423449013d4996bcef8f24dc879 GIT binary patch literal 174 zcmeAS@N?(olHy`uVBq!ia0vp^8X(NU1|)m_?Z^dEjKx9jP7LeL$-D$|GCW-zLn2z= z-q^_55WvIs@JM9rfn$m}F$ZExnI5)xCltoZR=Ce%f64XscGdFDosaie&5Tx)|J&3! z1q?&{{|j8M+waJ%i3V4`I27`<^z~Gzx+}~rN?bD{D$QpD?PTzD^>bP0l+XkK3>G~_ literal 0 HcmV?d00001 diff --git a/src/assets/past-day.png b/src/assets/past-day.png new file mode 100644 index 0000000000000000000000000000000000000000..c1b36e2069ef1ff6c124b25ae2ad548507938df9 GIT binary patch literal 174 zcmeAS@N?(olHy`uVBq!ia0vp^8X(NU1|)m_?Z^dEjKx9jP7LeL$-D$|GCW-zLn2z= z-q^_55WvIs@Q5ml^mqBwZUtO(9ezAiintTbesAJ4$6Zdpx7~Z0^T=Yo-?M2a-S;Ob zq=Mnq%l1dM+|R$@a0(4-?J@|hyjulPm8$TSAtRl0Zs-~JXrP@8p00i_>zopr03lXE A*8l(j literal 0 HcmV?d00001 diff --git a/src/index.ts b/src/index.ts index 5b814de..687c1bb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,22 +1,60 @@ -import { createCanvas } from "@napi-rs/canvas"; +/** biome-ignore-all assist/source/organizeImports: <> */ +import { createCanvas, loadImage, type Image } from "@napi-rs/canvas"; import { Hono } from "hono"; +import { readFileSync } from "node:fs"; + +let emptyDay: Image; +let currentDay: Image; +let pastDay: Image; +(async () => { + emptyDay = await loadImage(readFileSync("./src/assets/empty-day.png")); + currentDay = await loadImage(readFileSync("./src/assets/current-day.png")); + pastDay = await loadImage(readFileSync("./src/assets/past-day.png")); +})(); const app = new Hono(); -app.get("/", (c) => c.text("go to /width/height to get a placeholder image")); - -app.get("/:width/:height", async (c) => { - const width = Number.parseInt(c.req.param("width"), 10); - const height = Number.parseInt(c.req.param("height"), 10); +app.get("/", async (c) => { + const width = 1080; + const height = 2342; const canvas = createCanvas(width, height); const ctx = canvas.getContext("2d"); ctx.fillStyle = "#ded6c4"; ctx.fillRect(0, 0, width, height); + const now = new Date(); + const start = new Date(now.getFullYear(), 0, 0); + const diff = now - start; + const oneDay = 1000 * 60 * 60 * 24; + const today = Math.floor(diff / oneDay) - 1; + + const columns = 15; + const size = 40; + const padx = 100; + const pady = 500; + const gap = 20; + let x = padx; + let y = pady; + for (let i = 0; i < 365; i++) { + if (i % columns === 0) { + x = padx; + y += size + gap; + } + + if (today > i) ctx.drawImage(pastDay, x, y); + else if (today === i) ctx.drawImage(currentDay, x, y); + else ctx.drawImage(emptyDay, x, y); + + x += size + gap; + } + const buffer = new Uint8Array(canvas.toBuffer("image/png")); return c.body(buffer, 200, { "Content-Type": "image/png" }); }); -export default app; +export default { + fetch: app.fetch, + port: 7345, +};