clone

a daily shikaku puzzle for phones: one seeded puzzle per date, solved by dragging rectangles

Switch daily routes to /d

Dami committed 4d0a61d
commit
4d0a61d16442bb7e62631b768117db274aa59a07
parent
13a332ff9c3ef12ed7dd9e6d351cb7da7be5f11a
author
Dami <dami.etoile@gmail.com>
9 files changed, +131 -77
MREADME.md2+-
Alib/site/paths.ts13++++++
Mroutes/_app.tsx3+-
Aroutes/d/[date].tsx70++++++++++++++++++++++++++++++
Aroutes/d/index.tsx14++++++
Mroutes/daily/[date].tsx67+----------------------------
Mroutes/daily/index.tsx11+----
Mroutes/index.tsx3+-
Atests/lib/site/paths_test.ts25+++++++++++
M README.md +1 -1
A lib/site/paths.ts +13 -0
M routes/_app.tsx +2 -1
A routes/d/[date].tsx +70 -0
@@ -0,0 +1,70 @@
1+import { getPuzzleByDate } from "@/lib/shikaku/catalog.ts";2+import { buildDailyPath } from "@/lib/site/paths.ts";3+import { define } from "../../utils.ts";4+import ShikakuGame from "../../islands/ShikakuGame.tsx";5+6+export const handler = define.handlers((ctx) => {7+ const puzzle = getPuzzleByDate(ctx.params.date);8+9+ if (!puzzle) {10+ return new Response("Puzzle not found", { status: 404 });11+ }12+13+ const [year, month, day] = puzzle.date.split("-").map(Number);14+ const currentDate = new Date(Date.UTC(year, month - 1, day));15+ const previousDate = new Date(currentDate);16+ previousDate.setUTCDate(previousDate.getUTCDate() - 1);17+ const nextDate = new Date(currentDate);18+ nextDate.setUTCDate(nextDate.getUTCDate() + 1);19+20+ return {21+ data: {22+ puzzle,23+ previousDate: previousDate.toISOString().slice(0, 10),24+ nextDate: nextDate.toISOString().slice(0, 10),25+ },26+ };27+});28+29+export default define.page<typeof handler>(({ data }) => {30+ return (31+ <main class="shikaku-play-shell">32+ <div class="shikaku-play-frame">33+ <header class="shikaku-play-header">34+ <div class="shikaku-play-header__row">35+ <div class="shikaku-play-day-nav shikaku-play-day-nav--with-home">36+ <a37+ class="shikaku-play-nav shikaku-play-nav--icon"38+ href="/"39+ aria-label="Back home"40+ >41+ ⌂42+ </a>43+ <a44+ class="shikaku-play-nav shikaku-play-nav--icon"45+ href={buildDailyPath(data.previousDate)}46+ aria-label="Previous day"47+ >48+ ‹49+ </a>50+ <div>51+ <p class="shikaku-play-kicker">Daily puzzle</p>52+ <h1 class="shikaku-play-title">{data.puzzle.date}</h1>53+ </div>54+ <a55+ class="shikaku-play-nav shikaku-play-nav--icon"56+ href={buildDailyPath(data.nextDate)}57+ aria-label="Next day"58+ >59+ ›60+ </a>61+ </div>62+ </div>63+ <p class="shikaku-play-hint">Drag. One clue.</p>64+ </header>65+66+ <ShikakuGame puzzle={data.puzzle} />67+ </div>68+ </main>69+ );70+});
A routes/d/index.tsx +14 -0
M routes/daily/[date].tsx +2 -65
@@ -1,69 +1,6 @@
1-import { getPuzzleByDate } from "@/lib/shikaku/catalog.ts";1+import { buildDailyPath } from "@/lib/site/paths.ts";22 import { define } from "../../utils.ts";3-import ShikakuGame from "../../islands/ShikakuGame.tsx";43 54 export const handler = define.handlers((ctx) => {6- const puzzle = getPuzzleByDate(ctx.params.date);7-8- if (!puzzle) {9- return new Response("Puzzle not found", { status: 404 });10- }11-12- const [year, month, day] = puzzle.date.split("-").map(Number);13- const currentDate = new Date(Date.UTC(year, month - 1, day));14- const previousDate = new Date(currentDate);15- previousDate.setUTCDate(previousDate.getUTCDate() - 1);16- const nextDate = new Date(currentDate);17- nextDate.setUTCDate(nextDate.getUTCDate() + 1);18-19- return {20- data: {21- puzzle,22- previousDate: previousDate.toISOString().slice(0, 10),23- nextDate: nextDate.toISOString().slice(0, 10),24- },25- };26-});27-28-export default define.page<typeof handler>(({ data }) => {29- return (30- <main class="shikaku-play-shell">31- <div class="shikaku-play-frame">32- <header class="shikaku-play-header">33- <div class="shikaku-play-header__row">34- <div class="shikaku-play-day-nav shikaku-play-day-nav--with-home">35- <a36- class="shikaku-play-nav shikaku-play-nav--icon"37- href="/"38- aria-label="Back home"39- >40- ⌂41- </a>42- <a43- class="shikaku-play-nav shikaku-play-nav--icon"44- href={`/daily/${data.previousDate}`}45- aria-label="Previous day"46- >47- ‹48- </a>49- <div>50- <p class="shikaku-play-kicker">Daily puzzle</p>51- <h1 class="shikaku-play-title">{data.puzzle.date}</h1>52- </div>53- <a54- class="shikaku-play-nav shikaku-play-nav--icon"55- href={`/daily/${data.nextDate}`}56- aria-label="Next day"57- >58- ›59- </a>60- </div>61- </div>62- <p class="shikaku-play-hint">Drag. One clue.</p>63- </header>64-65- <ShikakuGame puzzle={data.puzzle} />66- </div>67- </main>68- );5+ return ctx.redirect(buildDailyPath(ctx.params.date));696 });
M routes/daily/index.tsx +2 -9
M routes/index.tsx +2 -1
A tests/lib/site/paths_test.ts +25 -0