Skip to content

Instantly share code, notes, and snippets.

@kulinacs
Created April 11, 2017 00:54
Show Gist options
  • Save kulinacs/67606f72d6888d9cbc67ddf16082413c to your computer and use it in GitHub Desktop.
Save kulinacs/67606f72d6888d9cbc67ddf16082413c to your computer and use it in GitHub Desktop.
Frontmatter Cleanup
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