Translate this page

Migrating From Jekyll To Hugo 🔗

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.

Move Posts 🔗

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

Change from menu_order to weight 🔗

$ find content/ -type f |
    xargs sed -i 's/menu_order/weight/'

Update from include to shortcode 🔗

For example:

$ find content/ -type f | xargs sed -i
    's#{% include video.html id="\(.*\)" %}'
    '#{{< video \1 >}}#'

Delete Unused Tags 🔗

For example:

$ find content/ -type f |
    xargs sed -i '/include_rouge: true/d'

Check All Remaining Tags 🔗

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 -}}

Move Page-Specific HTML/JS/CSS To A Page Resource 🔗

For example:

$ mkidr content/page/
$ mv content/page{,/index}.md
# then move the non-markdown content
# to content/page/include.html

Fix Tables 🔗

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'

Check For Remaining Problems 🔗

For example, find remaining includes with:

$ find ../server/_site/ -type f |
    xargs grep '{%' | grep -v 'Binary'

Download my free ebook


Subscribe to my mailing list and get a free email course

* indicates required

Interests



Translate this page

Updated on 2020 Jun 1.

DISCLAIMER: This is not professional advice. The ideas and opinions presented here are my own, not necessarily those of my employer.