fix: allow absolute urls in public_folder (#5311)
This commit is contained in:
@ -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