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

Fix 2798 #2799

Merged
merged 2 commits into from
May 25, 2017
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ New in master
Features
--------

* Guess file format from file name on new_post (Issue #2798)
* Use BaguetteBox as lightbox in base theme (Issue #2777)
* New ``deduplicate_ids``, for preventing duplication of HTML id
attributes (Issue #2570)
Expand Down
21 changes: 19 additions & 2 deletions nikola/plugins/command/new_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,33 @@ 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 and import_file:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could merge that and the first if into one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps, but it saves 3 lines of code at the cost of a non-stupid condition. I like stupid conditions.

# content_format not specified. If import_file was given, use
# it to guess (Issue #2798)
extension = os.path.splitext(import_file)[-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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps that if was there for a reason? (I can’t see it though.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked, this seems to work just as well :)

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