From 864083bc8be1e140ef86b2aae3c16bcbcebfff39 Mon Sep 17 00:00:00 2001 From: Caleb Date: Thu, 9 Nov 2017 20:26:53 -0700 Subject: [PATCH] Infer format from extension for new entries. If a collection has no format specified, we try to infer the format from the file extension when reading. This commit also allows us to infer the format from the `extension` set in the config, so that we can still create the correct format when making a new file. --- src/formats/formats.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/formats/formats.js b/src/formats/formats.js index 49aba1047138..be48fa28af82 100644 --- a/src/formats/formats.js +++ b/src/formats/formats.js @@ -47,6 +47,13 @@ export function resolveFormat(collectionOrEntity, entry) { return formatByExtension(fileExtension); } + // If creating a new file, and an `extension` is specified in the + // collection config, infer the format from that extension. + const extension = collectionOrEntity.get('extension'); + if (extension) { + return formatByExtension(extension); + } + // If no format is specified and it cannot be inferred, return the default. return formatByName(); }