From WordPress to Hugo
By Mikael Ståldal
I have used self-hosted WordPress for this blog since its start in 2006, but I finally got fed up with having to frequently update WordPress itself and a bunch of plugins, or having to constantly worry about security issues. Since I am the only one publishing on this blog, I decided to switch to a static site generator instead, and I chose Hugo, mainly because it is easy to install and does not require any heavy runtime (most of its competitors require Python, Ruby or Node.js).
I used this tool to export the WordPress site to Hugo format. I had to do some tweaks to get it to work properly:
- Convert HTML’s
<pre>...</pre>
to Markdown’s ``` format (beware of line breaks after/before). - Remove some HTML escaping such as
<
and>
. - Clean-up some
<p>
,</p>
and<br />
tags. - Put any static content into
static
directory, and fix links to it. - Move pages to
content
. - Fix temporal archives with a script like this:
#/bin/bash
for file in `ls -1 |grep '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-'`; do
year=`echo ${file} | sed 's|\([0-9][0-9][0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9]\)-.*|\1|g'`
month=`echo ${file} | sed 's|\([0-9][0-9][0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9]\)-.*|\1/\2|g'`
day=`echo ${file} | sed 's|\([0-9][0-9][0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9]\)-.*|\1/\2/\3|g'`
sed -i -e "1d" ${file}
sed -i -e "1i day: ${day}" ${file}
sed -i -e "1i month: ${month}" ${file}
sed -i -e "1i year: ${year}" ${file}
sed -i -e "1i ---" ${file}
done
- Add search with Pagefind.
- And some more.
The source code for the blog is now on GitHub.