Skip to content

Commit 033b1eb

Browse files
kaisugiclaude
andcommitted
Add last update date display from Git commit history
- Create git utility to fetch last commit timestamp - Display date in Japanese format (YYYY年M月D日) - Show last update date alongside recipe statistics 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 40cb746 commit 033b1eb

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

src/components/Stats.astro

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
---
22
import { recipes, getAllIngredients } from '../data/recipes';
3+
import { getLastUpdateDate } from '../utils/git';
34
45
const totalDishes = recipes.length;
56
const totalIngredients = getAllIngredients(recipes).length;
7+
const lastUpdated = getLastUpdateDate();
68
---
79

810
<div class="mt-8 pt-6 border-t border-gray-200 text-center text-sm text-gray-500">
9-
{totalDishes}品 / {totalIngredients}種類の食材
11+
<div>全{totalDishes}品 / {totalIngredients}種類の食材</div>
12+
<div class="mt-1">最終更新: {lastUpdated}</div>
1013
</div>

src/utils/git.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { execSync } from 'child_process';
2+
3+
/**
4+
* リポジトリの最終更新日を日本語形式で取得
5+
* @returns 日本語形式の日付(例: "2025年12月25日")、取得失敗時は "不明"
6+
*/
7+
export function getLastUpdateDate(): string {
8+
try {
9+
// Git コミットのタイムスタンプを取得(Unix timestamp)
10+
const timestampStr = execSync('git log -1 --format=%ct', {
11+
encoding: 'utf8',
12+
cwd: process.cwd(),
13+
}).trim();
14+
15+
const timestamp = parseInt(timestampStr, 10);
16+
17+
if (isNaN(timestamp)) {
18+
return '不明';
19+
}
20+
21+
// Unix timestampをミリ秒に変換してDateオブジェクト化
22+
const date = new Date(timestamp * 1000);
23+
24+
// 日本語形式にフォーマット
25+
const year = date.getFullYear();
26+
const month = date.getMonth() + 1;
27+
const day = date.getDate();
28+
29+
return `${year}${month}${day}日`;
30+
} catch (error) {
31+
console.warn('Failed to get last update date from Git:', error);
32+
return '不明';
33+
}
34+
}

0 commit comments

Comments
 (0)