fix: allow absolute urls in public_folder (#5311)
This commit is contained in:
@ -68,6 +68,7 @@
|
||||
"semaphore": "^1.0.5",
|
||||
"tomlify-j0.4": "^3.0.0-alpha.0",
|
||||
"url": "^0.11.0",
|
||||
"url-join": "^4.0.1",
|
||||
"what-input": "^5.1.4",
|
||||
"yaml": "^1.8.3"
|
||||
},
|
||||
@ -90,6 +91,7 @@
|
||||
"devDependencies": {
|
||||
"@types/history": "^4.7.8",
|
||||
"@types/redux-mock-store": "^1.0.2",
|
||||
"@types/url-join": "^4.0.0",
|
||||
"redux-mock-store": "^1.5.3"
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import url from 'url';
|
||||
import urlJoin from 'url-join';
|
||||
import diacritics from 'diacritics';
|
||||
import sanitizeFilename from 'sanitize-filename';
|
||||
import { isString, escapeRegExp, flow, partialRight } from 'lodash';
|
||||
@ -115,3 +116,7 @@ export function sanitizeSlug(str: string, options?: CmsSlug) {
|
||||
|
||||
return normalizedSlug;
|
||||
}
|
||||
|
||||
export function joinUrlPath(base: string, ...path: string[]) {
|
||||
return urlJoin(base, ...path);
|
||||
}
|
||||
|
@ -435,6 +435,22 @@ describe('entries', () => {
|
||||
).toBe('../../static/media/image.png');
|
||||
});
|
||||
|
||||
it('should handle absolute public_folder', () => {
|
||||
expect(
|
||||
selectMediaFilePublicPath(
|
||||
{ public_folder: 'https://www.netlify.com/media' },
|
||||
fromJS({
|
||||
name: 'posts',
|
||||
folder: 'posts',
|
||||
public_folder: 'https://www.netlify.com/media',
|
||||
}),
|
||||
'image.png',
|
||||
undefined,
|
||||
undefined,
|
||||
),
|
||||
).toBe('https://www.netlify.com/media/image.png');
|
||||
});
|
||||
|
||||
it('should compile collection public folder template', () => {
|
||||
const slugConfig = {
|
||||
encoding: 'unicode',
|
||||
|
@ -59,6 +59,7 @@ import { trim, once, sortBy, set, orderBy, groupBy } from 'lodash';
|
||||
import { selectSortDataPath } from './collections';
|
||||
import { stringTemplate } from 'netlify-cms-lib-widgets';
|
||||
import { VIEW_STYLE_LIST } from '../constants/collectionViews';
|
||||
import { joinUrlPath } from '../lib/urlHelper';
|
||||
|
||||
const { keyToPathArray } = stringTemplate;
|
||||
|
||||
@ -790,6 +791,10 @@ export function selectMediaFilePublicPath(
|
||||
publicFolder = evaluateFolder(name, config, collection!, entryMap, field);
|
||||
}
|
||||
|
||||
if (isAbsolutePath(publicFolder)) {
|
||||
return joinUrlPath(publicFolder, basename(mediaPath));
|
||||
}
|
||||
|
||||
return join(publicFolder, basename(mediaPath));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user