Skip to content

Commit

Permalink
Guess format from path on new_post (Issue #2798)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roberto Alsina committed May 25, 2017
1 parent b8808c2 commit 274cf88
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions nikola/plugins/command/new_post.py
Expand Up @@ -265,16 +265,25 @@ def _execute(self, options, args):
if "@" in content_format:
content_format, content_subformat = content_format.split("@")

if not content_format: # Issue #400
if not content_format and path:
# content_format not specified. If path was given, use
# it to guess (Issue #2798)
extension = os.path.splitext(path)[-1]
for compiler, extensions in self.site.config['COMPILERS'].items():
if extension in extensions:
content_format = compiler

elif not content_format: # Issue #400
content_format = get_default_compiler(
is_post,
self.site.config['COMPILERS'],
self.site.config['post_pages'])

if content_format not in compiler_names:
elif content_format not in compiler_names:
LOGGER.error("Unknown {0} format {1}, maybe you need to install a plugin or enable an existing one?".format(content_type, content_format))
self.print_compilers()
return

compiler_plugin = self.site.plugin_manager.getPluginByName(
content_format, "PageCompiler").plugin_object

Expand Down

0 comments on commit 274cf88

Please sign in to comment.