Here are the main parts that were required to migrate this site from Jekyll to Hugo.
You might also want to see how I use Hugo for this site and how I used Jekyll for this site before migrating to Hugo.
For each post I did the following:
import os
import sys
REPLACE_CMD = (
"sed -i '1s#---"
"#---\\ndate: %s\\naliases: %s#' %s")
valid_tags = {
"career": "wealth",
"awareness": "meaning",
# ...
}
for path in sys.stdin:
path = path.strip()
name = path.split("/")[-1]
date = "-".join(name.split("-")[0:3])
new_name = "-".join(name.split("-")[3:])
alias = "/posts/%s" % (
path.split("/_posts/")[1])
with open(path, "r") as f:
for line in f:
line = line.strip()
words = line.split(":")
if len(words) < 2:
continue
if words[0] != "tags":
continue
tags = words[1].split(" ")
found = False
for tag in tags:
tag = tag.strip()
if tag not in valid_tags:
continue
found = True
to = "content/%s/%s/%s" % (
valid_tags[tag], tag, new_name)
cp_cmd = "cp %s %s" % (path, to)
assert not os.system(cp_cmd)
replace_cmd = REPLACE_CMD % (
date, alias, to)
assert not os.system(replace_cmd)
assert found
break
Run with:
$ find _posts/ -type f |
python ../script/to_hugo.py
$ find content/ -type f |
xargs sed -i 's/menu_order/weight/'
For example:
$ find content/ -type f | xargs sed -i
's#{% include video.html id="\(.*\)" %}'
'#{{< video \1 >}}#'
For example:
$ find content/ -type f |
xargs sed -i '/include_rouge: true/d'
import os
import sys
valid_tags = set([
"title",
"description",
"date",
# ...
])
for tag in valid_tags:
print(tag)
for path in sys.stdin:
path = path.strip()
if path == "":
break
with open(path, "r") as f:
found = False
for line in f:
line = line.strip()
if line == "---":
if found:
break
found = True
words = line.split(":")
if len(words) < 2:
continue
tag = words[0]
assert tag in valid_tags
Check all content with:
$ find /content/ -type f | grep '\.md$' |
python ../script/check_tags.py
Check layouts with:
$ for tag in $(
echo "" |
python ../script/check_tags.py); do
echo; echo "tag: ${tag}";
find layouts/ -type f | xargs grep "${tag}";
done
tag: include_math_plot
layouts/partials/footer.html:
{{- $hasMathPlot :=
.Page.Params.include_math_plot -}}
For example:
$ mkidr content/page/
$ mv content/page{,/index}.md
# then move the non-markdown content
# to content/page/include.html
Some tables stopped working because they had the wrong number of columns, e.g.:
| a | b | c |
| - | - |
| 1 | 2 | 3 |
Find broken tables using:
$ find ../server/_site/ -type f |
xargs grep '|.*|' | grep -v 'Binary'
For example, find remaining includes with:
$ find ../server/_site/ -type f |
xargs grep '{%' | grep -v 'Binary'