26 lines
803 B
TypeScript
26 lines
803 B
TypeScript
const GITHUB_REPO_OWNER = 'MamunFarhat';
|
|
const GITHUB_REPO_NAME = 'aboutmamun';
|
|
const GITHUB_API_BASE_URL = `https://api.github.com/repos/${GITHUB_REPO_OWNER}/${GITHUB_REPO_NAME}`;
|
|
|
|
export async function fetchGithubJsonFile<T>(path: string): Promise<T | null> {
|
|
try {
|
|
const response = await fetch(`${GITHUB_API_BASE_URL}/contents/${path}`, {
|
|
headers: {
|
|
'Accept': 'application/vnd.github.v3.raw' // Request raw content
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
console.error(`Failed to fetch ${path}: ${response.status} ${response.statusText}`);
|
|
return null;
|
|
}
|
|
|
|
const textContent = await response.text();
|
|
return JSON.parse(textContent) as T;
|
|
|
|
} catch (error) {
|
|
console.error(`Error fetching GitHub JSON file from ${path}:`, error);
|
|
return null;
|
|
}
|
|
}
|