[READ-ONLY] Mirror of https://github.com/danielroe/dwaring87-webdev-wedding. Marissa & David's Wedding Website!
0

Configure Feed

Select the types of activity you want to include in your feed.

Directus Image Provider: clean up generated URL

+24 -18
+24 -18
providers/directus.js
··· 36 36 formatter: (key, value) => `${key}=${value}` 37 37 }); 38 38 39 - export const getImage = (src, { 39 + // Convert the Directus-specific modifiers into the required transforms format 40 + // https://docs.directus.io/reference/files.html#advanced-transformations 41 + const transformsGenerator = (transforms) => { 42 + let rtn = []; 43 + if ( transforms && typeof transforms === 'object' ) { 44 + for ( const key in transforms ) { 45 + if ( transforms.hasOwnProperty(key) ) { 46 + let value = transforms[key]; 47 + rtn.push([key, value]) 48 + } 49 + } 50 + } 51 + return rtn.length > 0 ? JSON.stringify(rtn) : undefined; 52 + } 53 + 54 + export const getImage = ( 55 + src, 56 + { 40 57 modifiers = {}, 41 58 baseURL, 42 59 token, 43 60 output_dir = '.output/public/', 44 61 image_dir = '_images/' 45 - } = {}) => { 62 + } = {} 63 + ) => { 46 64 47 65 // Base URL is a required provider option (set in nuxt.config file) 48 66 if ( !baseURL || baseURL === '' ) { ··· 53 71 const { width, height, format, quality, fit, ...providerModifiers } = modifiers; 54 72 const params = operationsGenerator({ width, height, format, quality, fit }); 55 73 const transforms = transformsGenerator(providerModifiers); 56 - const url = withQuery(joinURL(baseURL, 'assets', src, params ? '?' + params : ''), { transforms, access_token: token}); 74 + const url = withQuery( 75 + joinURL(baseURL, 'assets', src) + (params ? '?' + params : ''), 76 + { transforms, access_token: token } 77 + ); 57 78 58 79 // TEMP: Generate the images when run on the server during prerendering 59 80 if ( process.server && process.env.prerender ) { ··· 77 98 else { 78 99 return { url } 79 100 } 80 - } 81 - 82 - // Convert the Directus-specific modifiers into the required transforms format 83 - // https://docs.directus.io/reference/files.html#advanced-transformations 84 - function transformsGenerator(transforms) { 85 - let rtn = []; 86 - if ( transforms && typeof transforms === 'object' ) { 87 - for ( const key in transforms ) { 88 - if ( transforms.hasOwnProperty(key) ) { 89 - let value = transforms[key]; 90 - rtn.push([key, value]) 91 - } 92 - } 93 - } 94 - return rtn.length > 0 ? JSON.stringify(rtn) : undefined; 95 101 } 96 102 97 103 // TEMP: Generate local static images for the specified remote URL