summaryrefslogtreecommitdiffhomepage
path: root/scripts/update-library-dates.mjs
diff options
context:
space:
mode:
authorYasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com>2026-11-23 09:42:59 +0900
committerYasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com>2026-11-23 09:42:59 +0900
commitbe3c9c978843453c46a599792450d9750d005630 (patch)
treeb39f2a696f2a26db7dbe7f580d8af5c2f30ded15 /scripts/update-library-dates.mjs
parent62dbaa5be02a22cd97a828c8b1309d0459b8c777 (diff)
events.json: 図書館・小金井公園・ふるさと村の新着を反映
- 障害者週間特別展示(11/28〜12/16、市内全図書館)を追加 - 小金井公園 防災フェスタ2026(12/6)を追加 - 小平ふるさと村 お芝居ワークショップ「ひみつきち」(12/12・13)を追加 - update-library-dates.mjs を events.json 対応に修正(ページ移転で動かなくなっていた)
Diffstat (limited to 'scripts/update-library-dates.mjs')
-rw-r--r--scripts/update-library-dates.mjs32
1 files changed, 15 insertions, 17 deletions
diff --git a/scripts/update-library-dates.mjs b/scripts/update-library-dates.mjs
index 2317b17..74b9302 100644
--- a/scripts/update-library-dates.mjs
+++ b/scripts/update-library-dates.mjs
@@ -25,7 +25,7 @@ const targetIdx = args.indexOf('--target');
const targetPath =
targetIdx >= 0
? args[targetIdx + 1]
- : path.join('src', 'content', 'docs', 'kodaira-data', 'hp-archive', 'schedule.mdx');
+ : path.join('src', 'data', 'schedule', 'events.json');
async function fetchText(url) {
const res = await fetch(url, { headers: { 'User-Agent': UA } });
@@ -99,30 +99,28 @@ function formatDates(dateKeys, withWeekday) {
}
// 図書館のページ(info.html?id=…)を出典に含む行を対象にする。
-// 市報など他の出典と併記している行(例:「市報こだいら10月20日号3面/[図書館のページ](…)」)も拾う。
-const ROW_RE =
- /^\| ([^|]*) \| ([^|]*) \| ([^|]*) \| ([^|]*) \| ([^|]*library\.kodaira\.ed\.jp\/viewer\/info\.html\?id=(\d+)[^|]*) \|$/;
+// 市報など他の出典と併記している行(例:「市報こだいら10月20日号3面/<a …info.html?id=…>」)も拾う。
+const LIB_SOURCE_RE = /library\.kodaira\.ed\.jp\/viewer\/info\.html\?id=(\d+)/;
async function main() {
const events = await collectEvents();
- const src = fs.readFileSync(targetPath, 'utf8');
- const lines = src.split('\n');
+ const data = JSON.parse(fs.readFileSync(targetPath, 'utf8'));
+ const rows = data.rows;
const inTable = new Map();
const changes = [];
- lines.forEach((line, index) => {
- // Windows の CRLF でも一致するよう、照合時だけ行末の \r を除く
- const m = line.replace(/\r$/, '').match(ROW_RE);
- if (!m) return;
- const [, datesCell, name, , , , id] = m;
- inTable.set(id, { index, name, datesCell });
+ for (const row of rows) {
+ const m = (row.source || '').match(LIB_SOURCE_RE);
+ if (!m) continue;
+ const id = m[1];
+ inTable.set(id, { name: row.title, datesCell: row.date, row });
const ev = events.get(id);
- if (!ev || ev.dates.size === 0) return;
+ if (!ev || ev.dates.size === 0) continue;
const next = formatDates(ev.dates, ev.dates.size === 1);
- if (next !== datesCell) changes.push({ index, name, id, from: datesCell, to: next });
- });
+ if (next !== row.date) changes.push({ name: row.title, id, from: row.date, to: next, row });
+ }
console.log(`図書館の予定: カレンダー ${events.size}件 / 表 ${inTable.size}件(${months}か月分を取得)`);
@@ -133,7 +131,7 @@ async function main() {
console.log(`- ${c.name}`);
console.log(` 現在: ${c.from}`);
console.log(` 新規: ${c.to}`);
- if (apply) lines[c.index] = lines[c.index].replace(`| ${c.from} |`, `| ${c.to} |`);
+ if (apply) c.row.date = c.to;
}
}
@@ -152,7 +150,7 @@ async function main() {
}
if (apply && changes.length > 0) {
- fs.writeFileSync(targetPath, lines.join('\n'), 'utf8');
+ fs.writeFileSync(targetPath, JSON.stringify(data, null, 2) + '\n', 'utf8');
console.log(`\n${changes.length}件を ${targetPath} に反映しました。`);
} else if (!apply && changes.length > 0) {
console.log('\n(--apply を付けると反映します)');