feat: improve landing page UI and add pprof port mapping

This commit is contained in:
tinkle-community
2026-01-01 13:09:54 +08:00
parent 13bc752e82
commit 74adedbc64
8 changed files with 676 additions and 337 deletions

View File

@@ -3,6 +3,7 @@ import { useState, useEffect } from 'react'
interface GitHubStats {
stars: number
forks: number
contributors: number
createdAt: string
daysOld: number
isLoading: boolean
@@ -13,6 +14,7 @@ export function useGitHubStats(owner: string, repo: string): GitHubStats {
const [stats, setStats] = useState<GitHubStats>({
stars: 0,
forks: 0,
contributors: 0,
createdAt: '',
daysOld: 0,
isLoading: true,
@@ -22,26 +24,52 @@ export function useGitHubStats(owner: string, repo: string): GitHubStats {
useEffect(() => {
const fetchGitHubStats = async () => {
try {
const response = await fetch(
`https://api.github.com/repos/${owner}/${repo}`
)
// Fetch basic repo info
const repoRes = await fetch(`https://api.github.com/repos/${owner}/${repo}`)
if (!repoRes.ok) throw new Error('Failed to fetch GitHub stats')
const repoData = await repoRes.json()
if (!response.ok) {
throw new Error('Failed to fetch GitHub stats')
// Fetch contributors count (using Link header trick for large numbers, or length for small)
// Since we can't easily parse Link header in client-side without exposing logic,
// we'll try a rough count or just a list length valid for first page (max 30 or 100).
// For a more accurate count without pagination, we often check the 'Link' header of:
// https://api.github.com/repos/{owner}/{repo}/contributors?per_page=1&anon=true
let contributorsCount = 0
try {
const contribRes = await fetch(`https://api.github.com/repos/${owner}/${repo}/contributors?per_page=1&anon=true`)
const linkHeader = contribRes.headers.get('Link')
if (linkHeader) {
const match = linkHeader.match(/page=(\d+)>; rel="last"/)
if (match) {
contributorsCount = parseInt(match[1])
}
}
// If no link header, it means 1 page.
if (contributorsCount === 0 && contribRes.ok) {
// Fetch list to count (default page size 30)
// actually per_page=1 returns 1.
// We should fetch with per_page=100 to get exact count if <100.
const listRes = await fetch(`https://api.github.com/repos/${owner}/${repo}/contributors?per_page=100&anon=true`)
if (listRes.ok) {
const list = await listRes.json()
contributorsCount = list.length
}
}
} catch (e) {
console.warn('Failed to fetch contributors:', e)
}
const data = await response.json()
// Calculate days since creation
const createdDate = new Date(data.created_at)
const createdDate = new Date(repoData.created_at)
const now = new Date()
const diffTime = Math.abs(now.getTime() - createdDate.getTime())
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))
setStats({
stars: data.stargazers_count,
forks: data.forks_count,
createdAt: data.created_at,
stars: repoData.stargazers_count,
forks: repoData.forks_count,
contributors: contributorsCount > 0 ? contributorsCount : 0, // Fallback
createdAt: repoData.created_at,
daysOld: diffDays,
isLoading: false,
error: null,