Files
2025-04-08 01:32:00 +01:00

50 lines
1.2 KiB
TypeScript

import gInfo from "../../public/git-info.json"
interface GitInfo {
hash: string;
date: string;
message: string;
}
// Default git info if file is not found
const defaultGitInfo: GitInfo = {
hash: 'local-dev',
date: new Date().toISOString(),
message: 'Local development build',
};
/**
* Get git info - safely handles cases where the JSON file isn't available
*/
export function getGitInfo(): GitInfo {
try {
// In production builds, the git info should be available
// In development, we'll use default values
const gitInfo = {
hash: gInfo.commitHash,
date: process.env.NEXT_PUBLIC_GIT_DATE || new Date().toISOString(),
message: process.env.NEXT_PUBLIC_GIT_MESSAGE || 'Development build',
};
return gitInfo;
} catch (error) {
console.warn('Could not load git info, using defaults', error);
return defaultGitInfo;
}
}
/**
* Get a shorter git hash for display
*/
export function getShortGitHash(): string {
const { hash } = getGitInfo();
return hash.substring(0, 7);
}
/**
* Format git commit date for display
*/
export function getFormattedGitDate(): string {
const { date } = getGitInfo();
return new Date(date).toLocaleDateString();
}