fix: og image generation

This commit is contained in:
gosangam
2026-05-06 01:35:06 +05:30
parent b81b18632d
commit de374eab8b
27 changed files with 703 additions and 4 deletions
+14 -1
View File
@@ -4,7 +4,7 @@ import type { Metadata } from "next";
import Link from "next/link";
import { notFound } from "next/navigation";
import { getLetter, getAdjacentLetters } from "@/lib/letters";
import { ogForLetter } from "@/lib/og";
import { ogForLetter, extractQuoteFromHl, buildOgMeta } from "@/lib/og";
import { PageHeader } from "@/components/page-header";
import { Card, CardContent } from "@/components/ui/card";
import { buttonVariants } from "@/components/ui/button";
@@ -13,14 +13,27 @@ import { cn } from "@/lib/utils";
export async function generateMetadata({
params,
searchParams,
}: {
params: Promise<{ slug: string }>;
searchParams: Promise<Record<string, string | string[] | undefined>>;
}): Promise<Metadata> {
const { slug } = await params;
const sp = await searchParams;
const letter = await getLetter(slug);
if (!letter) return {};
const meta = [letter.date, letter.location].filter(Boolean).join(" · ");
const hlQuote = extractQuoteFromHl(sp);
if (hlQuote) {
return buildOgMeta({
title: `Letter to ${letter.recipientDisplay}`,
detail: meta || undefined,
quote: hlQuote,
});
}
return ogForLetter(letter.recipientDisplay, meta || undefined);
}