Skip to content
Permalink
Browse files

Improved support for post formats.

  • Loading branch information
felixfontein committed Jul 7, 2015
1 parent a334aa3 commit 9b5629a6fecabd567293af7542f81d908d2e48c6
Showing with 15 additions and 4 deletions.
  1. +15 −4 nikola/plugins/command/import_wordpress.py
@@ -439,9 +439,12 @@ def transform_content(self, content, post_format):
content = self.transform_caption(content)
content = self.transform_multiple_newlines(content)
return content, 'md'
else:
# FIXME ???
elif post_format == 'markdown':
return content, 'md'
elif post_format == 'none':
return content, 'html'
else:
return None

def _create_metadata(self, status, excerpt, tags, categories):
other_meta = {'wp-status': status}
@@ -547,6 +550,8 @@ def import_item(self, item, wordpress_namespace, out_folder=None):
format_tag = [x for x in item.findall('*//{%s}meta_key' % wordpress_namespace) if x.text == '_tc_post_format']
if format_tag:
post_format = format_tag[0].getparent().find('{%s}meta_value' % wordpress_namespace).text
if post_format == 'wpautop':
post_format = 'wp'

if is_draft and self.exclude_drafts:
LOGGER.notice('Draft "{0}" will not be imported.'.format(title))
@@ -566,7 +571,12 @@ def import_item(self, item, wordpress_namespace, out_folder=None):
content_translations = {"": content}
default_language = self.context["DEFAULT_LANG"]
for lang, content in content_translations.items():
content, extension = self.transform_content(content, post_format)
try:
content, extension = self.transform_content(content, post_format)
except:
LOGGER.error('Cannot interpret post "{0}" (language {1}) with post ' +
'format {2}!'.format(os.path.join(out_folder, slug), lang, post_format))
return False
if lang:
out_meta_filename = slug + '.meta'
if lang == default_language:
@@ -639,7 +649,8 @@ def import_posts(self, channel):
self.posts_pages[post_id][2] + ".attachments.json")
self.write_attachments_info(destination, self.attachments[post_id])
else:
LOGGER.warn("Found attachments for post or page #{0}, but didn't find post or page. (Attachments: {1})".format(post_id, [e[0] for _, e in self.attachments[post_id].items()]))
LOGGER.warn("Found attachments for post or page #{0}, but didn't find post or page. " +
"(Attachments: {1})".format(post_id, [e[0] for _, e in self.attachments[post_id].items()]))


def get_text_tag(tag, name, default):

0 comments on commit 9b5629a

Please sign in to comment.