Skip to content

Instantly share code, notes, and snippets.

@succi0303
Created July 7, 2019 04:55
Show Gist options
  • Select an option

  • Save succi0303/b3cc0f0c621acc8af81e87206a933728 to your computer and use it in GitHub Desktop.

Select an option

Save succi0303/b3cc0f0c621acc8af81e87206a933728 to your computer and use it in GitHub Desktop.
Frontmatterのカテゴリーをフラットな文字列から配列に置き換える。
import os
import glob
import frontmatter
target_file = "*.markdown"
new_dir = "new/"
os.makedirs(new_dir, exist_ok=True)
for fname in glob.glob(target_file):
print('start editing - ' + fname)
with open(fname, 'r') as f:
post = frontmatter.load(f)
categories = post['categories']
if categories is not None:
if type(categories) is str:
post['categories'] = categories.split(',')
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