I had been thinking using Wordpress for a personal blog is kind of wasteful for a long long time. After all, I don’t have dynamic content, it’s really just a bunch of text. I wanted to migrate to a static-file CMS for a long time but I never had the courage to do so. I recently had a few days of downtime, and so finally I did it. I decided to use Hugo as it was the most popular option at the time.
The basics of moving from Wordpress to Hugo are easy. Export the posts to XML, extract each post and convert to Markdown using blog2md, build the Hugo content and voila.
Not so fast 😅
After the initial conversion, it’s time to give it a go. Let’s fire Hugo internal server up with hugo server
, and … catastrophe 💥 None of the URLs are working, everything returns 404 😭 The URL layout (YYYY/MM/DD/slug
) isn’t the same by default. That’s an easy fix, set the permalinks section correctly:
[permalinks]
[permalinks.page]
'posts' = '/:year/:month/:day/:slug/'
To make my initial tests easier, I used this Bash oneliner to automate broken links testing:
curl https://blog.xentoo.info/post-sitemap.xml 2>/dev/null | egrep -o '<loc>https://[^<]*' | sed -e 's/<loc>//' | while read a ; do url=$(echo "$a" | sed -e 's;https://blog.xentoo.info;http://192.168.0.2:1314;') ; curl --silent --fail "$url" > /dev/null || echo "$url" ; done
Let’s build it again. Most of the URLs return 200. The ones that fail consistently have punctuation signs in their title. I manually defined the slug for the few non-compliant posts. Just set a slug
property in your Markdown header. Another Bash oneliner:
curl https://blog.xentoo.info/post-sitemap.xml 2>/dev/null | egrep -o '<loc>https://[^<]*' | sed -e 's/<loc>//' | while read a ; do url=$(echo "$a" | sed -e 's;https://blog.xentoo.info;http://192.168.0.2:1314;') ; curl --silent --fail "$url" > /dev/null || echo "$url" ; done | cut -d '/' -f 7 | while read a ; do sed -e "s;draft: false;draft: false\nslug: '$a';" -i content/posts/$a/index.md ; done
Let’s build it again. The pictures and attachments were missing. Wordpress automatically creates smaller versions of the images to display but I don’t want to manage that. So I downloaded only the original picture, and updated all the links. Fortunately I don’t have so many, so I did it manually, no oneliner this time 😥
After reviewing a few links again, it was time to put it to the test. I published it and used a few broken links checkers. I missed a few things but not many, fixed them, tested again and voila. Here’s my blog migrated.
It’s time to commit it to git and … realize the features I lost in the migration.
All the bells and whistles from a dynamic CMS such as helpful tips for SEO, statistics, comments, auto-updates, etc. are gone. I’m still thinking about the comments, and maybe the statistics. I’m old school and I thought about the venerable Webalizer for a couple of seconds 🤪 But no.
{{ $image := resources.GetRemote “https://linuxreviews.org/images/7/7e/Webalizer_October_2020-hourly.jpg" }}
Maybe I will use Plausible and publish another post about it, who knows 🤷♂️
For now, I’m happy with it as it is 😁