aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com>2026-09-22 11:32:31 +0900
committerYasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com>2026-09-22 11:32:31 +0900
commitee00a2355ff79048f7770d1a56c4f9e29eb6466a (patch)
tree5d749cf690b22c8b72035966208a1378b066953a
parent0ed3c09e909f3adafa7d81313e9aeb63a2727605 (diff)
Footer.astro: 最終更新日を和暦表記にする
Starlight の LastUpdated コンポーネント上書きが効かなかったため、Footer 内で令和・平成表記に整形して直接描画するようにした。
-rw-r--r--src/components/starlight/Footer.astro32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/components/starlight/Footer.astro b/src/components/starlight/Footer.astro
index 5b59d09..e553e60 100644
--- a/src/components/starlight/Footer.astro
+++ b/src/components/starlight/Footer.astro
@@ -1,6 +1,5 @@
---
import EditLink from 'virtual:starlight/components/EditLink';
-import LastUpdated from 'virtual:starlight/components/LastUpdated';
import Pagination from 'virtual:starlight/components/Pagination';
import config from 'virtual:starlight/user-config';
import { Icon } from '@astrojs/starlight/components';
@@ -12,6 +11,28 @@ const caption = shareCaption(
route.entry?.slug || route.id || '',
route.entry?.data?.title,
);
+
+/** Date を「令和8年9月22日 11:14」の形にする(ローカル時刻) */
+function toJapaneseDateTime(date: Date): string {
+ const y = date.getFullYear();
+ const m = date.getMonth() + 1;
+ const d = date.getDate();
+ let era = '昭和';
+ let n = y - 1925;
+ if (y > 2019 || (y === 2019 && m >= 5)) {
+ era = '令和';
+ n = y - 2018;
+ } else if (y >= 1989) {
+ era = '平成';
+ n = y - 1988;
+ }
+ const year = n === 1 ? `${era}元年` : `${era}${n}年`;
+ const hh = String(date.getHours()).padStart(2, '0');
+ const mm = String(date.getMinutes()).padStart(2, '0');
+ return `${year}${m}月${d}日 ${hh}:${mm}`;
+}
+
+const lastUpdated = route.lastUpdated;
---
<footer class="sl-flex">
@@ -19,7 +40,14 @@ const caption = shareCaption(
<div class="meta sl-flex">
<EditLink />
- <LastUpdated />
+ {
+ lastUpdated && (
+ <p>
+ {Astro.locals.t('page.lastUpdated')}{' '}
+ <time datetime={lastUpdated.toISOString()}>{toJapaneseDateTime(lastUpdated)}</time>
+ </p>
+ )
+ }
</div>
<Pagination />