You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Netlify Large Media has been deprecarted, but Netlify now provides Netlify Image CDN for working with images. Thus, I have written a custom provider that seems to work:
import{createOperationsGenerator}from'#image'import{joinURL}from'ufo'importtype{ProviderGetImage}from'@nuxt/image'exportconstgetImage : ProviderGetImage=(src,options={})=>{if(!options.baseURL){options.baseURL='/.netlify/images'}constsupportedFits=['contain','cover','fill']asconstconstsupportedFormats=['avif','blurhash','gif','jpg','png','webp']asconstconstsupportedModifiers=['fit','format','height','position','quality','width']asconstfunctioncheckSupport(supportArray : ReadonlyArray<string>,stringToCheck : string,typeOfCheck : 'fit'|'format'|'modifier',callback? : ()=>void){if(!supportArray.includes(stringToCheck)){console.error(`${typeOfCheck}: ${stringToCheck} is not supported by Netlify Image CDN.`)}elseif(callback){callback()}}functiongenerateValueMap(arrayOfValues : ReadonlyArray<string>) : Record<string,string>{returnarrayOfValues.reduce((generatedConfig,currentConfigItem)=>{constcurrentConfig=generatedConfigcurrentConfig[currentConfigItem]=currentConfigItemreturncurrentConfig},{}asRecord<string,string>)}if(options.modifiers){Object.keys(options.modifiers).forEach(modifier=>{checkSupport(supportedModifiers,modifier.toLowerCase(),'modifier')})if(options.modifiers.fit){checkSupport(supportedFits,options.modifiers.fit.toLowerCase(),'fit',()=>{console.warn('fit in Nuxt Image and Netlify Image CDN works differently. Please refer to appropriate docs to find the correct value.')})}if(options.modifiers.format){checkSupport(supportedFormats,options.modifiers.format.toLowerCase(),'format')}}return{url: joinURL(options.baseURL,`?url=${src}&${createOperationsGenerator({formatter: (key : string,value : string)=>{return`${key}=${value}`},joinWith: '&',keyMap: {fit: 'fit',format: 'fm',height: 'h',quality: 'q',width: 'w'},valueMap: {fit: generateValueMap(supportedFormats),format: generateValueMap(supportedFormats)}})(options.modifiers)}`)}}
The reason I am not submitting a PR is because I'm not confident writing the tests (I don't fully understand how tests are written for this module). Here's the Netlify Image CDN docs: https://docs.netlify.com/image-cdn/overview/
Netlify Large Media has been deprecarted, but Netlify now provides Netlify Image CDN for working with images. Thus, I have written a custom provider that seems to work:
The reason I am not submitting a PR is because I'm not confident writing the tests (I don't fully understand how tests are written for this module). Here's the Netlify Image CDN docs: https://docs.netlify.com/image-cdn/overview/
For the docs, the following note would be needed:
netlify.toml
: https://docs.netlify.com/image-cdn/overview/#remote-pathThe text was updated successfully, but these errors were encountered: