@@ -6,7 +6,13 @@ const ncc = require('@vercel/ncc');
6
6
const { configureCloudinary, updateHtmlImagesToCloudinary } = require ( './lib/cloudinary' ) ;
7
7
const { PREFIX , PUBLIC_ASSET_PATH } = require ( './data/cloudinary' ) ;
8
8
9
- const CLOUDINARY_MEDIA_FUNCTIONS = [ 'images' ] ;
9
+ const CLOUDINARY_MEDIA_FUNCTIONS = [
10
+ {
11
+ name : 'images' ,
12
+ inputKey : 'imagesPath' ,
13
+ path : '/images'
14
+ }
15
+ ] ;
10
16
11
17
/**
12
18
* TODO
@@ -17,7 +23,11 @@ module.exports = {
17
23
18
24
async onBuild ( { netlifyConfig, constants, inputs } ) {
19
25
const { FUNCTIONS_SRC , INTERNAL_FUNCTIONS_SRC } = constants ;
20
- const { uploadPreset, deliveryType, folder = process . env . SITE_NAME } = inputs ;
26
+ const {
27
+ deliveryType,
28
+ folder = process . env . SITE_NAME ,
29
+ uploadPreset,
30
+ } = inputs ;
21
31
22
32
const cloudName = process . env . CLOUDINARY_CLOUD_NAME || inputs . cloudName ;
23
33
@@ -63,19 +73,20 @@ module.exports = {
63
73
64
74
// Redirect any requests that hits /[media type]/* to a serverless function
65
75
66
- CLOUDINARY_MEDIA_FUNCTIONS . forEach ( mediaName => {
76
+ CLOUDINARY_MEDIA_FUNCTIONS . forEach ( ( { name : mediaName , inputKey, path : defaultPath } ) => {
77
+ const mediaPath = inputs [ inputKey ] || defaultPath ;
78
+ const mediaPathSplat = path . join ( mediaPath , ':splat' ) ;
67
79
const functionName = `${ PREFIX } _${ mediaName } ` ;
68
- const mediaPathSplat = `/${ mediaName } /:splat` ;
69
80
70
81
netlifyConfig . redirects . unshift ( {
71
- from : path . join ( PUBLIC_ASSET_PATH , mediaName , '*' ) ,
82
+ from : path . join ( PUBLIC_ASSET_PATH , mediaPath , '*' ) ,
72
83
to : mediaPathSplat ,
73
84
status : 200 ,
74
85
force : true
75
86
} ) ;
76
87
77
88
netlifyConfig . redirects . unshift ( {
78
- from : `/ ${ mediaName } /*` ,
89
+ from : path . join ( mediaPath , '*' ) ,
79
90
to : `/.netlify/functions/${ functionName } ?path=${ mediaPathSplat } &${ paramsString } ` ,
80
91
status : 302 ,
81
92
force : true ,
@@ -98,7 +109,7 @@ module.exports = {
98
109
const host = process . env . DEPLOY_PRIME_URL ;
99
110
100
111
if ( ! host ) {
101
- console . log ( 'Can not determine Netlify host, not proceeding with on-page image replacement.' ) ;
112
+ console . warn ( 'Can not determine Netlify host, not proceeding with on-page image replacement.' ) ;
102
113
console . log ( 'Note: the Netlify CLI does not currently support the ability to determine the host locally, try deploying on Netlify.' ) ;
103
114
return ;
104
115
}
0 commit comments