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:
Caleb 2017-11-05 08:48:57 -07:00 committed by Shawn Erquhart
parent 9b2e51d75d
commit 0e51cff231

View File

@ -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();
}