| 1 | import { notFound } from "next/navigation"; |
| 2 | |
| 3 | import { createServerClient } |
| 4 | import { ogCard, plural |
| 5 | |
| 6 | /** Cards for paths inside a repository. Next.js forbids an `opengraph-image` beside an optional catch-all segment, so the tree and blob pages point their metadata at this one route instead. */ |
| 7 | export async function GET |
| 8 | request: Request |
| 9 | { params }: |
| 10 | ) { |
| 11 | const { username, |
| 12 | const search = |
| 13 | const ref = |
| 14 | const path = |
| 15 | const client = |
| 16 | |
| 17 | if (search.get |
| 18 | const { data |
| 19 | "/api/repositories/{username}/{slug}/blob", |
| 20 | { params: { path: |
| 21 | ); |
| 22 | if (!data) |
| 23 | |
| 24 | return ogCard({ |
| 25 | eyebrow: `${username} |
| 26 | icon: "fileCode", |
| 27 | badge: { label: ref |
| 28 | title: path.split |
| 29 | // the directory only: repeating the file name under itself reads badly |
| 30 | description: shortenPath(path |
| 31 | stats: [ |
| 32 | { icon: "fileDiff", |
| 33 | ...(data.commit |
| 34 | ? [ |
| 35 | { |
| 36 | icon: "gitCommitHorizontal" as |
| 37 | label: data.commit |
| 38 | }, |
| 39 | ] |
| 40 | : []), |
| 41 | ], |
| 42 | }); |
| 43 | } |
| 44 | |
| 45 | const { data |
| 46 | "/api/repositories/{username}/{slug}/contents", |
| 47 | { |
| 48 | params: { |
| 49 | path: { username, |
| 50 | query: { ref, |
| 51 | }, |
| 52 | }, |
| 53 | ); |
| 54 | if (!data) |
| 55 | |
| 56 | return ogCard({ |
| 57 | eyebrow: `${username} |
| 58 | icon: "folder", |
| 59 | badge: { label: ref |
| 60 | title: path.split |
| 61 | description: path |
| 62 | ? shortenPath(path. |
| 63 | : (data.commit |
| 64 | stats: [ |
| 65 | { |
| 66 | icon: "fileCode", |
| 67 | label: plural(data |
| 68 | }, |
| 69 | { |
| 70 | icon: "gitCommitHorizontal", |
| 71 | label: plural(data |
| 72 | }, |
| 73 | ], |
| 74 | }); |
| 75 | } |
| 76 | |
| 77 | function formatBytes(bytes: |
| 78 | if (bytes < |
| 79 | if (bytes < |
| 80 | return `${(bytes |
| 81 | } |