Buckets:
| import NextImage, { ImageLoaderProps } from "next/image"; | |
| import { transformImageUrl } from "@kontent-ai/delivery-sdk"; | |
| const srcIsKontentAsset = (src: string) => { | |
| try { | |
| const { hostname } = new URL(src); | |
| return hostname.endsWith(".kc-usercontent.com"); | |
| } catch { | |
| return false; | |
| } | |
| }; | |
| const kontentImageLoader = ({ | |
| src, | |
| width, | |
| quality = 75, | |
| }: ImageLoaderProps): string => { | |
| return transformImageUrl(src) | |
| .withWidth(width) | |
| .withQuality(quality) | |
| .withCompression("lossless") | |
| .withAutomaticFormat() | |
| .getUrl(); | |
| }; | |
| const getLoader = (src: string) => { | |
| return srcIsKontentAsset(src) ? kontentImageLoader : undefined; | |
| }; | |
| type ImageType = { | |
| width?: number; | |
| height?: number; | |
| src: string; | |
| layout?: string; | |
| className: string; | |
| alt: string; | |
| }; | |
| export default function Image(props: ImageType) { | |
| const loader = getLoader(props.src); | |
| return <NextImage {...props} loader={loader} />; | |
| } | |
Xet Storage Details
- Size:
- 939 Bytes
- Xet hash:
- e94a669902f630465649261cfbb0f91b9358f3efa203f2f3c31b74852f6c5ce9
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.