@@ -22,7 +22,7 @@ const CLOUDINARY_MEDIA_FUNCTIONS = [
22
22
module . exports = {
23
23
24
24
async onBuild ( { netlifyConfig, constants, inputs } ) {
25
- const { FUNCTIONS_SRC , INTERNAL_FUNCTIONS_SRC } = constants ;
25
+ const { FUNCTIONS_SRC , INTERNAL_FUNCTIONS_SRC , PUBLISH_DIR } = constants ;
26
26
const {
27
27
deliveryType,
28
28
folder = process . env . SITE_NAME ,
@@ -35,6 +35,64 @@ module.exports = {
35
35
throw new Error ( 'Cloudinary Cloud Name required. Please set cloudName input or use environment variable CLOUDINARY_CLOUD_NAME' ) ;
36
36
}
37
37
38
+ const imagesDirectory = glob . sync ( `${ PUBLISH_DIR } /images/**/*` ) ;
39
+ const imagesFiles = imagesDirectory . filter ( file => ! ! path . extname ( file ) ) ;
40
+
41
+ imagesFiles . forEach ( file => {
42
+ const filePath = file . replace ( PUBLISH_DIR , '' ) ;
43
+
44
+ netlifyConfig . redirects . unshift ( {
45
+ from : `${ path . join ( PUBLIC_ASSET_PATH , filePath ) } *` ,
46
+ to : `${ filePath } :splat` ,
47
+ status : 200 ,
48
+ force : true
49
+ } ) ;
50
+
51
+ netlifyConfig . redirects . unshift ( {
52
+ from : `${ filePath } *` ,
53
+ to : `https://res.cloudinary.com/colbycloud/image/fetch/f_auto,q_auto/${ process . env . DEPLOY_PRIME_URL } /${ path . join ( PUBLIC_ASSET_PATH , filePath ) } :splat` ,
54
+ status : 200 ,
55
+ force : true
56
+ } ) ;
57
+
58
+ // netlifyConfig.redirects.unshift({
59
+ // from: `${filePath}*`,
60
+ // to: `/.netlify/functions/${functionName}?path=${mediaPathSplat}&${paramsString}`,
61
+ // status: 302,
62
+ // force: true,
63
+ // });
64
+ } )
65
+
66
+ return ;
67
+
68
+ CLOUDINARY_MEDIA_FUNCTIONS . forEach ( ( { name : mediaName , inputKey, path : defaultPath } ) => {
69
+ const mediaPath = inputs [ inputKey ] || defaultPath ;
70
+ const mediaPathSplat = path . join ( mediaPath , ':splat' ) ;
71
+ const functionName = `${ PREFIX } _${ mediaName } ` ;
72
+
73
+ netlifyConfig . redirects . unshift ( {
74
+ from : path . join ( PUBLIC_ASSET_PATH , mediaPath , '*' ) ,
75
+ to : mediaPathSplat ,
76
+ status : 200 ,
77
+ force : true
78
+ } ) ;
79
+
80
+ netlifyConfig . redirects . unshift ( {
81
+ from : path . join ( mediaPath , '*' ) ,
82
+ to : `/.netlify/functions/${ functionName } ?path=${ mediaPathSplat } &${ paramsString } ` ,
83
+ status : 302 ,
84
+ force : true ,
85
+ } ) ;
86
+ } ) ;
87
+
88
+
89
+
90
+
91
+ console . log ( 'PUBLISH_DIR' , PUBLISH_DIR ) ;
92
+ console . log ( 'imagesFiles' , imagesFiles ) ;
93
+
94
+ throw new Error ( 'asdf' ) ;
95
+
38
96
const functionsPath = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC ;
39
97
40
98
// Copy all of the templates over including the functions to deploy
0 commit comments