diff --git a/app/api/og/post/route.tsx b/app/api/og/post/route.tsx index 48bcbf0..1a8ba59 100644 --- a/app/api/og/post/route.tsx +++ b/app/api/og/post/route.tsx @@ -8,6 +8,24 @@ import { db } from "@/lib/db/client" import { posts } from "@/lib/db/schema" import { getSiteOrigin } from "@/lib/utils" +async function fetchGitHubUser(username: string) { + const res = await fetch(`https://api.github.com/users/${username}`, { + headers: { + Accept: "application/vnd.github.v3+json", + ...(process.env.GITHUB_TOKEN && { + Authorization: `Bearer ${process.env.GITHUB_TOKEN}`, + }), + }, + }) + if (!res.ok) return null + const data = (await res.json()) as { + login: string + name: string | null + avatar_url: string + } + return { login: data.login, name: data.name || data.login, image: data.avatar_url } +} + const size = { width: 1200, height: 630, @@ -48,6 +66,7 @@ export async function GET(request: NextRequest) { title: posts.title, number: posts.number, rootCommentId: posts.rootCommentId, + authorId: posts.authorId, }) .from(posts) .where( @@ -63,6 +82,8 @@ export async function GET(request: NextRequest) { geistMonoBold, ]) + const author = post?.authorId ? await fetchGitHubUser(post.authorId) : null + const title = post?.title || `Post #${postNumber}` const body = post?.rootCommentId ? await getRootCommentText(post.rootCommentId) @@ -76,69 +97,103 @@ export async function GET(request: NextRequest) { display: "flex", flexDirection: "column", alignItems: "flex-start", - justifyContent: "flex-start", + justifyContent: "space-between", backgroundColor: "#fafafa", padding: 60, - gap: 32, fontFamily: "Geist Mono", }} >