Skip to content

Commit

Permalink
Merge pull request #3 from networm/bugfix/front-matter
Browse files Browse the repository at this point in the history
Bugfix/front matter
  • Loading branch information
coderzh committed Oct 7, 2018
2 parents 837ddc6 + 431ece8 commit 13fa2ab
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ConvertToHugo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
__author__ = 'coderzh'


class MyDumper(yaml.Dumper):
def increase_indent(self, flow=False, indentless=False):
return super(MyDumper, self).increase_indent(flow, False)

content_regex = re.compile(r'---([\s\S]*?)---([\s\S]*)')


def convert_front_matter(front_data, post_date, url):
if post_date:
front_data['date'] = post_date.strftime('%Y-%m-%d')
front_data['url'] = url

del front_data['layout']
Expand Down Expand Up @@ -46,7 +48,7 @@ def convert_body_text(body_text):

def write_out_file(front_data, body_text, out_file_path):
out_lines = ['---']
front_string = yaml.dump(front_data, width=1000, default_flow_style=False, allow_unicode=True)
front_string = yaml.dump(front_data, width=1000, default_flow_style=False, allow_unicode=True, Dumper=MyDumper)
out_lines.extend(front_string.splitlines())
out_lines.append('---')
out_lines.extend(body_text.splitlines())
Expand All @@ -64,7 +66,7 @@ def parse_from_filename(filename):
if m:
slug = m.group(2)
post_date = datetime.strptime(m.group(1), '%Y-%m-%d')
return post_date, '/%s/%s' % (post_date.strftime('%Y/%m/%d'), slug)
return post_date, '/%s/%s/' % (post_date.strftime('%Y/%m/%d'), slug)
return None, '/' + slug


Expand Down

0 comments on commit 13fa2ab

Please sign in to comment.