Created
March 9, 2020 18:05
-
-
Save zonca/b4a5a44513854e1c8918743d219f5f34 to your computer and use it in GitHub Desktop.
Migrate markdown from Pelican to 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
import sys | |
filename = sys.argv[1] | |
print(filename) | |
f = open(filename, "r").read() | |
lines = f.splitlines() | |
first, rest = lines[:10], lines[10:] | |
fixed_first = ["---", "layout: post"] | |
for line in first: | |
for key in ["Title:", "Date:", "Slug:"]: | |
if line.startswith(key): | |
line = line.replace(key, key.lower()) | |
if key == "Date:": | |
if not filename.startswith("20"): | |
date = line[6 : 6 + 10] + "-" | |
else: | |
date = "" | |
if line.startswith("Author:"): | |
continue | |
if line.startswith("Tags:"): | |
line = line.replace("Tags: ", "categories: [") + "]" | |
fixed_first.append(line) | |
if line.startswith("slug:"): | |
fixed_first.append("---") | |
with open(f"jekyll/{date}{filename}", "w") as f: | |
f.writelines(l + "\n" for l in fixed_first + rest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment