teecup/frontend/app/clubs/[slug]/page.tsx

45 lines
1.2 KiB
TypeScript
Raw Normal View History

import type { Metadata } from "next"
import { PublicClub } from "@/components/public-club"
// Server-side -- går IKKE gjennom next.config.mjs sin rewrites() (kun for
// nettleser-trafikk inn til Next.js-serveren). Peker direkte på API-et.
const API_ORIGIN = process.env.TEECUP_API_ORIGIN || "http://localhost:8000"
type PublicOrgInfo = {
name: string
}
export async function generateMetadata({
params,
}: {
params: Promise<{ slug: string }>
}): Promise<Metadata> {
const { slug } = await params
try {
const res = await fetch(`${API_ORIGIN}/public/orgs/${slug}`, { cache: "no-store" })
if (!res.ok) {
return { title: "Klubb | TeeCup" }
}
const data: PublicOrgInfo = await res.json()
const title = `${data.name} | TeeCup`
const description = `Se ${data.name} sine turneringer på TeeCup.`
return {
title,
description,
openGraph: { title, description, siteName: "TeeCup", type: "website" },
twitter: { card: "summary", title, description },
}
} catch {
return { title: "TeeCup" }
}
}
export default async function ClubPage({
params,
}: {
params: Promise<{ slug: string }>
}) {
const { slug } = await params
return <PublicClub slug={slug} />
}