Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate redirect URLs from wordpress -> jekyll
def main(input_file):
with open(input_file) as f:
lines = f.readlines()
# sample line:
# _posts/2012-11-11-the-fundamentals-of-automated-testing-use-factories.md:#permalink: /?p=726
output = []
for l in lines:
l = l[7:]
yyyy = l[:4]
mm = l[5:7]
dd = l[8:10]
l = l[11:]
rest = l.rsplit('.md')
title = rest[0].rstrip()
redirect = rest[1].rsplit(":#permalink: /")[1].rstrip()
print("'" + redirect + "': '/blog/" + yyyy + "/" + mm + "/" + dd + "/" + title + "',")
if __name__ == "__main__":
# redirects.txt was generated by doing
# grep -ri permalink _posts/
main(r"C:\temp\redirects.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment