Skip to content

Instantly share code, notes, and snippets.

@tasugim
Created February 12, 2019 06:52
Show Gist options
  • Select an option

  • Save tasugim/183962655477f2d7e58604b1bb020d45 to your computer and use it in GitHub Desktop.

Select an option

Save tasugim/183962655477f2d7e58604b1bb020d45 to your computer and use it in GitHub Desktop.
Octopressの記事のFrontmatterをHugoで使用するために編集する。
import os
import glob
import frontmatter
def create_url(fname):
return 'blog/' + fname.replace('-', '/', 3).replace('.markdown', '')
target_file = "*.markdown"
new_dir = "new/"
os.makedirs(new_dir, exist_ok=True)
for fname in glob.glob(target_file):
print('start edit - ' + fname)
with open(fname, 'r') as f:
post = frontmatter.load(f)
categories = post['categories']
if categories is not None:
post['tags'] = categories.split(',')
post['url'] = create_url(fname)
with open(new_dir + fname, 'wb') as nf:
frontmatter.dump(post, nf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment