Contents

Moving from Jekyll to Hugo

Recently I have decided to bring my blog back to live. And to do that I went ahead and looked for popular static gen tools and found that Hugo is a popular tool nowadays. So I decided to migrate my blog from Jekyll to Hugo.

The blog was originally in Wordpress and I have already migrated from Wordpress to Jekyll. Lately I have been more interested in playing with blogging tools them actually write on my blog.

Migrating the blog

To migrate the blog I look up some tool to help me out and I ended up finding this one. After running the tool and installing and running Hugo locally I was able to view the website I noticed straight away that it had some issues:

  • There was no date on my posts
  • The posts’ images were not being displayed

In order to fix the date issue I came up with a simple Python script (code below) that would loop through my posts, look for the word permalink and from the permalink extract the date and create a new line with the date that Hugo would them interpret to properly display the date.

Here it is the script:

import os
import fileinput

for filename in os.listdir("./"):
    if filename.endswith(".md"):
        for line in fileinput.FileInput(filename,inplace=1):
            if "permalink" in line:
                txt = line.split("/")
                newDate = txt[1] + "-" + txt[2] + "-" + txt[3]
                line=line.replace(line,line+"date: " + newDate + "\n")
            print(line, end="")

Here it is how a header looks like before running the script:

---
author: Antonio Rodrigues
categories:
  - English
  - Personal
permalink: /2013/12/28/xmas-in-brazil/
title: Xmas in Brazil
url: /2013/12/28/xmas-in-brazil/
---

And here it is after running the script:

---
author: Antonio Rodrigues
categories:
  - English
  - Personal
permalink: /2013/12/28/xmas-in-brazil/
date: 2013-12-28
title: Xmas in Brazil
url: /2013/12/28/xmas-in-brazil/
---

As you can noticed it adds the date: field to the header and the cool part is that it does that by looking up the date from the permalink field.

Now my second issue which I haven’t fixed yet is due to the fact that when I migrate from Wordpress to Jekyll all the images were migrated with the absolute URL to the image files. Since I moved domains, that won’t work. Now I will need to write a new script to replace the absolute URLs into relative ones. But I will deal with that later. The important thing is that the website is now live again.