Skip to content

Commit

Permalink
Update cms-kontent example to action PR feedback
Browse files Browse the repository at this point in the history
* Updates the `cms-kontent` example `Image` component to implement the
  suggested improvements from @styfle in vercel#37188.
* Simplifies the Kontent loader host checking.
* Reduces the default image quality to from `100` to `75`.

vercel#37188
  • Loading branch information
tommarshall committed May 26, 2022
1 parent 82a9d21 commit 88684aa
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions examples/cms-kontent/components/image.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import NextImage from 'next/image'
import { transformImageUrl } from '@kentico/kontent-delivery'

const KONTENT_ASSET_HOSTNAME_REGEX = /.kc-usercontent.com$/

const getLoader = (src) => {
return srcIsKontentAsset(src) ? kontentImageLoader : undefined
}

const srcIsKontentAsset = (src) => {
try {
const { hostname } = new URL(src)
return KONTENT_ASSET_HOSTNAME_REGEX.test(hostname)
return hostname.endsWith('.kc-usercontent.com')
} catch {
return false
}
}

const kontentImageLoader = ({ src, width, quality = 100 }) => {
const kontentImageLoader = ({ src, width, quality = 75 }) => {
return new transformImageUrl(src)
.withWidth(width)
.withQuality(quality)
Expand Down

0 comments on commit 88684aa

Please sign in to comment.