jsx
import { client } from "@/sanity/sanityClient";
import { groq } from "next-sanity";
const query = groq`*[_type == "post" && slug.current == $slug][0]{
_id,
title,
"date": createdAt,
"image": mainImage.asset->url,
"slug": slug.current,
'author': author->{name, 'picture': image.asset->url},
body
}`;
export default async function getSinglePost(slug) {
if (client) {
return (await client.fetch(query, { slug })) || {};
}
return {};
}
Comments