From a9accad6798fe29950861257bda42d365166cec6 Mon Sep 17 00:00:00 2001 From: Nathaniel Tampus Date: Mon, 6 Mar 2023 10:30:22 +0800 Subject: [PATCH] add metadata and opengraph tags --- client/src/app/game/[code]/page.tsx | 32 +++++++++++++++++++++++++++++ client/src/app/layout.tsx | 16 ++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/client/src/app/game/[code]/page.tsx b/client/src/app/game/[code]/page.tsx index f654c84..b8d87c3 100644 --- a/client/src/app/game/[code]/page.tsx +++ b/client/src/app/game/[code]/page.tsx @@ -2,6 +2,38 @@ import GameAuthWrapper from "@/components/game/GameAuthWrapper"; import { getGame } from "@/lib/game"; import { notFound } from "next/navigation"; +export async function generateMetadata({ params }: { params: { code: string } }) { + const game = await getGame(params.code); + if (!game) { + return { + description: "Game not found", + robots: { + index: false, + follow: false, + nocache: true, + noarchive: true + } + }; + } + return { + description: `Play or watch a game with ${game.host?.name}`, + openGraph: { + title: "chessu", + description: `Play or watch a game with ${game.host?.name}`, + url: `https://ches.su/game/${game.code}`, + siteName: "chessu", + locale: "en_US", + type: "website" + }, + robots: { + index: false, + follow: false, + nocache: true, + noarchive: true + } + }; +} + export default async function Game({ params }: { params: { code: string } }) { const game = await getGame(params.code); if (!game) { diff --git a/client/src/app/layout.tsx b/client/src/app/layout.tsx index 954f8a3..45d79fc 100644 --- a/client/src/app/layout.tsx +++ b/client/src/app/layout.tsx @@ -8,7 +8,21 @@ import ContextProvider from "@/context/ContextProvider"; export const metadata = { title: "chessu", - description: "Play Chess online." + description: "Play Chess online.", + openGraph: { + title: "chessu", + description: "Play Chess online.", + url: "https://ches.su", + siteName: "chessu", + locale: "en_US", + type: "website" + }, + robots: { + index: true, + follow: false, + nocache: true, + noarchive: true + } }; export default function RootLayout({ children }: { children: React.ReactNode }) {