From f6bdca7dea59e81006a659676a00aae10d2cec58 Mon Sep 17 00:00:00 2001
From: Yasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com>
Date: Sat, 7 Nov 2026 21:46:24 +0900
Subject: events: 最終更新の日時を1か所に統一
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
ページ冒頭はビルド時刻、末尾はStarlight標準のgit日時と、2つの日付が
並んでいた。冒頭の表示を内容(ページと予定データ・関連コンポーネント)
の最終コミット時刻にし、dateModifiedとサイトマップのlastmodも同じ
値にそろえた。末尾の重複表示は lastUpdated: false で止めた。
---
src/components/ScheduleSeo.astro | 31 +++++++++++++++++++++++++------
src/content/docs/kodaira/events.mdx | 3 ++-
src/data/schedule/content-files.mjs | 16 ++++++++++++++++
src/data/updates.json | 4 ++--
4 files changed, 45 insertions(+), 9 deletions(-)
create mode 100644 src/data/schedule/content-files.mjs
(limited to 'src')
diff --git a/src/components/ScheduleSeo.astro b/src/components/ScheduleSeo.astro
index b87ec5b..fcf6898 100644
--- a/src/components/ScheduleSeo.astro
+++ b/src/components/ScheduleSeo.astro
@@ -1,15 +1,33 @@
---
-// このページの構造化データ(JSON-LD)。ビルド日を更新日として出力する。
+// このページの構造化データ(JSON-LD)と「最終更新」。
+// 更新日は、ページ本体と予定データのうち最後にコミットされた時刻を使う。
+// (ビルド時刻を使うと、内容が変わっていなくても日付が動いてしまうため)
+import { execSync } from 'node:child_process';
import { scheduleAbsoluteUrl } from '@/data/schedule/config';
import events from '@/data/schedule/events.json';
import { entryDates } from '@/lib/schedule-dates';
+import { SCHEDULE_PAGE_FILES } from '@/data/schedule/content-files.mjs';
// URLは src/data/schedule/config.ts で一元管理している(ページ移転時はそこだけ変える)
const url = scheduleAbsoluteUrl();
-const updated = new Date();
+
+function lastCommitDate(): Date {
+ try {
+ const out = execSync(`git log -1 --format=%cI -- ${SCHEDULE_PAGE_FILES.join(' ')}`, {
+ encoding: 'utf-8',
+ }).trim();
+ if (out) return new Date(out);
+ } catch {
+ // git が使えない環境ではビルド時刻にする
+ }
+ return new Date();
+}
+
+const updated = lastCommitDate();
+const now = new Date();
const pad = (n: number) => String(n).padStart(2, '0');
-// 表示は日本時間のビルド時刻。dateModified はタイムゾーン付きで出す。
+// 表示は日本時間。dateModified はタイムゾーン付きで出す。
const year = updated.getFullYear();
const month = updated.getMonth() + 1;
const day = updated.getDate();
@@ -18,12 +36,13 @@ const label = `${year}年${month}月${day}日 ${pad(updated.getHours())}:${pad(u
const offsetMinutes = -updated.getTimezoneOffset();
const offsetSign = offsetMinutes >= 0 ? '+' : '-';
const offsetAbs = Math.abs(offsetMinutes);
-const isoDateTime = `${iso}T${pad(updated.getHours())}:${pad(updated.getMinutes())}:00${offsetSign}${pad(Math.floor(offsetAbs / 60))}:${pad(offsetAbs % 60)}`;
+const isoDateTime = `${iso}T${pad(updated.getHours())}:${pad(updated.getMinutes())}:${pad(updated.getSeconds())}${offsetSign}${pad(Math.floor(offsetAbs / 60))}:${pad(offsetAbs % 60)}`;
-const todayKey = iso;
+// 「これからの予定」は、ビルドした日を基準にする。
+const todayKey = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
// 構造化データに入れるのは、ビルド日から1週間先までの予定(近い予定に絞る)
-const until = new Date(updated.getFullYear(), updated.getMonth(), updated.getDate() + 7);
+const until = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 7);
const untilKey = `${until.getFullYear()}-${pad(until.getMonth() + 1)}-${pad(until.getDate())}`;
const stripTags = (value: string) =>
diff --git a/src/content/docs/kodaira/events.mdx b/src/content/docs/kodaira/events.mdx
index 342736e..36fdf36 100644
--- a/src/content/docs/kodaira/events.mdx
+++ b/src/content/docs/kodaira/events.mdx
@@ -2,6 +2,7 @@
title: 小平市のイベント・行事予定カレンダー(審議会・市議会の日程も掲載)
description: 小平市のイベント・行事予定を月ごとのカレンダーで見られます。審議会・市議会の日程・会場・申込期限を一覧にし、カテゴリ別の絞り込みと地図で確認できます。
tableOfContents: true
+lastUpdated: false
head:
- tag: link
attrs:
@@ -19,7 +20,7 @@ import ScheduleMonthLinks from '../../../components/ScheduleMonthLinks.astro';