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