mirror of
https://github.com/mmahdium/portfolio.git
synced 2026-08-17 05:24:30 +03:30
feat: Implement initial portfolio website structure with components for various sections, i18n, and GitHub integration.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import type { GitHubApiResponse, GitHubContributionCalendar } from '@/types/github'
|
||||
|
||||
/**
|
||||
* Composable for fetching GitHub contribution calendar data
|
||||
* Based on: https://github.com/yuichkun/github-contribution-graph-example
|
||||
* Uses server-side API to avoid CORS and token exposure issues
|
||||
*/
|
||||
export const useGitHubContributions = () => {
|
||||
const fetchContributions = async (username: string): Promise<GitHubContributionCalendar | null> => {
|
||||
try {
|
||||
// Use our server API endpoint instead of calling GitHub directly
|
||||
const response = await $fetch<GitHubApiResponse>('/api/github/contributions', {
|
||||
params: { username }
|
||||
})
|
||||
|
||||
// Extract contribution calendar from response
|
||||
// Structure: { data: { user: { contributionsCollection: { contributionCalendar: {...} } } } }
|
||||
if (response?.data?.user?.contributionsCollection?.contributionCalendar) {
|
||||
return response.data.user.contributionsCollection.contributionCalendar
|
||||
}
|
||||
|
||||
console.error('Invalid response structure:', response)
|
||||
return null
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch GitHub contributions:', error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
fetchContributions
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user