import BlogComments from "@/components/BlogComments"; import BlogWidget from "@/components/BlogWidget"; import CommentForm from "@/components/CommentForm"; import { allBlogs } from "@/data/blogs"; import payloadConfig from "@/payload.config"; import { formatDate } from "@/utils/datetime"; import Image from "next/image"; import { getPayload } from "payload"; import { RichText } from "@payloadcms/richtext-lexical/react"; import { Metadata } from "next"; async function fetchBlog(slug: string) { const payload = await getPayload({ config: payloadConfig }); const blogDataQuery = await payload.find({ collection: "blogs", where: { slug: { equals: slug }, }, limit: 1, pagination: false, }); if (!blogDataQuery?.docs?.[0]) return null; const data = blogDataQuery?.docs?.[0]; const createdAt = formatDate(data.createdAt); const imgUrl = typeof data.img !== "number" ? (data?.img?.url ?? "") : ""; return { data, createdAt, imgUrl, }; } export async function generateMetadata({ params, }: { params: { slug: string }; }): Promise { const blog = await fetchBlog(params.slug); if (!blog) { return { title: "Cochise Oncology", description: "Cochise Oncology", openGraph: { title: "Cochise Oncology", description: "Cochise Oncology", images: [""], }, }; } const title = `${blog.data.title} - Cochise Oncology`; return { title: title, description: title, openGraph: { title: title, description: title, images: [blog.imgUrl || ""], }, }; } export default async function BlogRead({ params, }: { params: Promise<{ slug: string }>; }) { const slug = (await params).slug; const data = await fetchBlog(slug); if (!data) return <>; const blog = allBlogs.filter((elm) => elm.id == 34)[0] || allBlogs[0]; return ( <>
{/* */}
{/* */}

{data.data.title}

{/* Author, Categories, Comments */} {/* End Author, Categories, Comments */}
<> {/* Section */}
{/* Content */}
{/* Post */}
Image Description
{/* End Post */} {/* Comments */}

Comments (3)

{/* End Comments */} {/* Add Comment */}

Leave a comment

{/* Form */} {/* End Form */}
{/* End Add Comment */} {/* Prev/Next Post */} {/* End Prev/Next Post */}
{/* End Content */}
{/* End Section */} {/* Divider */}
{/* End Divider */} {/* Section */}
); }