Skip to content

Commit

Permalink
Do not infer file format if collection specified.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tech4him1 authored and erquhart committed Dec 6, 2017
1 parent 9b2e51d commit 0e51cff
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/formats/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 0e51cff

Please sign in to comment.