|
| 1 | +import { getCloudflareContext } from "@opennextjs/cloudflare"; |
| 2 | +import { desc } from "drizzle-orm"; |
| 3 | +import type { Metadata } from "next"; |
| 4 | +import { Footer } from "@/components/home/Footer"; |
| 5 | +import { Navbar } from "@/components/home/Navbar"; |
| 6 | +import { StoreGrid } from "@/components/store/StoreGrid"; |
| 7 | +import { getDb } from "@/db/client"; |
| 8 | +import { type Extension, extensions } from "@/db/schema"; |
| 9 | +import { getAppData } from "@/lib/data"; |
| 10 | +import { i18n, type Locale, locales } from "@/lib/i18n"; |
| 11 | +import { getTranslation } from "@/lib/i18n/translations"; |
| 12 | +import { pageAlternates } from "@/lib/seo"; |
| 13 | + |
| 14 | +export async function generateMetadata({ |
| 15 | + params, |
| 16 | +}: { |
| 17 | + params: Promise<{ lang: string }>; |
| 18 | +}): Promise<Metadata> { |
| 19 | + const { lang } = await params; |
| 20 | + const locale = ( |
| 21 | + locales.includes(lang as Locale) ? lang : i18n.defaultLanguage |
| 22 | + ) as Locale; |
| 23 | + const t = (key: string) => getTranslation(locale, key); |
| 24 | + |
| 25 | + return { |
| 26 | + title: t("store.title"), |
| 27 | + description: t("store.subtitle"), |
| 28 | + alternates: pageAlternates(locale, "/store"), |
| 29 | + }; |
| 30 | +} |
| 31 | + |
| 32 | +export default async function StorePage({ |
| 33 | + params, |
| 34 | +}: { |
| 35 | + params: Promise<{ lang: string }>; |
| 36 | +}) { |
| 37 | + const { lang } = await params; |
| 38 | + const locale = ( |
| 39 | + locales.includes(lang as Locale) ? lang : i18n.defaultLanguage |
| 40 | + ) as Locale; |
| 41 | + |
| 42 | + const appData = await getAppData(); |
| 43 | + |
| 44 | + let extensionList: Extension[] = []; |
| 45 | + |
| 46 | + try { |
| 47 | + const ctx = await getCloudflareContext({ async: true }); |
| 48 | + // @ts-expect-error - CF env type |
| 49 | + const d1 = ctx.env.DB as D1Database | undefined; |
| 50 | + |
| 51 | + if (d1) { |
| 52 | + const db = getDb(d1); |
| 53 | + extensionList = await db |
| 54 | + .select() |
| 55 | + .from(extensions) |
| 56 | + .orderBy(desc(extensions.installCount), desc(extensions.stars)) |
| 57 | + .all(); |
| 58 | + } |
| 59 | + } catch (err) { |
| 60 | + console.error("Failed to connect to D1:", err); |
| 61 | + } |
| 62 | + |
| 63 | + const t = (key: string) => getTranslation(locale, key); |
| 64 | + |
| 65 | + return ( |
| 66 | + <main className="min-h-screen stable-vh overflow-x-clip bg-white dark:bg-[#0A0A0A] text-gray-900 dark:text-gray-100 relative"> |
| 67 | + <Navbar version={appData.version} stars={appData.stars} /> |
| 68 | + |
| 69 | + {/* ── Minimalist Hero Header ── */} |
| 70 | + <section className="relative pt-32 pb-12 lg:pt-40 lg:pb-16 overflow-hidden"> |
| 71 | + <div className="max-w-7xl mx-auto px-6 sm:px-8 lg:px-16 relative"> |
| 72 | + <div className="max-w-3xl mx-auto text-center"> |
| 73 | + <h1 className="text-4xl sm:text-5xl lg:text-6xl font-semibold tracking-tight text-gray-950 dark:text-white mb-5"> |
| 74 | + {t("store.title")} |
| 75 | + </h1> |
| 76 | + <p className="text-lg sm:text-xl text-gray-500 dark:text-gray-400 font-medium tracking-wide"> |
| 77 | + {t("store.subtitle")} |
| 78 | + </p> |
| 79 | + </div> |
| 80 | + </div> |
| 81 | + </section> |
| 82 | + |
| 83 | + {/* ── Extension grid ── */} |
| 84 | + <div className="max-w-7xl mx-auto px-6 sm:px-8 lg:px-16 pb-24 relative"> |
| 85 | + <div className="max-w-6xl mx-auto"> |
| 86 | + <StoreGrid extensions={extensionList} /> |
| 87 | + </div> |
| 88 | + </div> |
| 89 | + |
| 90 | + <Footer /> |
| 91 | + </main> |
| 92 | + ); |
| 93 | +} |
0 commit comments