summaryrefslogtreecommitdiffhomepage
path: root/src/pages/kodaira/events/today.astro
blob: 47172ce6fce164f1e7f9ab689b85236c593ba759 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
---
// 「今日の予定」アプリの画面(/kodaira/events/today/)。
// データは /kodaira/events/data.json(ビルド時に日付を計算済み)から読み、
// 端末側で今日・明日の分だけを表示する。日付が変わっても再ビルドは不要。
const title = '今日の小平市';
---

<!doctype html>
<html lang="ja">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>{title}|小平市のイベント・行事予定</title>
    <meta name="robots" content="noindex" />
    <link rel="manifest" href="/manifest-events.webmanifest" />
    <meta name="theme-color" content="#1565c0" />
    <link rel="apple-touch-icon" href="/icons/event-192.png" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-title" content="今日の小平市" />
    <style is:global>
      :root {
        color-scheme: light dark;
        --bg: #f6f7f9;
        --card: #fff;
        --text: #1a1a1a;
        --muted: #5b6470;
        --line: #e3e6ea;
        --accent: #1565c0;
      }
      @media (prefers-color-scheme: dark) {
        :root {
          --bg: #12151a;
          --card: #1b1f26;
          --text: #e9edf2;
          --muted: #9aa4b1;
          --line: #2a3038;
          --accent: #6aa9ff;
        }
      }
      * { box-sizing: border-box; }
      body {
        margin: 0;
        background: var(--bg);
        color: var(--text);
        font-family: system-ui, -apple-system, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
        line-height: 1.5;
        -webkit-text-size-adjust: 100%;
      }
      header {
        position: sticky;
        top: 0;
        z-index: 2;
        padding: calc(0.8rem + env(safe-area-inset-top)) 1rem 0.8rem;
        background: var(--accent);
        color: #fff;
      }
      header h1 { margin: 0; font-size: 1.15rem; }
      header p { margin: 0.2rem 0 0; font-size: 0.8rem; opacity: 0.9; }
      main { padding: 0.9rem 0.8rem 1.5rem; max-width: 640px; margin: 0 auto; }
      section { margin-bottom: 1.2rem; }
      h2 {
        margin: 0 0 0.5rem;
        font-size: 0.95rem;
        color: var(--muted);
        font-weight: 600;
      }
      ul { list-style: none; margin: 0; padding: 0; }
      li {
        display: flex;
        gap: 0.6rem;
        padding: 0.7rem 0.8rem;
        margin-bottom: 0.5rem;
        background: var(--card);
        border: 1px solid var(--line);
        border-radius: 10px;
      }
      .time {
        flex: 0 0 3.4rem;
        font-variant-numeric: tabular-nums;
        font-weight: 700;
        color: var(--accent);
      }
      .body { flex: 1 1 auto; min-width: 0; }
      .name { font-weight: 600; overflow-wrap: anywhere; }
      .place { color: var(--muted); font-size: 0.82rem; overflow-wrap: anywhere; }
      .empty { color: var(--muted); font-size: 0.9rem; padding: 0.4rem 0.2rem; }
      footer {
        max-width: 640px;
        margin: 0 auto;
        padding: 0 1rem calc(1.4rem + env(safe-area-inset-bottom));
        color: var(--muted);
        font-size: 0.78rem;
      }
      footer a { color: var(--accent); }
      .note { margin: 0.4rem 0; }
    </style>
  </head>
  <body>
    <header>
      <h1>{title}</h1>
      <p id="range">読み込み中…</p>
    </header>

    <main id="app"></main>

    <footer>
      <p class="note">
        ※すべてのイベントを掲載できていない場合や、内容に誤りがある場合があります。最新の情報は、小平市や各主催者の公式発表をご確認ください。
      </p>
      <p class="note"><a href="/kodaira/events/">1週間分をすべて見る</a></p>
      <p class="note" id="updated"></p>
    </footer>

    <script>
      const WEEK = ['日', '月', '火', '水', '木', '金', '土'];
      const pad = (n) => String(n).padStart(2, '0');
      const keyOf = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
      const labelOf = (d) => `${d.getMonth() + 1}月${d.getDate()}日(${WEEK[d.getDay()]})`;

      const startTime = (place) => {
        const m = String(place).match(/(午前|午後)?\s*(\d{1,2})時(?:(\d{1,2})分|半)?/);
        if (!m) return '';
        let hour = Number(m[2]);
        const minute = m[3] ? Number(m[3]) : m[0].includes('半') ? 30 : 0;
        if (m[1] === '午後' && hour < 12) hour += 12;
        if (m[1] === '午前' && hour === 12) hour = 0;
        if (!m[1] && hour < 7) hour += 12;
        return `${pad(hour)}:${pad(minute)}`;
      };

      const venueOf = (place) => {
        const parts = String(place).split('/');
        return (parts.length > 1 ? parts[parts.length - 1] : '')
          .replace(/([^)]*)/g, '')
          .replace(/^注)/, '')
          .trim();
      };

      const esc = (s) =>
        String(s).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' })[c]);

      const render = (rows, key) => {
        const list = rows
          .filter((row) => row.dates.includes(key))
          .map((row) => ({ ...row, time: startTime(row.p), venue: venueOf(row.p) }))
          .sort((a, b) => (a.time || '99:99').localeCompare(b.time || '99:99'));
        if (list.length === 0) return '<p class="empty">予定はありません。</p>';
        return `<ul>${list
          .map(
            (row) =>
              `<li><div class="time">${esc(row.time)}</div><div class="body"><div class="name">${esc(
                row.t,
              )}</div>${
                row.venue ? `<div class="place">${esc(row.venue)}</div>` : ''
              }</div></li>`,
          )
          .join('')}</ul>`;
      };

      const today = new Date();
      const tomorrow = new Date(today);
      tomorrow.setDate(tomorrow.getDate() + 1);

      document.getElementById('range').textContent = `${labelOf(today)}〜${labelOf(tomorrow)}`;

      fetch('/kodaira/events/data.json')
        .then((res) => (res.ok ? res.json() : Promise.reject(new Error(String(res.status)))))
        .then((data) => {
          const rows = Array.isArray(data.rows) ? data.rows : [];
          document.getElementById('app').innerHTML = `
            <section><h2>今日 ${labelOf(today)}</h2>${render(rows, keyOf(today))}</section>
            <section><h2>明日 ${labelOf(tomorrow)}</h2>${render(rows, keyOf(tomorrow))}</section>`;
          const generated = data.generated ? new Date(data.generated) : null;
          if (generated && !Number.isNaN(generated.getTime())) {
            document.getElementById('updated').textContent =
              `データ更新:${generated.getFullYear()}年${generated.getMonth() + 1}月${generated.getDate()}日 ` +
              `${pad(generated.getHours())}:${pad(generated.getMinutes())}`;
          }
        })
        .catch(() => {
          document.getElementById('app').innerHTML =
            '<p class="empty">予定を読み込めませんでした。通信状態を確認して、もう一度開いてください。</p>';
        });
    </script>
  </body>
</html>