From 35c6242e4e2ddfd6f4793ef289a3ea11a942e6f6 Mon Sep 17 00:00:00 2001 From: Caleb Date: Sun, 5 Nov 2017 08:48:57 -0700 Subject: [PATCH] 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. --- src/formats/formats.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/formats/formats.js b/src/formats/formats.js index 3b610cd0f919..49aba1047138 100644 --- a/src/formats/formats.js +++ b/src/formats/formats.js @@ -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(); }