Skip to content

Commit 864083b

Browse files
tech4him1erquhart
authored andcommitted
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 0e51cff commit 864083b

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
@@ -47,6 +47,13 @@ export function resolveFormat(collectionOrEntity, entry) {
4747
return formatByExtension(fileExtension);
4848
}
4949

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

0 commit comments

Comments
 (0)