Skip to content

Instantly share code, notes, and snippets.

@aladagemre
Created February 10, 2015 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aladagemre/7d642a51692c67cee34b to your computer and use it in GitHub Desktop.
Save aladagemre/7d642a51692c67cee34b to your computer and use it in GitHub Desktop.
Jekyll to Pelican convertor. Only fixes categories, tags list to comma separated tags and single category
# encoding: utf-8
import os
filenames = filter(lambda x: x.endswith(".md"), os.listdir("."))
def parse(filename):
print filename
lines = open(filename).read().split("\n")
tags_i = None
last_tag_i = None
tags = []
for i, line in enumerate(lines):
line_ = line.strip()
if line_ == "category:":
category_i = i
if line_ == "tags:":
tags_i = i
if tags_i and line_.startswith("-"):
tags.append(line_[1:].strip())
last_tag_i = i
categories = map(lambda x: x.split("-")[-1].strip(), lines[category_i+1:tags_i])
tags_ = set(tags)
categories_ = set(categories)
if "Türkçe" in categories_:
category = "Türkçe"
else:
category = "English"
tags_ = tags_.union(categories_)
try:
tags_.remove("Türkçe")
tags_.remove("English")
except:
pass
txt = ""
txt += "\n".join(lines[:category_i]) + "\n"
txt += "Category: " + category + "\n"
txt += "Tags: " + ", ".join(tags_) + "\n\n"
if last_tag_i:
txt += "\n".join(lines[last_tag_i+1:]) + "\n"
else:
txt += "\n".join(lines[category_i + len(categories)+ 1:]) + "\n"
o = open("new/" + filename, "w")
o.write(txt)
o.close()
for filename in filenames:
parse(filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment