Skip to content
Permalink
Browse files
Fix #112, a few corner cases in the upgrade_metadata plugin
  • Loading branch information
ralsina committed Sep 9, 2015
1 parent 5f22614 commit 50c3631f8ff5197222a08acc122f264c46124981
Showing 2 changed files with 11 additions and 10 deletions.
@@ -7,6 +7,6 @@ MinVersion = 7.4.0

[Documentation]
Author = Chris Warrick
Version = 0.1.2
Version = 0.1.3
Website = http://plugins.getnikola.com/#upgrade_metadata
Description = Upgrade old-style metadata
@@ -70,22 +70,23 @@ def _execute(self, options, args):
yesno = utils.ask_yesno("Proceed with metadata upgrade?")
if options['yes'] or yesno:
for post in flagged:
for lang in post.translated_to:
for lang in self.site.config['TRANSLATIONS'].keys():
if lang == post.default_lang:
fname = post.metadata_path
else:
meta_path = os.path.splitext(post.source_path)[0] + '.meta'
fname = utils.get_translation_candidate(post.config, meta_path, lang)

with io.open(fname, 'r', encoding='utf-8') as fh:
meta = fh.readlines()
if os.path.exists(fname):
with io.open(fname, 'r', encoding='utf-8') as fh:
meta = fh.readlines()

if not meta[1].startswith('.. '):
# check if we’re dealing with old style metadata
with io.open(fname, 'w', encoding='utf-8') as fh:
for k, v in zip(self.fields, meta):
fh.write('.. {0}: {1}'.format(k, v))
L.debug(fname)
if not meta[min(1, len(meta)-1)].startswith('.. '):
# check if we’re dealing with old style metadata
with io.open(fname, 'w', encoding='utf-8') as fh:
for k, v in zip(self.fields, meta):
fh.write('.. {0}: {1}'.format(k, v))
L.debug(fname)

L.info('{0} posts upgraded.'.format(len(flagged)))
else:

0 comments on commit 50c3631

Please sign in to comment.