This commit is contained in:
NotII
2025-04-07 19:25:24 +01:00
parent 7f7dd78818
commit 2f48ee38c2
102 changed files with 1825 additions and 761 deletions

50
lib/utils/git.ts Normal file
View File

@@ -0,0 +1,50 @@
// Git utility functions
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: process.env.NEXT_PUBLIC_GIT_HASH || 'dev',
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();
}