@@ -16,7 +16,11 @@ module.exports = {
16
16
17
17
async onPostBuild ( { constants, inputs } ) {
18
18
const { PUBLISH_DIR } = constants ;
19
- const { deliveryType, uploadPreset } = inputs ;
19
+ const {
20
+ deliveryType,
21
+ uploadPreset,
22
+ folder = process . env . SITE_NAME
23
+ } = inputs ;
20
24
21
25
const cloudName = process . env . CLOUDINARY_CLOUD_NAME || inputs . cloudName ;
22
26
const apiKey = process . env . CLOUDINARY_API_KEY ;
@@ -90,14 +94,19 @@ module.exports = {
90
94
91
95
const id = `${ imgName } -${ hash } ` ;
92
96
97
+ const uploadOptions = {
98
+ folder,
99
+ public_id : id
100
+ }
101
+
93
102
let results ;
94
-
103
+
95
104
if ( apiKey && apiSecret ) {
96
105
// We need an API Key and Secret to use signed uploading
97
106
98
107
try {
99
108
results = await cloudinary . uploader . upload ( imgSrc , {
100
- public_id : id ,
109
+ ... uploadOptions ,
101
110
overwrite : false
102
111
} ) ;
103
112
} catch ( e ) {
@@ -114,7 +123,7 @@ module.exports = {
114
123
115
124
try {
116
125
results = await cloudinary . uploader . unsigned_upload ( imgSrc , uploadPreset , {
117
- public_id : id ,
126
+ ... uploadOptions
118
127
// Unsigned uploads default to overwrite: false
119
128
} ) ;
120
129
} catch ( e ) {
@@ -169,7 +178,7 @@ function isRemoteUrl(path) {
169
178
return path . startsWith ( 'http' ) ;
170
179
}
171
180
172
- /**
181
+ /**
173
182
* determineRemoteUrl
174
183
*/
175
184
@@ -181,7 +190,7 @@ function determineRemoteUrl(path) {
181
190
if ( ! path . startsWith ( '/' ) ) {
182
191
url = `/${ url } ` ;
183
192
}
184
-
193
+
185
194
url = `${ process . env . DEPLOY_PRIME_URL } ${ url } ` ;
186
195
187
196
return url ;
0 commit comments