|
1 | | -import type { CloudinaryAsset } from "@/sanity/types"; |
2 | | -import CloudinaryImage from "@/components/cloudinary-image"; |
3 | | -import { getCldImageUrl } from "next-cloudinary"; |
4 | | -import { stegaClean } from "@sanity/client/stega"; |
| 1 | +import Image from "next/image"; |
| 2 | +import { urlForImage } from "@/sanity/lib/image"; |
5 | 3 |
|
6 | 4 | interface CoverImageProps { |
7 | | - image: CloudinaryAsset | null | undefined; |
8 | | - priority?: boolean; |
9 | | - className?: string; |
10 | | - width?: number; |
11 | | - height?: number; |
12 | | - quality?: number | `${number}`; |
| 5 | + image: any; |
| 6 | + priority?: boolean; |
| 7 | + className?: string; |
| 8 | + width?: number; |
| 9 | + height?: number; |
| 10 | + quality?: number; |
13 | 11 | } |
14 | 12 |
|
15 | | -export default async function CoverImage(props: CoverImageProps) { |
16 | | - const { |
17 | | - image: originalImage, |
18 | | - priority, |
19 | | - className, |
20 | | - width, |
21 | | - height, |
22 | | - quality, |
23 | | - } = props; |
| 13 | +export default function CoverImage(props: CoverImageProps) { |
| 14 | + const { image, priority, className, width, height, quality } = props; |
24 | 15 |
|
25 | | - const source = stegaClean(originalImage); |
| 16 | + const imageUrl = image?.asset?._ref |
| 17 | + ? urlForImage(image)?.width(width || 1920).height(height || 1080).quality(quality || 80).url() |
| 18 | + : null; |
26 | 19 |
|
27 | | - const getImageUrl = async (src: string) => { |
28 | | - const imageUrl = getCldImageUrl({ |
29 | | - src, |
30 | | - width: 100, |
31 | | - }); |
32 | | - const response = await fetch(imageUrl); |
33 | | - const arrayBuffer = await response.arrayBuffer(); |
34 | | - const buffer = Buffer.from(arrayBuffer); |
35 | | - const base64 = buffer.toString("base64"); |
36 | | - return `data:${response.type};base64,${base64}`; |
37 | | - }; |
| 20 | + if (!imageUrl) { |
| 21 | + return ( |
| 22 | + <div className="transition-shadow duration-200 shadow-md group-hover:shadow-lg sm:mx-0"> |
| 23 | + <div className="bg-background" style={{ paddingTop: "50%" }} /> |
| 24 | + </div> |
| 25 | + ); |
| 26 | + } |
38 | 27 |
|
39 | | - let image: JSX.Element | undefined; |
40 | | - if (source?.public_id) { |
41 | | - image = ( |
42 | | - <CloudinaryImage |
43 | | - className={className || "w-full h-auto aspect-video rounded-md"} |
44 | | - width={width || 1920} |
45 | | - height={height || 1080} |
46 | | - priority={priority} |
47 | | - quality={quality || "auto"} |
48 | | - sizes="(max-width: 768px) 100vw,(max-width: 1200px) 50vw, 33vw" |
49 | | - alt={source?.context?.custom?.alt || ""} |
50 | | - src={source?.public_id} |
51 | | - placeholder="blur" |
52 | | - blurDataURL={await getImageUrl(source.public_id)} |
53 | | - /> |
54 | | - ); |
55 | | - } else { |
56 | | - image = <div className="bg-background" style={{ paddingTop: "50%" }} />; |
57 | | - } |
58 | | - |
59 | | - return ( |
60 | | - <div className="transition-shadow duration-200 shadow-md group-hover:shadow-lg sm:mx-0"> |
61 | | - {image} |
62 | | - </div> |
63 | | - ); |
| 28 | + return ( |
| 29 | + <div className="transition-shadow duration-200 shadow-md group-hover:shadow-lg sm:mx-0"> |
| 30 | + <Image |
| 31 | + className={className || "w-full h-auto aspect-video rounded-md"} |
| 32 | + width={width || 1920} |
| 33 | + height={height || 1080} |
| 34 | + priority={priority} |
| 35 | + quality={quality || 80} |
| 36 | + sizes="(max-width: 768px) 100vw,(max-width: 1200px) 50vw, 33vw" |
| 37 | + alt={image?.alt || ""} |
| 38 | + src={imageUrl} |
| 39 | + /> |
| 40 | + </div> |
| 41 | + ); |
64 | 42 | } |
0 commit comments