Converting WordPress Export File to Hugo

I have written on the Hugo static site generator here. Now I have written a migration program in the Go programming language to convert from WordPress export format to Hugo format. This program wp2hugo.go is in GitHub. It can be freely downloaded and does not need any further dependencies, except, of course, Go. The Go software is in Arch Linux or Ubuntu.

To convert a blog from WordPress you have to create an export file.

If the blog is not too voluminous one downloads a single XML-file which contains all posts and pages. If the blog in question is larger then you will receive an e-mail from that you can download a ZIP which two or more XML files in them. If you have such a ZIP-file, then unpack it, for example by using p7zip. Then run

go run wp2hugo.go XML1 XML2 ...

This will produce empty directories archetypes, data, layouts, static,
and themes. It will create a directory content which has sub-directories page, and post, possibly private. This setup is similar to hugo new. It will furthermore produce two files config.toml and attachm.txt. Converting this blog will result in the following config.toml for example:

title = "Elmar Klausmeier's Weblog"
languageCode = "en"
baseURL = ""
paginate = 20

   tag = "tags"
   category = "categories"
   archive = "archives"

   description = "Computers and Programming"

File attachm.txt contains a list of all attachments, i.e., in most cases these are images. In my case this file looks like this:    cablesurf-speed1.png      load99.png  c10ktitles.jpg

It lists all files which are actually referenced in your blog. You can download them like this:

cd static
mkdir img
cd img
perl -ane '`curl $F[0] -o $F[1]\n`' ../../attachm.txt

You don’t have to download the files, if you already have your images on your local machine. wp2hugo.go changes all your blog posts and pages so that they reference their images (attachments) in /img/, i.e., static/img/.

I have two blogs on

  1. Elmar Klausmeier’s Weblog, more than 220 posts, 4 pages
  2. Collected Links, almost 3,000 posts, 2 pages

Converting the first one using wp2hugo.go takes less than 2 seconds for 220 posts, the second, larger blog, takes less than 6 seconds for the 3,000 posts. These timings are on a desktop PC with an AMD octacore FX 8120 clocked at 3.1 GHz.

wp2hugo.go splits the XML export file where each post or page becomes a separate markdown file under content, additionally it handles the following specialities:

  1. Tags and categories
  2. Converts [code] and <pre> to ```
  3. Converts YouTube videos to {{< youtube ... >}}
  4. Handles Google maps
  5. Handles $latex, posts with TeX math get math=true in their frontmatter
  6. Corrects corrupted code in [code] blocks where special characters like lower than, greater than, or ampersand where erroneously transformed to HTML format by WordPress
  7. http converted to https
  8. Draft posts in WordPress are drafts in Hugo

I experimented with the converted files and used the following themes, which showed results without too much fiddling in config.toml:

  1. hugo-academic
  2. hugo-theme-bootstrap4-blog
  3. hugo-tranquilpeak-theme

Hugo, not wp2hugo.go, is a CPU hog. When Hugo reads all 3,000 posts then all 8 cores in my machines are mostly busy.

/tmp/H: time hugo --theme=hugo-theme-bootstrap4-blog
Started building sites ...
Built site for language en:
0 draft content
0 future content
0 expired content
2904 regular pages created
11394 other pages created
0 non-page files copied
6209 paginator pages created
0 archives created
5690 tags created
1 categories created
total in 116501 ms

real    1m56.727s
user    8m5.703s
sys     0m1.877s

I.e., after 2 minutes Hugo has processed all files, but bills 8 minutes because it has used more than one core. I ran this in /tmp, so there is no actual writing to disk; /tmp is mounted as tmpfs in Arch Linux.

Currently wp2hugo.go has the following limitations:

  1. Password protected posts in WordPress have no password in Hugo
  2. Handling for Vimeo shortcode [vimeo]
  3. Inlined TeX equations work, but displayed equations do not, e.g., On Differential Forms
  4. The highlight parameter in [code] is ignored
  5. When a post references to a page this link will be 404, while references to all other posts work fine

wp2hugo.go works as follows:

  1. Iterate over all filenames given as arguments
  2. Fill Go maps config[], frontmatter[], attachm[], etc.
  3. Find posts or pages within item-tag
  4. Use various regular expressions to change the body of posts and pages — they would nicely fit into a configuration file

The larger of the two blogs has previously been migrated from to Collected Links using a Perl script, which generated WordPress import/export format, see Migrating from to WordPress.

It deserves another article how to actually bring the converted blog to GitHub, GitLab, Netlify, etc.

Using Odroid as IP Router

I purchased an Odroid-XU4 for ca. 80 EUR including power-supply and case from Pollin. The original manufacturer is hardkernel. I intended to use this small ARM computer as a router and firewall. In the past I had used routers from multiple vendors, e.g., Linksys/Cisco, TP-Link, AVM/FritzBox, Netgear, and so on. There is a rule of thumb with all these devices: Usually you have to reboot them once or twice a month, otherwise they misbehave somehow. At least three of these device went completely catatonic. Now I had enough of this, I also wanted a command line interface to the router, ideally a real Linux system with bash, cron, gcc, etc. Although I already own an Intel NUC and I am very happy with this computer, an Intel NUC is a little bit too expensive to be used as just a router.

I recommend to additionally purchase a RTC backup battery. The Odroid has a realtime clock, but looses all date and time information once powered off. This way the log of the computer is garbled.

Continue reading

Exceeding 10.000 km with E-Bike

As described in Commuting to Work with an E-Bike I drive to my work place using an e-bike. As I found out that using a bike is a viable alternative to public transport I bought a better e-bike after about a year. I bought my first e-bike in March 2015, my second in December 2015, and used it since January 2016. With this second e-bike I now exceeded more than 10.000 km within a year, as shown in below photographs from the odometer. In total I have now travelled about 20.000 km with my two bikes within two years, i.e., I cycled half the earth perimeter.

Analyzing above recorded data from Nyon on my smartphone:

My second bike had three flat tires, and a loose crankshaft. I replaced the chain two times, and the sprocket once, furthermore I replaced both pedals. Apart from that I had no further issues.