From d99e57c263c63b77f4d297261450e62325957c68 Mon Sep 17 00:00:00 2001 From: yyamashita Date: Mon, 1 Jun 2026 22:13:23 +0900 Subject: Show today's (JST) events only, add link to by-date page Co-Authored-By: Claude Sonnet 4.6 --- scripts/send-recap.ts | 74 +++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 47 deletions(-) diff --git a/scripts/send-recap.ts b/scripts/send-recap.ts index 5a11d0a..232ea76 100644 --- a/scripts/send-recap.ts +++ b/scripts/send-recap.ts @@ -1,8 +1,8 @@ #!/usr/bin/env node /** * Daily live event recap mailer. - * Queries upcoming events (tomorrow + 6 days) from SQLite and sends an HTML - * digest via the internal Postfix container (mail:25 on the web Docker network). + * Queries today's events (JST) from SQLite and sends an HTML digest via the + * internal Postfix container (mail:25 on the web Docker network). * * Env vars: * DB_PATH path to SQLite database (default: /app/data/events.db) @@ -19,7 +19,7 @@ const MAIL_HOST = process.env.MAIL_HOST ?? "mail"; const MAIL_PORT = parseInt(process.env.MAIL_PORT ?? "25", 10); const FROM = "noreply@golive.yyamashita.com"; const TO = process.env.RECAP_TO ?? "efemeraladdress+golive@gmail.com"; -const DAYS = 7; +const APP_URL = "https://golive.yyamashita.com"; // ---- date helpers (JST = UTC+9) ---------------------------------------- @@ -34,12 +34,6 @@ function isoDate(d: Date): string { return new Date(d.getTime() + JST_MS).toISOString().slice(0, 10); } -function addDays(d: Date, n: number): Date { - const r = new Date(d); - r.setUTCDate(r.getUTCDate() + n); - return r; -} - function fmtJST(dateStr: string): string { const DOW = ["日", "月", "火", "水", "木", "金", "土"]; // Parse as JST midnight @@ -89,7 +83,8 @@ function esc(s: string): string { .replace(/"/g, """); } -function buildHtml(events: EventRow[], from: string, to: string): string { +function buildHtml(events: EventRow[], date: string): string { + const pageUrl = `${APP_URL}/events/by-date?date=${date}`; const head = ` @@ -97,7 +92,6 @@ function buildHtml(events: EventRow[], from: string, to: string): string { -

東京ライブハウス 週間イベント

-

${esc(fmtJST(from))} 〜 ${esc(fmtJST(to))} のイベント一覧

+

東京ライブハウス ${esc(fmtJST(date))} のライブ

+

${esc(pageUrl)}

`; if (events.length === 0) { - return ( - head + - `

この期間のイベントはまだ登録されていません。

` - ); + return head + `

本日のイベントはまだ登録されていません。

`; } - const byDate = new Map(); + let body = `\n\n`; for (const e of events) { - const list = byDate.get(e.date) ?? []; - list.push(e); - byDate.set(e.date, list); - } - - let body = ""; - for (const [date, rows] of byDate) { - body += `

${esc(fmtJST(date))} ${rows.length} 件

\n`; - body += `
会場アーティスト / タイトル開演料金リンク
\n\n`; - for (const e of rows) { - const nameCell = e.artist - ? `${esc(e.artist)}
${esc(e.title)}` - : `${esc(e.title)}`; - const time = e.start_time ? esc(e.start_time) : `-`; - const price = e.price ? esc(e.price) : `-`; - const url = e.ticket_url ?? e.source_url; - const link = url - ? `詳細` - : `-`; - body += `\n`; - } - body += `
会場アーティスト / タイトル開演料金リンク
${esc(e.venue_name)}${nameCell}${time}${price}${link}
\n`; + const nameCell = e.artist + ? `${esc(e.artist)}
${esc(e.title)}` + : `${esc(e.title)}`; + const time = e.start_time ? esc(e.start_time) : `-`; + const price = e.price ? esc(e.price) : `-`; + const url = e.ticket_url ?? e.source_url; + const link = url + ? `詳細` + : `-`; + body += `${esc(e.venue_name)}${nameCell}${time}${price}${link}\n`; } + body += `\n`; + body += `\n`; return head + body + ``; } @@ -255,16 +237,14 @@ function smtpSend( // ---- main --------------------------------------------------------------- async function main() { - const today = nowJST(); - const from = isoDate(addDays(today, 1)); // tomorrow - const to = isoDate(addDays(today, DAYS)); // 7 days out + const date = isoDate(nowJST()); - console.log(`[recap] querying events ${from} – ${to}`); - const events = fetchEvents(from, to); + console.log(`[recap] querying events for ${date}`); + const events = fetchEvents(date, date); console.log(`[recap] ${events.length} events found`); - const subject = `東京ライブハウス ${fmtJST(from).slice(5, 10)} 〜 ${fmtJST(to).slice(5, 10)} のイベント(${events.length} 件)`; - const html = buildHtml(events, from, to); + const subject = `東京ライブハウス ${fmtJST(date)} のライブ(${events.length} 件)`; + const html = buildHtml(events, date); const message = buildMessage(subject, html); console.log(`[recap] sending to ${TO} via ${MAIL_HOST}:${MAIL_PORT}`); -- cgit v1.2.3