import { client, urlFor } from "@/lib/sanity"; import { PortableText } from "@portabletext/react"; import Image from "next/image"; import Link from "next/link"; import { ArrowLeft } from "lucide-react"; import { Separator } from "@/components/ui/separator"; import { notFound } from "next/navigation"; import { Metadata } from "next"; import { format } from "date-fns"; async function getData(slug: string) { const query = ` *[_type == "blog" && slug.current == '${slug}'] { "currentSlug": slug.current, title, content, titleImage, _createdAt }[0]`; const data = await client.fetch(query); return data; } interface BlogSlugArticle { currentSlug: string; title: string; content: any; titleImage: string; _createdAt: string; } export async function generateMetadata({ params, }: { params: { slug: string }; }): Promise { const data = await getData(params.slug); if (!data) { return { title: "Not Found", description: "Blog post not found", }; } return { title: data.title, description: data.smallDescription, openGraph: { title: data.title, description: data.smallDescription, url: `https://svrjs.org/blog/${data.currentSlug}`, type: "website", images: [ { url: urlFor(data.titleImage).url(), width: 800, height: 600, alt: data.title, }, ], }, twitter: { card: "summary_large_image", site: "@SVR_JS", title: data.title, description: data.smallDescription, images: [urlFor(data.titleImage).url()], creator: "@SVR_JS", }, }; } export default async function BlogSlugArticle({ params, }: { params: { slug: string }; }) { const data: BlogSlugArticle = await getData(params.slug); if (!data) { notFound(); } const formattedDate = format(new Date(data._createdAt), "MMMM d, yyyy"); return ( <>
Back to Blog
{data.titleImage && (

{data.title}

{data.title}

Uploaded at {formattedDate}

{" "}
)}
); }