Skip to content

Commit 358afd1

Browse files
committed
adding custom image paths, tidying up npmignore
1 parent d63763e commit 358afd1

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
.env
33
# Local Netlify folder
44
.netlify
5+
_next

.npmignore

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
node_modules
21
.env
3-
tests
2+
.github
3+
.netlify
4+
_next
5+
demo
46
jest.config.js
5-
.github
7+
node_modules
8+
netlify.toml
9+
tests

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ By default, your images will served via the [fetch delivery method](https://clou
4343
|-----------------|----------|-------------|
4444
| cloudName | false* | Cloudinary Cloud Name |
4545
| deliveryType | false | The method in which Cloudinary stores and delivers images (Ex: fetch, upload) |
46+
| imagePath | false | Local path application serves image assets from |
4647
| folder | false | Folder all media will be stored in. Defaults to Netlify site name |
4748
| uploadPreset | false | Defined set of asset upload defaults in Cloudinary |
4849

manifest.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ inputs:
77
required: false
88
description: "The method in which Cloudinary stores and delivers images (Ex: fetch, upload)"
99
default: "fetch"
10+
- name: imagesPath
11+
required: false
12+
description: "Local path application serves image assets from"
13+
default: "/images"
1014
- name: folder
1115
required: false
1216
description: "Folder all media will be stored in. Defaults to Netlify site name"

src/index.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ const ncc = require('@vercel/ncc');
66
const { configureCloudinary, updateHtmlImagesToCloudinary } = require('./lib/cloudinary');
77
const { PREFIX, PUBLIC_ASSET_PATH } = require('./data/cloudinary');
88

9-
const CLOUDINARY_MEDIA_FUNCTIONS = ['images'];
9+
const CLOUDINARY_MEDIA_FUNCTIONS = [
10+
{
11+
name: 'images',
12+
inputKey: 'imagesPath',
13+
path: '/images'
14+
}
15+
];
1016

1117
/**
1218
* TODO
@@ -17,7 +23,11 @@ module.exports = {
1723

1824
async onBuild({ netlifyConfig, constants, inputs }) {
1925
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;
2131

2232
const cloudName = process.env.CLOUDINARY_CLOUD_NAME || inputs.cloudName;
2333

@@ -63,19 +73,20 @@ module.exports = {
6373

6474
// Redirect any requests that hits /[media type]/* to a serverless function
6575

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');
6779
const functionName = `${PREFIX}_${mediaName}`;
68-
const mediaPathSplat = `/${mediaName}/:splat`;
6980

7081
netlifyConfig.redirects.unshift({
71-
from: path.join(PUBLIC_ASSET_PATH, mediaName, '*'),
82+
from: path.join(PUBLIC_ASSET_PATH, mediaPath, '*'),
7283
to: mediaPathSplat,
7384
status: 200,
7485
force: true
7586
});
7687

7788
netlifyConfig.redirects.unshift({
78-
from: `/${mediaName}/*`,
89+
from: path.join(mediaPath, '*'),
7990
to: `/.netlify/functions/${functionName}?path=${mediaPathSplat}&${paramsString}`,
8091
status: 302,
8192
force: true,
@@ -98,7 +109,7 @@ module.exports = {
98109
const host = process.env.DEPLOY_PRIME_URL;
99110

100111
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.');
102113
console.log('Note: the Netlify CLI does not currently support the ability to determine the host locally, try deploying on Netlify.');
103114
return;
104115
}

0 commit comments

Comments
 (0)