mirror of
https://github.com/avinal/avinal.github.io.git
synced 2026-07-04 07:40:09 +05:30
feat: redesign my webiste from scratch
- remove hugo and paper box theme - inspiration https://jay.fish - use astro based system Signed-off-by: Avinal Kumar <avinal.xlvii@gmail.com>
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
const GITHUB_USER = "avinal";
|
||||
|
||||
export interface GitHubUser {
|
||||
login: string;
|
||||
name: string;
|
||||
bio: string;
|
||||
avatar_url: string;
|
||||
public_repos: number;
|
||||
followers: number;
|
||||
}
|
||||
|
||||
export interface GitHubRepo {
|
||||
name: string;
|
||||
description: string | null;
|
||||
html_url: string;
|
||||
stargazers_count: number;
|
||||
language: string | null;
|
||||
fork: boolean;
|
||||
topics: string[];
|
||||
}
|
||||
|
||||
export interface ContributionDay {
|
||||
date: string;
|
||||
count: number;
|
||||
level: number; // 0-4
|
||||
}
|
||||
|
||||
export interface ContributionData {
|
||||
total: number;
|
||||
weeks: ContributionDay[][];
|
||||
}
|
||||
|
||||
export async function fetchGitHubUser(): Promise<GitHubUser | null> {
|
||||
try {
|
||||
const res = await fetch(`https://api.github.com/users/${GITHUB_USER}`, {
|
||||
headers: { Accept: "application/vnd.github.v3+json" },
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
return await res.json();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchGitHubRepos(): Promise<GitHubRepo[]> {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`https://api.github.com/users/${GITHUB_USER}/repos?sort=stars&per_page=8&type=owner`,
|
||||
{ headers: { Accept: "application/vnd.github.v3+json" } },
|
||||
);
|
||||
if (!res.ok) return [];
|
||||
const repos: GitHubRepo[] = await res.json();
|
||||
return repos.filter((r) => !r.fork).sort((a, b) => b.stargazers_count - a.stargazers_count);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchContributions(): Promise<ContributionData | null> {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`https://github-contributions-api.jogruber.de/v4/${GITHUB_USER}?y=last`,
|
||||
);
|
||||
if (!res.ok) return null;
|
||||
const data = await res.json();
|
||||
|
||||
const contributions: ContributionDay[][] = [];
|
||||
let weekBucket: ContributionDay[] = [];
|
||||
let total = 0;
|
||||
|
||||
for (const c of data.contributions) {
|
||||
total += c.count;
|
||||
const day: ContributionDay = {
|
||||
date: c.date,
|
||||
count: c.count,
|
||||
level: c.level,
|
||||
};
|
||||
weekBucket.push(day);
|
||||
if (weekBucket.length === 7) {
|
||||
contributions.push(weekBucket);
|
||||
weekBucket = [];
|
||||
}
|
||||
}
|
||||
if (weekBucket.length > 0) contributions.push(weekBucket);
|
||||
|
||||
return { total, weeks: contributions };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user