Skip to content

Instantly share code, notes, and snippets.

@zonca
Created March 9, 2020 18:05
Show Gist options
  • Save zonca/b4a5a44513854e1c8918743d219f5f34 to your computer and use it in GitHub Desktop.
Save zonca/b4a5a44513854e1c8918743d219f5f34 to your computer and use it in GitHub Desktop.
Migrate markdown from Pelican to Jekyll
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