29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import type { Metadata } from "next";
|
|
import { notFound, permanentRedirect } from "next/navigation";
|
|
import { connection } from "next/server";
|
|
|
|
import { GuideShell } from "@/components/public/guide-shell";
|
|
import { loadPublicPage } from "@/lib/content/loaders";
|
|
|
|
type RouteParams = Promise<{ character: string; page: string }>;
|
|
|
|
export async function generateMetadata({ params }: { params: RouteParams }): Promise<Metadata> {
|
|
await connection();
|
|
const { character, page } = await params;
|
|
const result = await loadPublicPage(character, page);
|
|
if (result.type !== "page") return { title: "ไม่พบคู่มือ" };
|
|
return {
|
|
title: `${result.snapshot.page.title} — ${result.snapshot.character.nameTh}`,
|
|
description: result.snapshot.character.description ?? undefined,
|
|
};
|
|
}
|
|
|
|
export default async function GuidePage({ params }: { params: RouteParams }) {
|
|
await connection();
|
|
const { character, page } = await params;
|
|
const result = await loadPublicPage(character, page);
|
|
if (result.type === "redirect") permanentRedirect(result.location);
|
|
if (result.type === "not-found") notFound();
|
|
return <GuideShell snapshot={result.snapshot} />;
|
|
}
|