|
| 1 | +import { type SanityDocument } from "next-sanity"; |
| 2 | +import { client } from "@/sanity/lib/client"; |
| 3 | +import Image from "next/image"; |
| 4 | +import createImageUrlBuilder from "@sanity/image-url"; |
| 5 | +import type SanityImageSource from "@sanity/image-url"; |
| 6 | +import Link from "next/link"; |
| 7 | +import { notFound } from "next/navigation"; |
| 8 | + |
| 9 | +// Create an image URL builder using the client |
| 10 | +const builder = createImageUrlBuilder(client); |
| 11 | + |
| 12 | +// Export a function that can be used to get image URLs |
| 13 | +export function urlFor(source: typeof SanityImageSource) { |
| 14 | + return builder.image(source); |
| 15 | +} |
| 16 | + |
| 17 | +const DATASET_QUERY = `*[_type == "peopleType" && slug.current == $slug][0] |
| 18 | + {_id, fullname, email, bio, image, recentwork, jobtitles, interests, slug}`; |
| 19 | + |
| 20 | +const options = { next: { revalidate: 30 } }; |
| 21 | + |
| 22 | +export default async function SanityExampleDataset({ |
| 23 | + params, |
| 24 | +}: { |
| 25 | + params: Promise<{ slug: string }>; |
| 26 | +}) { |
| 27 | + const { slug } = await params; |
| 28 | + const dataset = await client.fetch<SanityDocument | null>( |
| 29 | + DATASET_QUERY, |
| 30 | + { slug }, |
| 31 | + options, |
| 32 | + ); |
| 33 | + |
| 34 | + if (!dataset) notFound(); |
| 35 | + |
| 36 | + return ( |
| 37 | + <div className=""> |
| 38 | + <div className="flex bg-gray-100"> |
| 39 | + <div className="max-w-1/2"> |
| 40 | + <h1 className="text-7xl mt-[5rem] ml-[6rem]">{dataset.fullname}</h1> |
| 41 | + <p className="text-gray-500 mt-[0.6rem] ml-[6rem]"> |
| 42 | + {dataset.jobtitles.join(", ")} |
| 43 | + </p> |
| 44 | + <p className="mt-[0.5rem] mt-[1.5rem] ml-[6rem]"> |
| 45 | + {" "} |
| 46 | + Email:{" "} |
| 47 | + <a className="hover:underline" href={`mailto:${dataset.email}`}> |
| 48 | + {dataset.email} |
| 49 | + </a> |
| 50 | + </p> |
| 51 | + </div> |
| 52 | + <div className=" mb-[5rem] mt-[5rem] ml-auto mr-[5rem]"> |
| 53 | + <Image |
| 54 | + alt="generic profile image" |
| 55 | + src={urlFor(dataset.image).url()} |
| 56 | + width={400} |
| 57 | + height={400} |
| 58 | + /> |
| 59 | + </div> |
| 60 | + </div> |
| 61 | + <div className="flex"> |
| 62 | + <div> |
| 63 | + <hr |
| 64 | + style={{ |
| 65 | + width: "20rem", |
| 66 | + marginTop: "6rem", |
| 67 | + marginLeft: "6rem", |
| 68 | + marginBottom: "0.5rem", |
| 69 | + }} |
| 70 | + ></hr> |
| 71 | + <p className="text-lg mt-[1rem] ml-[6rem]"> |
| 72 | + {dataset.interests.join(", ")} |
| 73 | + </p> |
| 74 | + </div> |
| 75 | + <div> |
| 76 | + <p className="text-lg mt-[6rem] mb-[1rem] ml-[6rem] mr-[5rem]"> |
| 77 | + {dataset.bio} |
| 78 | + </p> |
| 79 | + <a |
| 80 | + className="font-bold text-lg ml-[6rem] hover:underline" |
| 81 | + href={`${dataset.recentwork}`} |
| 82 | + > |
| 83 | + Their most recent work |
| 84 | + </a> |
| 85 | + </div> |
| 86 | + </div> |
| 87 | + </div> |
| 88 | + ); |
| 89 | +} |
0 commit comments