Created
April 11, 2017 00:54
-
-
Save kulinacs/67606f72d6888d9cbc67ddf16082413c to your computer and use it in GitHub Desktop.
Frontmatter Cleanup
This file contains 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 frontmatter | |
from datetime import timezone, timedelta | |
import glob | |
globby = glob.glob('../_posts/*/*.md') | |
for filename in globby: | |
post = frontmatter.load(filename) | |
desired_tags = ['layout', 'title', 'date', 'content'] | |
current_tags = list(post.keys()) | |
for key in current_tags: | |
if key not in desired_tags: | |
del post[key] | |
post['date'] = post['date'].replace(hour=0,minute=0,second=0,microsecond=0, | |
tzinfo=timezone(-timedelta(hours=6))) | |
with open(filename, "w") as f: | |
f.write(frontmatter.dumps(post) + '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment