caelum0x 378f23036e feat(ritgram): RIT-SEO badge 404s unknown users, copy button + docs page
The embeddable /badge/<user>.svg route (deployed 2026-11-27) rendered a
confident-looking badge for any handle, real or not. It now looks the
user up via the existing explicit-select GET /v1/users/:id route and
renders a neutral "not found" SVG (HTTP 404) for unknown handles, while
showing a live post count for real ones. The lookup fails open (no 404)
on a slow/unreachable backend so this stays a reliable public image
endpoint rather than a hard API dependency.

Also adds the two missing pieces from the Hashnode-style backlink wedge:
a "copy badge" icon button on a user's own profile (copies the markdown
snippet) and a /docs/badge page explaining the URL, markdown/HTML
snippets, and the privacy posture (username + public post count only,
same fields already on any public profile).

Verified locally end-to-end: started the real backend (local Postgres)
+ web dev server — an existing seeded user returns 200 with a live post
count, an unknown handle returns the 404 SVG, invalid characters still
400, and killing the backend falls back to the neutral badge instead of
a false 404. `tsc --noEmit` clean across the whole web app.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 20:03:31 +03:00

93 lines
3.8 KiB
TypeScript

import Link from 'next/link'
import { RITGRAM_SITE_URL, RITGRAM_SITE_HOST } from '@/lib/site-config'
export const metadata = {
title: 'Ritgram profile badge — embed your repo/post count anywhere',
description:
'Drop a small SVG badge for your Ritgram profile into any README or site. Shows your handle and post count, links back to your profile, no sign-up required to display it.',
}
const EXAMPLE_USER = 'caelum0x'
export default function BadgeDocsPage() {
const badgeUrl = `${RITGRAM_SITE_URL}/badge/${EXAMPLE_USER}.svg`
const profileUrl = `${RITGRAM_SITE_URL}/${EXAMPLE_USER}`
const markdownSnippet = `[![Ritgram](${badgeUrl})](${profileUrl})`
const htmlSnippet = `<a href="${profileUrl}"><img src="${badgeUrl}" alt="Ritgram" /></a>`
return (
<div className="max-w-3xl mx-auto py-16 px-4">
<h1 className="text-4xl font-bold mb-4">Ritgram profile badge</h1>
<p className="text-lg text-muted mb-10">
A small embeddable badge for your Ritgram profile. Put it in a README, a personal site,
or anywhere else that renders images and links — it shows your handle and post count and
links back to <code>{RITGRAM_SITE_HOST}/&lt;you&gt;</code>.
</p>
<div className="space-y-10">
<section>
<h2 className="text-2xl font-bold mb-3">The URL</h2>
<p className="text-muted mb-3">
Every Ritgram user has one at this path — no auth, no setup, no API key:
</p>
<pre className="bg-surface border border-border rounded-lg p-4 overflow-x-auto text-sm">
<code>{RITGRAM_SITE_URL}/badge/&lt;username&gt;.svg</code>
</pre>
</section>
<section>
<h2 className="text-2xl font-bold mb-3">Example</h2>
<p className="text-muted mb-3">
<code>@{EXAMPLE_USER}</code>&apos;s badge:
</p>
<img src={badgeUrl} alt={`Ritgram badge for @${EXAMPLE_USER}`} className="h-5" />
</section>
<section>
<h2 className="text-2xl font-bold mb-3">Markdown</h2>
<p className="text-muted mb-3">
Paste this into a README or any markdown file (swap in your own username — find your
exact snippet with a one-click copy on your{' '}
<Link href="/profile" className="text-primary underline">
own profile page
</Link>
):
</p>
<pre className="bg-surface border border-border rounded-lg p-4 overflow-x-auto text-sm">
<code>{markdownSnippet}</code>
</pre>
</section>
<section>
<h2 className="text-2xl font-bold mb-3">HTML</h2>
<p className="text-muted mb-3">For a plain site instead of markdown:</p>
<pre className="bg-surface border border-border rounded-lg p-4 overflow-x-auto text-sm">
<code>{htmlSnippet}</code>
</pre>
</section>
<section>
<h2 className="text-2xl font-bold mb-3">Unknown handles</h2>
<p className="text-muted">
Requesting a badge for a username that doesn&apos;t exist on Ritgram returns a plain
&quot;not found&quot; badge instead of a confident-looking one — so a typo in your
snippet is obvious at a glance rather than silently wrong.
</p>
</section>
<section>
<h2 className="text-2xl font-bold mb-3">Privacy</h2>
<p className="text-muted">
The badge only ever shows a username and a public post count — the same two fields
already visible on any public{' '}
<Link href={`/${EXAMPLE_USER}`} className="text-primary underline">
profile page
</Link>
. No email, no private data, no auth required to view it.
</p>
</section>
</div>
</div>
)
}