feat(guides): add structured image-first editor
This commit is contained in:
@@ -1,28 +1,23 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound, permanentRedirect } from "next/navigation";
|
||||
import { notFound } from "next/navigation";
|
||||
import { connection } from "next/server";
|
||||
|
||||
import { GuideShell } from "@/components/public/guide-shell";
|
||||
import { loadPublicPage } from "@/lib/content/loaders";
|
||||
import { publicSections, StructuredGuideShell } from "@/components/public/structured-guide";
|
||||
import { getPublicGuide } from "@/lib/guides/queries";
|
||||
|
||||
type RouteParams = Promise<{ character: string; page: string }>;
|
||||
type Params = Promise<{ character: string; page: string }>;
|
||||
|
||||
export async function generateMetadata({ params }: { params: RouteParams }): Promise<Metadata> {
|
||||
export async function generateMetadata({ params }: { params: Params }): 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,
|
||||
};
|
||||
const guide = await getPublicGuide(character);
|
||||
return guide ? { title: `${page} — ${guide.name} Build Guide`, description: guide.overview } : { title: "ไม่พบ Guide" };
|
||||
}
|
||||
|
||||
export default async function GuidePage({ params }: { params: RouteParams }) {
|
||||
export default async function GuideSectionPage({ params }: { params: Params }) {
|
||||
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} />;
|
||||
const guide = await getPublicGuide(character);
|
||||
if (!guide || !publicSections(guide).some((section) => section.slug === page)) notFound();
|
||||
return <StructuredGuideShell guide={guide} section={page} />;
|
||||
}
|
||||
|
||||
+16
-11
@@ -1,16 +1,21 @@
|
||||
import { notFound, permanentRedirect } from "next/navigation";
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
import { connection } from "next/server";
|
||||
|
||||
import { loadPublicPage } from "@/lib/content/loaders";
|
||||
import { StructuredGuideShell } from "@/components/public/structured-guide";
|
||||
import { getPublicGuide } from "@/lib/guides/queries";
|
||||
|
||||
export default async function CharacterPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ character: string }>;
|
||||
}) {
|
||||
type Params = Promise<{ character: string }>;
|
||||
|
||||
export async function generateMetadata({ params }: { params: Params }): Promise<Metadata> {
|
||||
await connection();
|
||||
const { character } = await params;
|
||||
const result = await loadPublicPage(character);
|
||||
if (result.type === "redirect") permanentRedirect(result.location);
|
||||
notFound();
|
||||
const guide = await getPublicGuide((await params).character);
|
||||
return guide ? { title: `${guide.name} Build Guide`, description: guide.overview } : { title: "ไม่พบ Guide" };
|
||||
}
|
||||
|
||||
export default async function GuideOverviewPage({ params }: { params: Params }) {
|
||||
await connection();
|
||||
const guide = await getPublicGuide((await params).character);
|
||||
if (!guide) notFound();
|
||||
return <StructuredGuideShell guide={guide} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user