Download next.js/examples/cms-dotcms/components/dotcms-image.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 756 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/examples/cms-dotcms/components/dotcms-image.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/examples/cms-dotcms/components/dotcms-image.tsx
-
curl -L -o dotcms-image.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/examples/cms-dotcms/components/dotcms-image.tsx
756 Bytes
| 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; | |