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:
shay
2026-08-22 16:10:44 -07:00
co-authored by Claude Opus 5
parent 0904c4bb9f
commit faf41ad952
7 changed files with 149 additions and 32 deletions
+19 -1
View File
@@ -4,7 +4,25 @@
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<link rel="icon" type="image/svg+xml" href="/favicon.svg"/> <link rel="icon" type="image/svg+xml" href="/favicon.svg"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <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"> <script type="module">
// Import the functions you need from the SDKs you need // Import the functions you need from the SDKs you need
import {initializeApp} from "https://www.gstatic.com/firebasejs/12.13.0/firebase-app.js"; import {initializeApp} from "https://www.gstatic.com/firebasejs/12.13.0/firebase-app.js";
Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

+3
View File
@@ -0,0 +1,3 @@
User-agent: *
Allow: /
Sitemap: https://gh-stats.com/sitemap.xml
+8
View File
@@ -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
View File
@@ -51,6 +51,27 @@ const DEFAULT_SETTINGS: WidgetSettings = {
type Step = 'search' | 'workshop' | 'result' 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_INTERVAL_MS = 2000
const POLL_TIMEOUT_MS = 120_000 const POLL_TIMEOUT_MS = 120_000
// ResultScreen poll: a bit slower than the workshop poll because each tick // ResultScreen poll: a bit slower than the workshop poll because each tick
@@ -74,9 +95,11 @@ export default function App() {
return <DevScreen /> return <DevScreen />
} }
const [me, setMe] = useState<Me>({ login: null }) const [me, setMe] = useState<Me>({ login: null })
const [step, setStep] = useState<Step>('search') // Work in progress left behind by a sign-in redirect, if any.
const [username, setUsername] = useState('') const [resumed] = useState(loadResume)
const [settings, setSettings] = useState<WidgetSettings>({ ...DEFAULT_SETTINGS }) 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 [widgetData, setWidgetData] = useState<WidgetData | null>(null)
const [fetchDone, setFetchDone] = useState(false) const [fetchDone, setFetchDone] = useState(false)
const [fetchError, setFetchError] = useState<string | null>(null) const [fetchError, setFetchError] = useState<string | null>(null)
@@ -155,7 +178,10 @@ export default function App() {
return stopResultPolling return stopResultPolling
}, [step, widgetStatus, embedUrl, refetchEmbed, 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() stopPolling()
aborted.current = false aborted.current = false
pollStart.current = Date.now() pollStart.current = Date.now()
@@ -165,12 +191,12 @@ export default function App() {
setWidgetData(DEMO_WIDGET_DATA) setWidgetData(DEMO_WIDGET_DATA)
// Reset to defaults first so the form doesn't briefly show the previous // Reset to defaults first so the form doesn't briefly show the previous
// user's settings while we fetch this user's saved blob. // 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. // Hydrate the Workshop form from the user's persisted settings.
// Backend stores snake_case keys; we map them onto the camelCase // Backend stores snake_case keys; we map them onto the camelCase
// state shape here. 404 (not enrolled yet) is expected — keep defaults. // state shape here. 404 (not enrolled yet) is expected — keep defaults.
void (async () => { if (!keepSettings) void (async () => {
try { try {
const r = await fetch(`/api/${encodeURIComponent(user)}/settings`, { const r = await fetch(`/api/${encodeURIComponent(user)}/settings`, {
credentials: 'include', credentials: 'include',
@@ -258,6 +284,24 @@ export default function App() {
poll() poll()
}, [stopPolling]) }, [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) => { const handleSearch = (user: string) => {
setUsername(user) setUsername(user)
startFetch(user) startFetch(user)
@@ -377,6 +421,7 @@ export default function App() {
fetchDone={fetchDone} fetchDone={fetchDone}
fetchError={fetchError} fetchError={fetchError}
widgetData={widgetData} widgetData={widgetData}
isDemoData={widgetData === DEMO_WIDGET_DATA}
me={me} me={me}
onAuthChange={setMe} onAuthChange={setMe}
/> />
+60 -25
View File
@@ -4,8 +4,14 @@ type Props = {
onSearch: (username: string) => void 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) { export function SearchScreen({ onSearch }: Props) {
const [value, setValue] = useState('') const [value, setValue] = useState('')
const [exampleFailed, setExampleFailed] = useState(false)
const handleSubmit = (e: React.FormEvent) => { const handleSubmit = (e: React.FormEvent) => {
e.preventDefault() e.preventDefault()
@@ -14,31 +20,60 @@ export function SearchScreen({ onSearch }: Props) {
} }
return ( return (
<div className="min-h-screen flex items-center justify-center animate-fade-in-up"> <div className="min-h-screen flex items-start md:items-center justify-center px-6 py-12 animate-fade-in-up">
<div className="text-center w-full max-w-md px-6"> <div className="w-full max-w-4xl grid gap-10 md:grid-cols-2 md:items-center">
<h1 className="font-serif text-4xl text-gray-800 tracking-tight mb-2"> <div className="w-full max-w-md mx-auto md:mx-0 text-center md:text-left">
GitHub Stats <h1 className="font-serif text-4xl md:text-5xl text-gray-800 tracking-tight mb-3">
</h1> GitHub Stats
<p className="text-sm text-gray-400 mb-8"> </h1>
Generate your profile widget <p className="text-sm text-gray-500 leading-relaxed mb-8">
</p> One image for your profile README: your score, contribution timeline,
<form onSubmit={handleSubmit} className="flex gap-2"> top collaborators, language breakdown, commit streaks and auto-awarded tags.
<input </p>
type="text" <form onSubmit={handleSubmit} className="flex gap-2">
value={value} <input
onChange={e => setValue(e.target.value)} type="text"
placeholder="Enter GitHub username..." value={value}
autoFocus onChange={e => setValue(e.target.value)}
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" placeholder="Enter GitHub username..."
/> autoFocus
<button 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"
type="submit" />
disabled={!value.trim()} <button
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" type="submit"
> disabled={!value.trim()}
Go 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"
</button> >
</form> 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>
</div> </div>
) )
@@ -226,6 +226,7 @@ type Props = {
fetchDone: boolean fetchDone: boolean
fetchError: string | null fetchError: string | null
widgetData: WidgetData | null widgetData: WidgetData | null
isDemoData: boolean
me: Me me: Me
onAuthChange?: (m: Me) => void onAuthChange?: (m: Me) => void
} }
@@ -239,6 +240,7 @@ export function WorkshopScreen({
fetchDone, fetchDone,
fetchError, fetchError,
widgetData, widgetData,
isDemoData,
me, me,
}: Props) { }: Props) {
const canEdit = !!me.login && me.login.toLowerCase() === username.toLowerCase() const canEdit = !!me.login && me.login.toLowerCase() === username.toLowerCase()
@@ -744,6 +746,12 @@ export function WorkshopScreen({
{/* Right preview area */} {/* Right preview area */}
<div className="flex-1 flex items-start justify-center p-8 overflow-auto"> <div className="flex-1 flex items-start justify-center p-8 overflow-auto">
<div className="relative"> <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 ? ( {svgContent ? (
<div dangerouslySetInnerHTML={{ __html: svgContent }} /> <div dangerouslySetInnerHTML={{ __html: svgContent }} />
) : ( ) : (