aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/components/ScheduleSeo.astro
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/ScheduleSeo.astro')
-rw-r--r--src/components/ScheduleSeo.astro31
1 files changed, 25 insertions, 6 deletions
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) =>