From 82bc85b2bb95172c20f6aea5c6d2b0f9fc9a19d0 Mon Sep 17 00:00:00 2001 From: Yasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com> Date: Tue, 17 Nov 2026 23:37:02 +0900 Subject: today.astro: 今日と明日の予定を表示するアプリ画面を追加 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ビルド時に日付を計算した data.json を端末側で絞り込むため、日付が変わっても再ビルドなしで今日の予定が出る。通信できないときは Service Worker のキャッシュを使う。 --- src/pages/kodaira/events/data.json.ts | 57 +++++++++++ src/pages/kodaira/events/today.astro | 186 ++++++++++++++++++++++++++++++++++ 2 files changed, 243 insertions(+) create mode 100644 src/pages/kodaira/events/data.json.ts create mode 100644 src/pages/kodaira/events/today.astro (limited to 'src/pages/kodaira/events') diff --git a/src/pages/kodaira/events/data.json.ts b/src/pages/kodaira/events/data.json.ts new file mode 100644 index 0000000..67bda61 --- /dev/null +++ b/src/pages/kodaira/events/data.json.ts @@ -0,0 +1,57 @@ +// 「今日の予定」アプリ用のデータ(/kodaira/events/data.json)。 +// 日付の解釈はビルド時に済ませ、端末側は今日・明日の日付で絞り込むだけにする。 +import type { APIRoute } from 'astro'; +import events from '@/data/schedule/events.json'; +import meetings from '@/data/schedule/meetings.json'; +import { entryDates } from '@/lib/schedule-dates'; + +type Row = { date: string; title: string; place: string; note: string }; + +const strip = (value: string) => + String(value ?? '') + .replace(/<[^>]*>/g, '') + .replace(/ /g, ' ') + .replace(/&/g, '&') + .replace(/</g, '<') + .replace(/>/g, '>') + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/\s+/g, ' ') + .trim(); + +const pad = (n: number) => String(n).padStart(2, '0'); +const toKey = (d: Date) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`; + +const now = new Date(); +const from = new Date(now); +from.setDate(from.getDate() - 31); +const to = new Date(now); +to.setDate(to.getDate() + 400); +const fromKey = toKey(from); +const toKeyStr = toKey(to); + +const collect = (rows: Row[], type: 'event' | 'meeting') => + rows + .map((row) => { + const dates = entryDates(type, row.date, row.place).filter( + (d) => d >= fromKey && d <= toKeyStr, + ); + if (dates.length === 0) return null; + return { + t: strip(row.title), + p: strip(row.place), + n: strip(row.note).slice(0, 140), + dates, + }; + }) + .filter(Boolean); + +const data = { + generated: now.toISOString(), + rows: [...collect(events.rows as Row[], 'event'), ...collect(meetings.rows as Row[], 'meeting')], +}; + +export const GET: APIRoute = () => + new Response(JSON.stringify(data), { + headers: { 'Content-Type': 'application/json; charset=utf-8' }, + }); diff --git a/src/pages/kodaira/events/today.astro b/src/pages/kodaira/events/today.astro new file mode 100644 index 0000000..47172ce --- /dev/null +++ b/src/pages/kodaira/events/today.astro @@ -0,0 +1,186 @@ +--- +// 「今日の予定」アプリの画面(/kodaira/events/today/)。 +// データは /kodaira/events/data.json(ビルド時に日付を計算済み)から読み、 +// 端末側で今日・明日の分だけを表示する。日付が変わっても再ビルドは不要。 +const title = '今日の小平市'; +--- + + + + + + + {title}|小平市のイベント・行事予定 + + + + + + + + + +
+

{title}

+

読み込み中…

+
+ +
+ + + + + + -- cgit v1.3.1