fix: og image generation
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import {
|
||||
@@ -9,6 +10,7 @@ import {
|
||||
slugToBookCode,
|
||||
type OtherDocumentSidebarItem,
|
||||
} from "@/lib/other-documents";
|
||||
import { ogForOtherDocument, extractQuoteFromHl, buildOgMeta } from "@/lib/og";
|
||||
import { PageHeader } from "@/components/page-header";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
@@ -16,6 +18,38 @@ import { ChevronLeft, ChevronRight } from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { MobileNav, type MobileNavGroup } from "@/components/mobile-nav";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Metadata
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
searchParams,
|
||||
}: {
|
||||
params: Promise<{ slug: string; chapter: string }>;
|
||||
searchParams: Promise<Record<string, string | string[] | undefined>>;
|
||||
}): Promise<Metadata> {
|
||||
const { slug, chapter: chapterSlug } = await params;
|
||||
const sp = await searchParams;
|
||||
const bookCode = slugToBookCode(slug);
|
||||
|
||||
const quote = extractQuoteFromHl(sp);
|
||||
if (quote) {
|
||||
const meta = await getOtherDocumentMeta(bookCode);
|
||||
const content = await getOtherDocumentContent(bookCode, chapterSlug);
|
||||
const title = meta?.title ?? slug;
|
||||
const detail = content?.title ?? `Chapter ${chapterSlug}`;
|
||||
return buildOgMeta({ title, detail, quote });
|
||||
}
|
||||
|
||||
const [meta, content] = await Promise.all([
|
||||
getOtherDocumentMeta(bookCode),
|
||||
getOtherDocumentContent(bookCode, chapterSlug),
|
||||
]);
|
||||
|
||||
return ogForOtherDocument(meta?.title ?? slug, content?.title ?? undefined);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Page
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user