Skip to content

Commit

Permalink
Infer format from extension for new entries.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tech4him1 committed Dec 1, 2017
1 parent 35c6242 commit d6f7d6b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/formats/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ export function resolveFormat(collectionOrEntity, entry) {
return formatByExtension(fileExtension);
}

// If creating a new file, and an `extension` is specified in the
// collection config, infer the format from that extension.
const extension = collectionOrEntity.get('extension');
if (extension) {
return formatByExtension(extension);
}

// If no format is specified and it cannot be inferred, return the default.
return formatByName();
}

0 comments on commit d6f7d6b

Please sign in to comment.