Skip to content

Commit

Permalink
Fix #2380 -- copy imported two-file posts
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jun 21, 2016
1 parent 06b18f6 commit 0667520
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -9,6 +9,9 @@ Features
Bugfixes
--------

* Copy files when importing two-file posts instead of reading and
writing (useful for binary formats, eg. docx) (Issue #2380)

New in v7.7.9
=============

Expand Down
20 changes: 13 additions & 7 deletions nikola/plugins/command/new_post.py
Expand Up @@ -29,10 +29,11 @@
from __future__ import unicode_literals, print_function
import io
import datetime
import operator
import os
import sys
import shutil
import subprocess
import operator
import sys

from blinker import signal
import dateutil.tz
Expand Down Expand Up @@ -366,17 +367,22 @@ def _execute(self, options, args):
onefile = False
LOGGER.warn('This compiler does not support one-file posts.')

if import_file:
if onefile and import_file:
with io.open(import_file, 'r', encoding='utf-8') as fh:
content = fh.read()
else:
elif not import_file:
if is_page:
content = self.site.MESSAGES[self.site.default_lang]["Write your page here."]
else:
content = self.site.MESSAGES[self.site.default_lang]["Write your post here."]
compiler_plugin.create_post(
txt_path, content=content, onefile=onefile, title=title,
slug=slug, date=date, tags=tags, is_page=is_page, **metadata)

if (not onefile) and import_file:
# Two-file posts are copied on import (Issue #2380)
shutil.copy(import_file, txt_path)
else:
compiler_plugin.create_post(
txt_path, content=content, onefile=onefile, title=title,
slug=slug, date=date, tags=tags, is_page=is_page, **metadata)

event = dict(path=txt_path)

Expand Down

0 comments on commit 0667520

Please sign in to comment.