Skip to content

Instantly share code, notes, and snippets.

@marksimpson82
Last active August 2, 2020 02:19
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 marksimpson82/fdc8f6915a6256391138fdc70a0a9a0b to your computer and use it in GitHub Desktop.
Save marksimpson82/fdc8f6915a6256391138fdc70a0a9a0b to your computer and use it in GitHub Desktop.
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