feat: Implement initial portfolio website structure with components for various sections, i18n, and GitHub integration.

This commit is contained in:
mahdiarghyani
2025-12-13 12:59:24 +03:30
parent e11a59f02d
commit bda5f86a79
26 changed files with 547 additions and 82 deletions
+75
View File
@@ -0,0 +1,75 @@
import type { GitHubApiResponse } from '@/types/github'
/**
* GitHub Contributions API Endpoint
* Based on: https://github.com/yuichkun/github-contribution-graph-example
*
* Fetches contribution calendar data using GitHub GraphQL API
* EXACTLY as shown in the reference implementation
*/
export default defineEventHandler(async (event): Promise<GitHubApiResponse> => {
const config = useRuntimeConfig()
const query = getQuery(event)
const username = query.username as string
if (!username) {
throw createError({
statusCode: 400,
message: 'Username is required'
})
}
// GraphQL query - EXACTLY as in reference (no date range!)
const graphqlQuery = `
query($userName:String!) {
user(login: $userName){
contributionsCollection {
contributionCalendar {
totalContributions
weeks {
contributionDays {
contributionCount
date
}
}
}
}
}
}
`
try {
const headers: Record<string, string> = {}
// Add authorization token (EXACTLY as in reference)
if (config.public.githubToken) {
headers['Authorization'] = `Bearer ${config.public.githubToken}`
}
// Make GraphQL request (EXACTLY as in reference)
const response = await $fetch<GitHubApiResponse>('https://api.github.com/graphql', {
method: 'POST',
headers,
body: JSON.stringify({
query: graphqlQuery,
variables: `
{
"userName": "${username}"
}
`
})
})
console.log(`Fetched contributions for ${username}:`, response.data?.user?.contributionsCollection?.contributionCalendar?.totalContributions)
// Return the response (structure: { data: { user: { contributionsCollection: ... } } })
return response
} catch (error: any) {
console.error('GitHub API Error:', error)
throw createError({
statusCode: error.statusCode || 500,
message: error.message || 'Failed to fetch GitHub contributions'
})
}
})