fix: don't use getAsset for draft entries (#3403)

This commit is contained in:
Erez Rokah
2020-03-22 16:53:06 +02:00
committed by GitHub
parent e92ba412d8
commit 45a1654404
10 changed files with 102 additions and 120 deletions

View File

@ -142,7 +142,7 @@ describe('entries', () => {
folder: 'src/docs/getting-started',
media_folder: '/static/images/docs/getting-started',
}),
fromJS({ path: 'src/docs/getting-started/with-github.md' }),
fromJS({}),
undefined,
),
).toEqual('static/images/docs/getting-started');
@ -184,7 +184,6 @@ describe('entries', () => {
};
const entry = fromJS({
path: 'src/docs/extending/overview.md',
data: { title: 'Overview' },
});
const collection = fromJS({

View File

@ -351,18 +351,15 @@ export const selectMediaFolder = (
const customFolder = hasCustomFolder(name, collection, entryMap?.get('slug'), field);
if (customFolder) {
const entryPath = entryMap?.get('path');
if (entryPath) {
const entryDir = dirname(entryPath);
const folder = evaluateFolder(name, config, collection!, entryMap, field);
const folder = evaluateFolder(name, config, collection!, entryMap, field);
if (folder.startsWith('/')) {
// return absolute paths as is
if (folder.startsWith('/')) {
mediaFolder = join(folder);
} else {
mediaFolder = join(entryDir, folder as string);
}
mediaFolder = join(folder);
} else {
mediaFolder = join(collection!.get('folder') as string, DRAFT_MEDIA_FILES);
const entryPath = entryMap?.get('path');
mediaFolder = entryPath
? join(dirname(entryPath), folder)
: join(collection!.get('folder') as string, DRAFT_MEDIA_FILES);
}
}