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'; -小平市のイベントと審議会等・市議会の開催予定を、カレンダー・地図・一覧表でまとめています。[多くの情報源](#情報源)から取得したものです。延期・中止・会場変更の可能性もありますので、最新状況は、それぞれのお問い合わせ先へご確認ください。このページに問い合わせ先の記載がないものは、市報こだいら10月20日号や市の[「各課の電話番号一覧」](https://www.city.kodaira.tokyo.jp/contact-info/index.html)などをご覧ください。 +小平市のイベントと審議会等・市議会の開催予定を、カレンダー・地図・一覧表でまとめています。[多くの情報源](#情報源)から取得したものです。延期・中止・会場変更の可能性もありますので、最新状況は、それぞれのお問い合わせ先へご確認ください。このページに問い合わせ先の記載がないものは、市報こだいらや市の[「各課の電話番号一覧」](https://www.city.kodaira.tokyo.jp/contact-info/index.html)などをご覧ください。
diff --git a/src/data/schedule/content-files.mjs b/src/data/schedule/content-files.mjs new file mode 100644 index 0000000..fa87e5e --- /dev/null +++ b/src/data/schedule/content-files.mjs @@ -0,0 +1,16 @@ +// 行事予定ページ(/kodaira/events/)の内容を構成するファイル。 +// ページ冒頭の「最終更新」、JSON-LD の dateModified、サイトマップの lastmod で +// 同じリストを使う(表示と構造化データの日付がずれないようにするため)。 +export const SCHEDULE_PAGE_FILES = [ + 'src/content/docs/kodaira/events.mdx', + 'src/data/schedule/events.json', + 'src/data/schedule/meetings.json', + 'src/data/schedule/config.ts', + 'src/components/ScheduleInteractive.astro', + 'src/components/ScheduleMap.astro', + 'src/components/ScheduleMonthLinks.astro', + 'src/components/ScheduleSeo.astro', + 'src/components/ScheduleTable.astro', + 'src/lib/schedule-dates.ts', + 'src/lib/schedule-months.ts', +]; diff --git a/src/data/updates.json b/src/data/updates.json index ade1379..30fd446 100644 --- a/src/data/updates.json +++ b/src/data/updates.json @@ -35,7 +35,7 @@ "kind": "update" }, { - "title": "こだいら 公園さんぽマップ", + "title": "こだいら 公園さんぽマップβ", "url": "/kodaira-data/parks/", "group": "", "date": "2026-11-03", @@ -224,7 +224,7 @@ "kind": "update" }, { - "title": "こだいら 公園さんぽマップ", + "title": "こだいら 公園さんぽマップβ", "url": "/kodaira-data/parks/", "group": "", "date": "2026-10-06", -- cgit v1.3.1