Created
July 7, 2019 04:55
-
-
Save succi0303/b3cc0f0c621acc8af81e87206a933728 to your computer and use it in GitHub Desktop.
Frontmatterのカテゴリーをフラットな文字列から配列に置き換える。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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