| 1 | import { notFound } from "next/navigation"; |
| 2 | |
| 3 | import { createServerClient } from "@/lib/api/server"; |
| 4 | import { ogCard, plural } from "@/lib/og"; |
| 5 | |
| 6 | export { size, contentType } from "@/lib/og"; |
| 7 | export const alt = "Repository"; |
| 8 | |
| 9 | export default async function Image({ |
| 10 | params, |
| 11 | }: { |
| 12 | params: Promise<{ username: string; repo: string }>; |
| 13 | }) { |
| 14 | const { username, repo } = await params; |
| 15 | |
| 16 | const client = await createServerClient(); |
| 17 | const [{ data }, languages] = await Promise.all([ |
| 18 | client.GET("/api/repositories/{username}/{slug}", { |
| 19 | params: { path: { username, slug: repo } }, |
| 20 | }), |
| 21 | client.GET("/api/repositories/{username}/{slug}/languages", { |
| 22 | params: { path: { username, slug: repo } }, |
| 23 | }), |
| 24 | ]); |
| 25 | |
| 26 | // A private repository answers 404 to the crawler, so nothing leaks here. |
| 27 | if (!data) notFound(); |
| 28 | |
| 29 | return ogCard({ |
| 30 | eyebrow: `${username}/${data.slug}`, |
| 31 | icon: "bookMarked", |
| 32 | title: data.name, |
| 33 | description: data.description, |
| 34 | stats: [ |
| 35 | { icon: "star", label: plural(data.starCount, "star") }, |
| 36 | { icon: "gitFork", label: plural(data.forkCount, "fork") }, |
| 37 | ], |
| 38 | languages: languages.data?.languages, |
| 39 | }); |
| 40 | } |