Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not infer file format if collection specified. #795

Merged
merged 1 commit into from
Dec 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}