ed81a14922
Found that this rule was added but all options are set to `false` so it doesn't do anything. Started with enabling it for examples to ensure minimal breaking of existing PRs. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
30 lines
720 B
JavaScript
30 lines
720 B
JavaScript
import NextImage from 'next/image'
|
|
import { transformImageUrl } from '@kentico/kontent-delivery'
|
|
|
|
const srcIsKontentAsset = (src) => {
|
|
try {
|
|
const { hostname } = new URL(src)
|
|
return hostname.endsWith('.kc-usercontent.com')
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|
|
|
|
const kontentImageLoader = ({ src, width, quality = 75 }) => {
|
|
return new transformImageUrl(src)
|
|
.withWidth(width)
|
|
.withQuality(quality)
|
|
.withCompression('lossless')
|
|
.withAutomaticFormat()
|
|
.getUrl()
|
|
}
|
|
|
|
const getLoader = (src) => {
|
|
return srcIsKontentAsset(src) ? kontentImageLoader : undefined
|
|
}
|
|
|
|
export default function Image(props) {
|
|
const loader = getLoader(props.src)
|
|
|
|
return <NextImage {...props} loader={loader} />
|
|
}
|