Ability to add version for cloudinary provider
Hello, Thank you very much for this module ! I am using it with cloudinary as a provider, but I would like to set the version in the url (the timestamp used to bypass cache issues). I can not include it in the baseURL since it comes after the transformation string. Is there anything planned to address this ? Thank you again
@Davounet You could create your own custom provider, something like this:
export const getImage = (src, { modifiers = {}, baseURL = '/' } = {}, { $img }) => {
const url = $img.cloudinary(src, { modifiers, baseURL })
return {
url: url + '?timestamp=' + Date.now()
}
}
@danielroe Thank you for your answer
I'm trying with your solution, but I can't access the existing cloudinary helper inside $img
I am trying to find it somewhere in the module, but without success for now. I'll keep trying ;)
I got it working with the following :
Inside nuxt.config.js
image: {
provider: 'custom',
providers: {
custom: {
provider: '~/providers/custom',
options: {
version: `v${Math.round(Date.now() / 1000)}`
}
}
},
cloudinary: {
baseURL: 'https://res.cloudinary.com/numorning/image/upload/'
}
}
the custom.js provider
export function getImage(src, { modifiers = {} }, { options }) {
const baseURL = options.providers.cloudinary.defaults.baseURL
const { url: base } = options.providers.cloudinary.provider.getImage('/', { modifiers, baseURL })
const version = options.providers.custom.defaults.version
const url = `${base}/${version}/${src}`
return { url }
}
Thank you again !