Skip to content

Commit 4a5a723

Browse files
ux(badge): match card width and avoid double border
Made-with: Cursor
1 parent 5dc57d9 commit 4a5a723

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

src/app/api/badge/route.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,31 @@ async function fetchStats(username: string) {
3434
return { dead, struggling, alive, total: dead + struggling + alive }
3535
}
3636

37-
function buildSvg(username: string, dead: number, struggling: number, alive: number, total: number) {
37+
function buildSvg(
38+
username: string,
39+
dead: number,
40+
struggling: number,
41+
alive: number,
42+
total: number,
43+
framed: boolean
44+
) {
3845
const BAR_X = 16, BAR_W = 408, BAR_Y = 76, BAR_H = 6
3946
const deadW = total === 0 ? 0 : Math.round((dead / total) * BAR_W)
4047
const strugglingW = total === 0 ? 0 : Math.round((struggling / total) * BAR_W)
4148
const aliveW = total === 0 ? BAR_W : BAR_W - deadW - strugglingW
4249
const MONO = "'Courier New','Courier',ui-monospace,monospace"
4350

51+
const outerBg = framed ? `<rect width="440" height="96" fill="#FAF6EF"/>` : ''
52+
const outerStroke = framed
53+
? `<rect x="1" y="1" width="438" height="94" fill="none" stroke="#1a1a1a" stroke-width="2"/>`
54+
: ''
55+
4456
return `<svg width="440" height="96" viewBox="0 0 440 96" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Graveyard report for @${username}">
4557
<defs>
4658
<clipPath id="bar-clip"><rect x="${BAR_X}" y="${BAR_Y}" width="${BAR_W}" height="${BAR_H}"/></clipPath>
4759
</defs>
48-
<rect width="440" height="96" fill="#FAF6EF"/>
49-
<rect x="1" y="1" width="438" height="94" fill="none" stroke="#1a1a1a" stroke-width="2"/>
60+
${outerBg}
61+
${outerStroke}
5062
5163
<text x="16" y="28" font-family=${JSON.stringify(MONO)} font-size="9" font-weight="700" fill="#9a9288" letter-spacing="2.2">GITHUB REPO GRAVEYARD</text>
5264
@@ -69,10 +81,13 @@ export async function GET(req: NextRequest) {
6981
return new NextResponse('invalid username', { status: 400 })
7082
}
7183

84+
const framedParam = req.nextUrl.searchParams.get('frame')
85+
const framed = framedParam == null ? true : framedParam !== '0'
86+
7287
const stats = await fetchStats(username)
7388
const { dead, struggling, alive, total } = stats ?? { dead: 0, struggling: 0, alive: 0, total: 0 }
7489

75-
const svg = buildSvg(username, dead, struggling, alive, total)
90+
const svg = buildSvg(username, dead, struggling, alive, total, framed)
7691

7792
return new NextResponse(svg, {
7893
headers: {

src/components/ReadmeBadge.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function ReadmeBadge({ username }: Props) {
1616

1717
// Version param forces GitHub's camo proxy to refetch when we redesign the badge.
1818
const BADGE_VERSION = '3'
19-
const badgeUrl = `https://commitmentissues.dev/api/badge?username=${username}&v=${BADGE_VERSION}`
19+
const badgeUrl = `https://commitmentissues.dev/api/badge?username=${username}&v=${BADGE_VERSION}&frame=1`
2020
const profileUrl = `https://commitmentissues.dev/user/${username}`
2121
const altText = `Commitment Issues — @${username}'s graveyard`
2222
const markdown = `[![${altText}](${badgeUrl})](${profileUrl})`
@@ -25,7 +25,7 @@ export default function ReadmeBadge({ username }: Props) {
2525
let cancelled = false
2626
setSvg(null)
2727
setSvgError(false)
28-
fetch(`/api/badge?username=${encodeURIComponent(username)}&v=${BADGE_VERSION}`)
28+
fetch(`/api/badge?username=${encodeURIComponent(username)}&v=${BADGE_VERSION}&frame=0`)
2929
.then(r => {
3030
if (!r.ok) throw new Error('badge fetch failed')
3131
return r.text()
@@ -47,7 +47,7 @@ export default function ReadmeBadge({ username }: Props) {
4747
}
4848

4949
return (
50-
<div className="readme-badge-block" style={{ width: '100%', marginBottom: '22px' }}>
50+
<div className="readme-badge-block record-card" style={{ width: '100%', marginBottom: '22px', border: '2px solid #1a1a1a' }}>
5151
{/* Badge preview — the SVG already has its own border; keep the wrapper borderless */}
5252
<div className="readme-badge-preview" style={{ width: '100%', aspectRatio: '440 / 96', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
5353
{svg ? (
@@ -65,8 +65,7 @@ export default function ReadmeBadge({ username }: Props) {
6565
style={{
6666
width: '100%',
6767
height: '100%',
68-
border: '2px solid #1a1a1a',
69-
background: 'var(--c-bg)',
68+
background: 'transparent',
7069
display: 'flex',
7170
alignItems: 'center',
7271
justifyContent: 'center',

0 commit comments

Comments
 (0)