Created
February 12, 2019 06:52
-
-
Save tasugim/183962655477f2d7e58604b1bb020d45 to your computer and use it in GitHub Desktop.
Octopressの記事のFrontmatterをHugoで使用するために編集する。
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 | |
| 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