I have been running my blog with a self-hosted WordPress install for almost two decades, and I finally decided to move to a static website solution. The relatively rapid shift was triggered by a WordPress update that caused trouble with the paths to images throughout my blog. However, since my site was hacked a couple of years ago, I have pondered alternative solutions for running the blog.
I have been tired of all the updates and security issues with a server-based content management system and figured that a static website solution would be more straightforward in the long run. My first web pages were based on plain HTML files, so I considered going back to such an old-school approach. However, there are many static web page solutions, so I decided to try a few different options. Here, I will discuss why I ended up with Hugo for my new page.
Exporting with Pelican
It took so long to decide to move because I have a blog post with more than 800 posts and 2000 images. When I looked into various options a couple of years ago, I didn’t find a solution for quickly moving all the content. I must have overlooked Pelican, a static site generator written in Python that has an importer that handles WordPress files.
It almost seemed too good to be true, but in only a few steps, I had downloaded and converted my entire WordPress blog:
- Export an XML file using the menus in WordPress
- Run a small Pelican-script
- Download the media files from my server with FTP
All the paths to images and pages were wrong, but that was easy to fix with some query-replacing in a text editor. So after some initial tweaking, I had a test page up and running.
While the start of my Pelican journey was easy, everything became much more complex when I tried to get themes and plugins to work. I spent a couple of hours trying to make things look nice, but without succeeding. I also realized that most of the files and discussions I encountered were over three years old. People still use Pelican, but the community could be more active. So I started looking for alternatives.
Moving to Hugo
When looking for static website generators, “everyone” mentions Hugo. So I thought I should give it a try. And, yes, I agree that getting up and running is effortless. The most challenging part was that the header syntax is slightly different than from Pelican, but with some more query-replacing and regexp-ing, I managed to get most things sorted out:
Dates need to be in ISO format. I could probably have figured out how to convert the date-time strings from WordPress, but since I do not expect people to be particularly concerned about the time of my blog posts, I ended up stripping the time from the date using the following regex:
(?<=Date: (([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])))).*
Tags must be on separate lines or inside square brackets if separated by colons. The latter was more manageable, so I padded all the tag lines with brackets.
WordPress has a bunch of internal commands that can just be removed. One exception is Youtube embeds, which are painful to fix because the WordPress syntax appears to have changed over the years. I have fixed a bunch of the more recent iframe-based video embeds, but the older ones are tricky, and I will probably have to correct them manually.
Still, it has only taken a couple of hours to “massage” my content into something that works quite ok.
Adding functionality
Setting up a new blog service, I realized that there are many things that one is used to having around. Fortunately, Hugo has built-in solutions for RSS feeds and tagging and a good solution for multi-language support. So I decided to make a separate section of my blog in Norwegian.
The most critical part that needs to be added is a search solution. So that is the main priority right now.
Summing up
I am pleased about finally making a move. It turned out to be faster and easier than expected, although not entirely wrinkle-free. Fortunately, one of the best things about having a static web page is that it is easy to make corrections. Being able to query-replace things across my entire blog is excellent.
There are a couple of things that I miss from WordPress, including automagic image resizing. I could set up a script to do the same for my current system, but it could be more user-friendly.
I have grown accustomed to running my texts through a grammar checker before posting. Nowadays, I use Grammarly Premium for this. I can still do it by manually copying text to Grammarly’s web app, but it was even easier to have it integrated into the WordPress editing view.
Still, all in all, I think my new system will work well and save me from many security headaches in the future.