Last active
February 24, 2017 16:11
-
-
Save noqqe/f2981daf33221332b4462f93b5df4772 to your computer and use it in GitHub Desktop.
Restructuring the metadata of my blog with frontmatter
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
#!/usr/bin/env python2.7 | |
# -*- coding: utf-8 -*- | |
import frontmatter | |
import glob | |
import codecs | |
home = '/home/noqqe/Code/noqqe.de/content/blog/' | |
files = glob.glob(home + '*.md') | |
for f in files: | |
print f | |
with open(f, "r") as o: | |
post = frontmatter.loads(o.read()) | |
tags = post["tags"] | |
tags = [ unicode(v).lower() for v in tags ] | |
try: | |
tags = list(set(tags)) | |
except: | |
continue | |
tags = [ v for v in tags if not unicode(v).lower().startswith('ubuntuusers') ] | |
tags = [ v for v in tags if not unicode(v).lower().startswith('planetenblogger') ] | |
tags = [ v for v in tags if not unicode(v).lower().startswith('osbn') ] | |
post["tags"] = tags | |
# correct date | |
post["date"] = post["date"].strftime("%Y-%m-%dT%H:%M:%S") | |
# remove comments flag | |
try: | |
del post["comments"] | |
except KeyError: | |
pass | |
with codecs.open(f, "wb+", 'utf8') as o: | |
o.write(frontmatter.dumps(post)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment