Skip to content

Commit 24889df

Browse files
committed
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.
1 parent d56e925 commit 24889df

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/formats/formats.js

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ export function resolveFormat(collectionOrEntity, entry) {
4646
return formatByExtension(fileExtension);
4747
}
4848

49+
// If creating a new file, and an `extension` is specified in the
50+
// collection config, infer the format from that extension.
51+
const extension = collectionOrEntity.get('extension');
52+
if (extension) {
53+
return formatByExtension(extension);
54+
}
55+
4956
// If no format is specified and it cannot be inferred, return the default.
5057
return formatByName();
5158
}

0 commit comments

Comments
 (0)