diff options
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/Updates.astro | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/components/Updates.astro b/src/components/Updates.astro index eaf159a..47278fe 100644 --- a/src/components/Updates.astro +++ b/src/components/Updates.astro @@ -6,12 +6,27 @@ type Update = { date: string; title: string; url: string; group: string }; const initial = Number(Astro.props.limit ?? 5); const step = Number(Astro.props.step ?? 10); const items = updates as Update[]; + +/** ISO の日付(YYYY-MM-DD)を「令和8年9月20日」の形にする */ +function toJapaneseDate(iso: string): string { + const [y, m, d] = iso.split("-").map(Number); + let era = "昭和"; + let n = y - 1925; + if (y >= 2019 && !(y === 2019 && m <= 4)) { + era = "令和"; + n = y - 2018; + } else if (y >= 1989) { + era = "平成"; + n = y - 1988; + } + return `${n === 1 ? `${era}元年` : `${era}${n}年`}${m}月${d}日`; +} --- <ul class="updates" data-updates data-step={step}> {items.map((u, index) => ( <li hidden={index >= initial}> - <time datetime={u.date}>{u.date.replace(/-/g, ".")}</time> + <time datetime={u.date}>{toJapaneseDate(u.date)}</time> {u.group && <span class="updates-group">{u.group}</span>} <a href={u.url}>{u.title}</a> </li> |
