15cc88909c
<!-- Thanks for opening a PR! Your contribution is much appreciated. In order to make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change that you're making: --> This adds a new example under cms-dotcms/. Is a general-purpose example that should allow developers to undestand how to use next.js with dotCMS apis. ## 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 - [x] 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 - [x] Make sure the linting passes by running `pnpm lint` - [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples) Co-authored-by: Daniel Esteves <estevesd8@gmail.com> Co-authored-by: Will Ezell <will@dotcms.com> Co-authored-by: Arcadio Quintero A <oidacra@gmail.com> Co-authored-by: Rafael <rjvelazco21@gmail.com>
31 lines
740 B
TypeScript
31 lines
740 B
TypeScript
import Image from 'next/image'
|
|
const DEFAULT_QUALITY = 20
|
|
|
|
// https://dotcms.com/docs/latest/image-resizing-and-processing
|
|
const getUrlWithResizingParameters = ({
|
|
src,
|
|
width,
|
|
quality = DEFAULT_QUALITY,
|
|
}) => {
|
|
const urlParams = []
|
|
const lastSeparatorIdx = src.lastIndexOf('/')
|
|
const imageIdentifierAndField = src.slice(0, lastSeparatorIdx)
|
|
|
|
urlParams.push(imageIdentifierAndField)
|
|
urlParams.push(width + 'w')
|
|
urlParams.push(quality + 'q')
|
|
|
|
return urlParams.join('/')
|
|
}
|
|
|
|
const dotCmsLoader = (props) => {
|
|
return `${process.env.NEXT_PUBLIC_DOTCMS_HOST}${getUrlWithResizingParameters(
|
|
props
|
|
)}`
|
|
}
|
|
|
|
const DotCmsImage = (params) => {
|
|
return <Image {...params} loader={dotCmsLoader} />
|
|
}
|
|
|
|
export default DotCmsImage
|