| 1 | import { createServerClient } from "@/lib/api/server"; |
| 2 | import { codeSearchStats, ogCard |
| 3 | |
| 4 | const REPOSITORY_PAGE = 20 |
| 5 | |
| 6 | /** The card for `/search`. An `opengraph-image` never sees search params, so the page points its metadata here with the query attached. */ |
| 7 | export async function GET |
| 8 | const search = |
| 9 | const query = |
| 10 | const kind = |
| 11 | |
| 12 | if (!query) |
| 13 | return ogCard({ |
| 14 | eyebrow: "Search", |
| 15 | icon: "search", |
| 16 | title: "Search Ghost", |
| 17 | description: "Find public repositories and the code inside them.", |
| 18 | }); |
| 19 | } |
| 20 | |
| 21 | const client = |
| 22 | |
| 23 | if (kind === |
| 24 | const { data |
| 25 | params: { query: { |
| 26 | }); |
| 27 | |
| 28 | return ogCard({ |
| 29 | eyebrow: "Code search", |
| 30 | icon: "code", |
| 31 | badge: { label: " |
| 32 | title: `“${query |
| 33 | description: "Matches in public code on Ghost", |
| 34 | stats: codeSearchStats(data |
| 35 | }); |
| 36 | } |
| 37 | |
| 38 | const { data |
| 39 | params: { query: { |
| 40 | }); |
| 41 | const found = |
| 42 | |
| 43 | return ogCard({ |
| 44 | eyebrow: "Repository search", |
| 45 | icon: "search", |
| 46 | badge: { label: " |
| 47 | title: `“${query |
| 48 | description: |
| 49 | "Public repositories on Ghost whose name or description matches", |
| 50 | stats: [ |
| 51 | { |
| 52 | icon: "bookMarked", |
| 53 | // one page is all the card fetches, so a full page is a lower bound |
| 54 | label: data?.hasMore |
| 55 | ? `${found}+ repositories |
| 56 | : plural(found, |
| 57 | }, |
| 58 | ], |
| 59 | }); |
| 60 | } |