mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
feat(frontend): show the product, keep work across sign-in, add social preview
Of 27 people who typed a username in the last 14 days, 15 left before a widget rendered. The landing page showed zero pixels of a product whose entire value is visual, so it now leads with a live example card and says concretely what you get. Sign-in used to discard everything: with no router the OAuth `next` is always "/", so users came back to an empty search box with their theme, widget order and achievements gone. Persist work-in-progress to sessionStorage and restore it on mount. The Workshop preview seeds from demo data (grade A, 842 commits, collaborators named alex/jordan/sam) with nothing saying so, so users saw numbers they knew were wrong. Label it until real data arrives. Add title, description, canonical, OG and Twitter tags, robots.txt and a sitemap. The page was a 445-byte shell titled "GitHub Widgets", so every link shared anywhere rendered with no image and no description. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BwMoSbmK77Ph7XaV5YnAdS
This commit is contained in:
@@ -4,7 +4,25 @@
|
||||
<meta charset="UTF-8"/>
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title>GitHub Widgets</title>
|
||||
<title>gh-stats - one stats card for your GitHub profile README</title>
|
||||
<meta name="description"
|
||||
content="Drop one line into your GitHub profile README and get a single SVG card: your score, contribution timeline, top collaborators, language breakdown, commit streaks and auto-awarded tags. Free, no signup needed."/>
|
||||
<link rel="canonical" href="https://gh-stats.com/"/>
|
||||
<meta property="og:type" content="website"/>
|
||||
<meta property="og:site_name" content="gh-stats"/>
|
||||
<meta property="og:url" content="https://gh-stats.com/"/>
|
||||
<meta property="og:title" content="One stats card for your GitHub profile README"/>
|
||||
<meta property="og:description"
|
||||
content="Score, contribution timeline, top collaborators, languages, streaks and tags. One line of markdown, five themes, no signup."/>
|
||||
<meta property="og:image" content="https://gh-stats.com/og.png"/>
|
||||
<meta property="og:image:width" content="1200"/>
|
||||
<meta property="og:image:height" content="630"/>
|
||||
<meta property="og:image:alt" content="A gh-stats card on a GitHub profile README."/>
|
||||
<meta name="twitter:card" content="summary_large_image"/>
|
||||
<meta name="twitter:title" content="One stats card for your GitHub profile README"/>
|
||||
<meta name="twitter:description"
|
||||
content="Score, contribution timeline, top collaborators, languages, streaks and tags. One line of markdown, five themes, no signup."/>
|
||||
<meta name="twitter:image" content="https://gh-stats.com/og.png"/>
|
||||
<script type="module">
|
||||
// Import the functions you need from the SDKs you need
|
||||
import {initializeApp} from "https://www.gstatic.com/firebasejs/12.13.0/firebase-app.js";
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 105 KiB |
@@ -0,0 +1,3 @@
|
||||
User-agent: *
|
||||
Allow: /
|
||||
Sitemap: https://gh-stats.com/sitemap.xml
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<url>
|
||||
<loc>https://gh-stats.com/</loc>
|
||||
<changefreq>weekly</changefreq>
|
||||
<priority>1.0</priority>
|
||||
</url>
|
||||
</urlset>
|
||||
@@ -51,6 +51,27 @@ const DEFAULT_SETTINGS: WidgetSettings = {
|
||||
|
||||
type Step = 'search' | 'workshop' | 'result'
|
||||
|
||||
// Signing in navigates the whole tab through GitHub's OAuth flow, and the
|
||||
// SPA keeps username + settings only in React state, so without this the
|
||||
// user comes back to an empty search box with their edits gone.
|
||||
// sessionStorage survives the round trip within the tab.
|
||||
const RESUME_KEY = 'gh-stats:in-progress'
|
||||
|
||||
type Resume = { username: string; settings: WidgetSettings }
|
||||
|
||||
function loadResume(): Resume | null {
|
||||
try {
|
||||
const raw = sessionStorage.getItem(RESUME_KEY)
|
||||
if (!raw) return null
|
||||
const parsed = JSON.parse(raw) as Partial<Resume> | null
|
||||
if (!parsed || typeof parsed.username !== 'string' || !parsed.username) return null
|
||||
if (!parsed.settings || typeof parsed.settings !== 'object') return null
|
||||
return { username: parsed.username, settings: { ...DEFAULT_SETTINGS, ...parsed.settings } }
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
const POLL_INTERVAL_MS = 2000
|
||||
const POLL_TIMEOUT_MS = 120_000
|
||||
// ResultScreen poll: a bit slower than the workshop poll because each tick
|
||||
@@ -74,9 +95,11 @@ export default function App() {
|
||||
return <DevScreen />
|
||||
}
|
||||
const [me, setMe] = useState<Me>({ login: null })
|
||||
const [step, setStep] = useState<Step>('search')
|
||||
const [username, setUsername] = useState('')
|
||||
const [settings, setSettings] = useState<WidgetSettings>({ ...DEFAULT_SETTINGS })
|
||||
// Work in progress left behind by a sign-in redirect, if any.
|
||||
const [resumed] = useState(loadResume)
|
||||
const [step, setStep] = useState<Step>(resumed ? 'workshop' : 'search')
|
||||
const [username, setUsername] = useState(resumed?.username ?? '')
|
||||
const [settings, setSettings] = useState<WidgetSettings>(resumed?.settings ?? { ...DEFAULT_SETTINGS })
|
||||
const [widgetData, setWidgetData] = useState<WidgetData | null>(null)
|
||||
const [fetchDone, setFetchDone] = useState(false)
|
||||
const [fetchError, setFetchError] = useState<string | null>(null)
|
||||
@@ -155,7 +178,10 @@ export default function App() {
|
||||
return stopResultPolling
|
||||
}, [step, widgetStatus, embedUrl, refetchEmbed, stopResultPolling])
|
||||
|
||||
const startFetch = useCallback((user: string) => {
|
||||
// `keepSettings` is set when resuming after a sign-in redirect: the
|
||||
// settings already on screen are the user's own unsaved edits, so neither
|
||||
// the reset nor the server hydration below may overwrite them.
|
||||
const startFetch = useCallback((user: string, keepSettings = false) => {
|
||||
stopPolling()
|
||||
aborted.current = false
|
||||
pollStart.current = Date.now()
|
||||
@@ -165,12 +191,12 @@ export default function App() {
|
||||
setWidgetData(DEMO_WIDGET_DATA)
|
||||
// Reset to defaults first so the form doesn't briefly show the previous
|
||||
// user's settings while we fetch this user's saved blob.
|
||||
setSettings({ ...DEFAULT_SETTINGS })
|
||||
if (!keepSettings) setSettings({ ...DEFAULT_SETTINGS })
|
||||
|
||||
// Hydrate the Workshop form from the user's persisted settings.
|
||||
// Backend stores snake_case keys; we map them onto the camelCase
|
||||
// state shape here. 404 (not enrolled yet) is expected — keep defaults.
|
||||
void (async () => {
|
||||
if (!keepSettings) void (async () => {
|
||||
try {
|
||||
const r = await fetch(`/api/${encodeURIComponent(user)}/settings`, {
|
||||
credentials: 'include',
|
||||
@@ -258,6 +284,24 @@ export default function App() {
|
||||
poll()
|
||||
}, [stopPolling])
|
||||
|
||||
// Keep the in-progress username and settings recoverable across the
|
||||
// sign-in redirect (and a plain reload). Cleared once the user is back
|
||||
// on the search screen, so a fresh visit starts fresh.
|
||||
useEffect(() => {
|
||||
try {
|
||||
if (step === 'search' || !username) sessionStorage.removeItem(RESUME_KEY)
|
||||
else sessionStorage.setItem(RESUME_KEY, JSON.stringify({ username, settings }))
|
||||
} catch {
|
||||
/* private mode or quota: resuming is a nicety, not a requirement */
|
||||
}
|
||||
}, [step, username, settings])
|
||||
|
||||
// Restore: the widget data itself is not persisted, so re-fetch it for
|
||||
// the username we came back to.
|
||||
useEffect(() => {
|
||||
if (resumed) startFetch(resumed.username, true)
|
||||
}, [resumed, startFetch])
|
||||
|
||||
const handleSearch = (user: string) => {
|
||||
setUsername(user)
|
||||
startFetch(user)
|
||||
@@ -377,6 +421,7 @@ export default function App() {
|
||||
fetchDone={fetchDone}
|
||||
fetchError={fetchError}
|
||||
widgetData={widgetData}
|
||||
isDemoData={widgetData === DEMO_WIDGET_DATA}
|
||||
me={me}
|
||||
onAuthChange={setMe}
|
||||
/>
|
||||
|
||||
@@ -4,8 +4,14 @@ type Props = {
|
||||
onSearch: (username: string) => void
|
||||
}
|
||||
|
||||
// A real card served by the live API, so the landing page shows the actual
|
||||
// product, not a mockup. The frame below has a fixed height so a slow or
|
||||
// failed load never reflows the page or pushes the input out of view.
|
||||
const EXAMPLE_URL = 'https://gh-stats.com/api/shaymanor'
|
||||
|
||||
export function SearchScreen({ onSearch }: Props) {
|
||||
const [value, setValue] = useState('')
|
||||
const [exampleFailed, setExampleFailed] = useState(false)
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
@@ -14,31 +20,60 @@ export function SearchScreen({ onSearch }: Props) {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center animate-fade-in-up">
|
||||
<div className="text-center w-full max-w-md px-6">
|
||||
<h1 className="font-serif text-4xl text-gray-800 tracking-tight mb-2">
|
||||
GitHub Stats
|
||||
</h1>
|
||||
<p className="text-sm text-gray-400 mb-8">
|
||||
Generate your profile widget
|
||||
</p>
|
||||
<form onSubmit={handleSubmit} className="flex gap-2">
|
||||
<input
|
||||
type="text"
|
||||
value={value}
|
||||
onChange={e => setValue(e.target.value)}
|
||||
placeholder="Enter GitHub username..."
|
||||
autoFocus
|
||||
className="flex-1 px-4 py-3 rounded-xl border border-gray-200 bg-white text-sm text-gray-800 placeholder:text-gray-300 focus:outline-none focus:ring-1 focus:ring-gray-300 transition-colors"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={!value.trim()}
|
||||
className="px-6 py-3 rounded-xl bg-gray-800 text-white text-sm font-medium hover:bg-gray-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors"
|
||||
>
|
||||
Go
|
||||
</button>
|
||||
</form>
|
||||
<div className="min-h-screen flex items-start md:items-center justify-center px-6 py-12 animate-fade-in-up">
|
||||
<div className="w-full max-w-4xl grid gap-10 md:grid-cols-2 md:items-center">
|
||||
<div className="w-full max-w-md mx-auto md:mx-0 text-center md:text-left">
|
||||
<h1 className="font-serif text-4xl md:text-5xl text-gray-800 tracking-tight mb-3">
|
||||
GitHub Stats
|
||||
</h1>
|
||||
<p className="text-sm text-gray-500 leading-relaxed mb-8">
|
||||
One image for your profile README: your score, contribution timeline,
|
||||
top collaborators, language breakdown, commit streaks and auto-awarded tags.
|
||||
</p>
|
||||
<form onSubmit={handleSubmit} className="flex gap-2">
|
||||
<input
|
||||
type="text"
|
||||
value={value}
|
||||
onChange={e => setValue(e.target.value)}
|
||||
placeholder="Enter GitHub username..."
|
||||
autoFocus
|
||||
className="flex-1 min-w-0 px-4 py-3 rounded-xl border border-gray-200 bg-white text-sm text-gray-800 placeholder:text-gray-300 focus:outline-none focus:ring-1 focus:ring-gray-300 transition-colors"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={!value.trim()}
|
||||
className="px-6 py-3 rounded-xl bg-gray-800 text-white text-sm font-medium hover:bg-gray-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors"
|
||||
>
|
||||
Go
|
||||
</button>
|
||||
</form>
|
||||
<p className="mt-3 text-xs text-gray-400">
|
||||
Five themes · one line of markdown · no signup
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="w-full max-w-[420px] mx-auto md:mx-0">
|
||||
<div className="relative h-[300px] md:h-[420px] overflow-hidden rounded-2xl border border-gray-200 bg-white">
|
||||
{exampleFailed ? (
|
||||
<p className="absolute inset-0 flex items-center justify-center text-xs text-gray-400">
|
||||
Example card unavailable
|
||||
</p>
|
||||
) : (
|
||||
<img
|
||||
src={EXAMPLE_URL}
|
||||
width={420}
|
||||
height={1196}
|
||||
alt="Example stats card"
|
||||
onError={() => setExampleFailed(true)}
|
||||
className="block w-full"
|
||||
/>
|
||||
)}
|
||||
<div className="pointer-events-none absolute inset-x-0 bottom-0 h-14 md:h-16 bg-gradient-to-t from-gray-50 to-transparent" />
|
||||
</div>
|
||||
<p className="mt-3 text-center md:text-left font-mono text-[11px] text-gray-400 truncate">
|
||||
gh-stats.com/api/shaymanor
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -226,6 +226,7 @@ type Props = {
|
||||
fetchDone: boolean
|
||||
fetchError: string | null
|
||||
widgetData: WidgetData | null
|
||||
isDemoData: boolean
|
||||
me: Me
|
||||
onAuthChange?: (m: Me) => void
|
||||
}
|
||||
@@ -239,6 +240,7 @@ export function WorkshopScreen({
|
||||
fetchDone,
|
||||
fetchError,
|
||||
widgetData,
|
||||
isDemoData,
|
||||
me,
|
||||
}: Props) {
|
||||
const canEdit = !!me.login && me.login.toLowerCase() === username.toLowerCase()
|
||||
@@ -744,6 +746,12 @@ export function WorkshopScreen({
|
||||
{/* Right preview area */}
|
||||
<div className="flex-1 flex items-start justify-center p-8 overflow-auto">
|
||||
<div className="relative">
|
||||
{isDemoData && svgContent && (
|
||||
<div className="flex items-center gap-1.5 mx-auto mb-3 w-fit rounded-full border border-amber-200 bg-amber-50 px-2.5 py-1 text-[10px] text-amber-700">
|
||||
<div className="w-1.5 h-1.5 rounded-full bg-amber-400" />
|
||||
Sample data until your stats finish building
|
||||
</div>
|
||||
)}
|
||||
{svgContent ? (
|
||||
<div dangerouslySetInnerHTML={{ __html: svgContent }} />
|
||||
) : (
|
||||
|
||||
Reference in New Issue
Block a user