Skip to content

Commit d56e925

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

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/formats/formats.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,19 @@ function formatByName(name) {
3333
}
3434

3535
export function resolveFormat(collectionOrEntity, entry) {
36-
const path = entry && entry.path;
37-
if (path) {
38-
return formatByExtension(path.split('.').pop());
36+
// If the format is specified in the collection, use that format.
37+
const format = collectionOrEntity.get('format');
38+
if (format) {
39+
return formatByName(format);
3940
}
40-
return formatByName(collectionOrEntity.get('format'));
41+
42+
// If a file already exists, infer the format from its file extension.
43+
const filePath = entry && entry.path;
44+
if (filePath) {
45+
const fileExtension = filePath.split('.').pop();
46+
return formatByExtension(fileExtension);
47+
}
48+
49+
// If no format is specified and it cannot be inferred, return the default.
50+
return formatByName();
4151
}

0 commit comments

Comments
 (0)