feat: support per collection public_folder (#3069)
* feat: support per collection public_folder * test: improve tests readability
This commit is contained in:
committed by
Shawn Erquhart
parent
476f45096e
commit
0a50efda8e
@ -182,7 +182,7 @@ describe('entries', () => {
|
||||
).toBe('/media/image.png');
|
||||
});
|
||||
|
||||
it('should resolve path from public folder when in editorial workflow for collection with no media folder', () => {
|
||||
it('should resolve path from public folder when in editorial workflow for collection with no public folder', () => {
|
||||
expect(
|
||||
selectMediaFilePublicPath(
|
||||
Map({ public_folder: '/media', publish_mode: EDITORIAL_WORKFLOW }),
|
||||
@ -192,21 +192,21 @@ describe('entries', () => {
|
||||
).toBe('/media/image.png');
|
||||
});
|
||||
|
||||
it('should resolve path from collection media folder when in editorial workflow for collection with media folder', () => {
|
||||
it('should resolve path from collection media folder when in editorial workflow for collection with public folder', () => {
|
||||
expect(
|
||||
selectMediaFilePublicPath(
|
||||
Map({ public_folder: '/media', publish_mode: EDITORIAL_WORKFLOW }),
|
||||
Map({ name: 'posts', folder: 'posts', media_folder: '' }),
|
||||
Map({ name: 'posts', folder: 'posts', public_folder: '' }),
|
||||
'image.png',
|
||||
),
|
||||
).toBe('image.png');
|
||||
});
|
||||
|
||||
it('should handle relative media_folder', () => {
|
||||
it('should handle relative public_folder', () => {
|
||||
expect(
|
||||
selectMediaFilePublicPath(
|
||||
Map({ public_folder: '/media', publish_mode: EDITORIAL_WORKFLOW }),
|
||||
Map({ name: 'posts', folder: 'posts', media_folder: '../../static/media/' }),
|
||||
Map({ name: 'posts', folder: 'posts', public_folder: '../../static/media/' }),
|
||||
'image.png',
|
||||
),
|
||||
).toBe('../../static/media/image.png');
|
||||
|
@ -190,8 +190,8 @@ export const selectMediaFilePublicPath = (
|
||||
let publicFolder = config.get('public_folder');
|
||||
|
||||
const useWorkflow = config.get('publish_mode') === EDITORIAL_WORKFLOW;
|
||||
if (useWorkflow && collection && collection.has('media_folder')) {
|
||||
publicFolder = collection.get('media_folder') as string;
|
||||
if (useWorkflow && collection && collection.has('public_folder')) {
|
||||
publicFolder = collection.get('public_folder') as string;
|
||||
}
|
||||
|
||||
return join(publicFolder, basename(mediaPath));
|
||||
|
Reference in New Issue
Block a user