Do not infer file format if collection specified.
Before, we always tried to infer a file's format, even if it was explicitly specified in the collection's config. This commit makes it so that we always use the format from the config if it is specified, and only if it is not set do we try to infer it from the file extension.
This commit is contained in:
parent
9b2e51d75d
commit
0e51cff231
@ -34,9 +34,19 @@ function formatByName(name) {
|
||||
}
|
||||
|
||||
export function resolveFormat(collectionOrEntity, entry) {
|
||||
const path = entry && entry.path;
|
||||
if (path) {
|
||||
return formatByExtension(path.split('.').pop());
|
||||
// If the format is specified in the collection, use that format.
|
||||
const format = collectionOrEntity.get('format');
|
||||
if (format) {
|
||||
return formatByName(format);
|
||||
}
|
||||
return formatByName(collectionOrEntity.get('format'));
|
||||
|
||||
// If a file already exists, infer the format from its file extension.
|
||||
const filePath = entry && entry.path;
|
||||
if (filePath) {
|
||||
const fileExtension = filePath.split('.').pop();
|
||||
return formatByExtension(fileExtension);
|
||||
}
|
||||
|
||||
// If no format is specified and it cannot be inferred, return the default.
|
||||
return formatByName();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user