chore(website): add social media link; add star

This commit is contained in:
Simon
2026-03-13 20:23:13 +08:00
parent 0a160697d1
commit 5695b3d6aa
5 changed files with 65 additions and 8 deletions

View File

@@ -0,0 +1,27 @@
import { useEffect, useState } from 'react'
const STATS_URL = 'https://page-agent.github.io/gh-stats/stats.json'
let cached: number | null = null
export function useGitHubStars() {
const [stars, setStars] = useState(cached)
useEffect(() => {
if (cached !== null) return
fetch(STATS_URL)
.then((r) => r.json())
.then((data) => {
cached = data.stargazers_count ?? null
setStars(cached)
})
.catch(() => {})
}, [])
return stars
}
export function formatStars(n: number): string {
if (n >= 1000) return `${(n / 1000).toFixed(1).replace(/\.0$/, '')}k`
return String(n)
}