Finally I have decided to buy me a domain. But before that I must keep my content ready.
Earlier on, I was decided on to giving my website a go backend, but I later thought it was an overkill to use golang as a backend for a personal website and I should keep that enthusiasm for a real app. Instead of manually creating a frontend for my site, I will be using already available Hugo theme. I will be migrating my blog which I’m maintaining at codicious.wordpress.com and fxcious.wordpress.com.
Hugo has already done a great job to steal users from WordPress. Reasons are already well known, but I’ll jot it down briefly. Here are the points:
- It’s free, no hosting to pay for. Not only Hugo is free, it can be hosted free too. I’ll be using GitHub Pages or Netlify.
- No server side dynamics. As there are no server side dynamics involved, there is less attack vector.
I have no real gain to migrating to the Hugo, I’m just going with the trend. Also, by using Hugo, I’ll be able to keep close to the go community which already is a language of 2020s.
SEO Crisis - It’s not a big problem to me at the time of migration as I have not a lot of visitor. But if your site have a lot of traffic, you might wanna keep your old installation of WordPress inact to give search engines a transition to keep your SEO rank maintained.
Update: Google has nice tools and tips to avoid this SEO. To avoid it, one should register your new domain on Google Webmaster Tools.
Image Captions - Image captions would go away.
Update: Use figure shortcode. You can always create custom shortcode.
Analytics - In wordpress hosted version, we can see how many people are visiting us, and where they are from and verious democratic data.
Update: Use Google Analytics. There’s a inbuilt template which you can include in your header after writing anatytics id to config.toml. This has a drawback. When you see your website yourself (local development), you put a lot of shit out there on the Google Analytics dashboard. There are a lot of workaround though.
RSS Feed -
I went through a lot a blog posts to see what people have already faced during and after migration. But whatever you say man, writing blog in vim is fun. 😉
Among others is a WordPress to jekyll blog engine converter exitwp.py (also works fine with Hugo). It is written in Python and works on exported xml file. Download the repo:
Enable a virtual environment and install the requirements:
Keep the xml file in wordpress-xml directory (can put multiple files), and:
Copy the created
.markdown files in
_posts directory to to
I also renamed all
.markdown extension to
Other method includes wordpress-to-hugo-exporter. This method assumes a install of WordPress on your own server. One thing I was not aware of before migration was, even if you don’t host your blog at your own, you can download the xml from your wordpress.com website and import it to local install and proceed as a normal. I haven’t tried this method.
If you have a nodejs background, you might like blog2md which also works on exported xml file. Modify
wordpressImport according to will.
No matter what script you use for migration, it will not give you the desired result. There will be some tune up needed, which I’ve discussed in cleanup and tuning process. But just to let you know, the site just runs if you run it in deployment. So maybe one you can proceed to deployment section and publish it first then continue back from here.
Also, I found out that drafts are not converted to hugo format. And I had to manually copy paste the content.
Note on Comment Migration
Although I’ve not tried, Alessandro Bahgat in his blog post says:
Disqus comments are associated with page URLs, so you will want to make sure your pages are served at the same URLs as before the migration. Alternatively, you can edit the URLs in the export file before importing it following the instructions above.
Note on Image Migration
- Downscale images.
- Git LFS should be enabled to keep git repo efficient as git is not meant to track binary files.
- For me, images came up like this after conversion:
It needs to be converted like this:
(Are you wondering why only the above piece of code is hosted on gist and rest natively? Seems like hermit does not support shortcode inside code blocks; or maybe it is by desigh, who knows).
- If you have featured image per post, it goes like this in front matter:
These images is also used in Twitter Cards and the Open Graph metadata.
- Use relative url from static folder.
No matter what method you used above for data extraction, your isn’t going to be perfect. You might semi-automate some of these with tools like or text editor.
Front Matter Cleanup
This is how a typical blog post looked like:
Obviously I don’t need all of them. Following are the things I’m planning to throw away:
author- As I’m the only author of this blog, it’s redundant.
layout- I don’t find any use of them.
categories- categories are by default disabled, tags are enough though.
titleis enough to generate URLs
Janik Vonrotz has covered a lot of these automation if not all in his blog post: https://janikvonrotz.ch/2018/07/08/another-wordpress-to-hugo-migration/
- I checked if code blocks are converted properly and placed correctly (they were not).
- Convert youtube, twitter, image shortcodes to Hugo equivalent. See https://gohugo.io/content-management/shortcodes/
- Check internal links, make them relative. For images, I’ve replaced
/uploads/wherever image is being referenced. And downloaded and kept them inside
/static/uploadsfolder. Inside uploads directory I’ve maintained YYYY and MM subdirectories so that one single directory is not cluttered up.
I didn’t think of these parameters but these also matters. I have not implemented them yet. I’m planning to work on it when the site has started rolling.
Many Hugo users employ Google Custom Search. But it contains ads (in the free edition). That’s why I’m using a simple HTML form and redirect to Google Search but restrict the search to my site.
Related Posts (pending)
Update: Since version 0.27, Hugo provides a powerful solution for related content out of the box. One needs to add a related content section to all single posts page, like below:
Initially I was going to host my website at Github Pages, but while this entire process I came over Netlify. It gives more control over the deployment process. It also works directly with my local Hugo setup and I don’t need another repo with generated html content.
I added these lines in a file called
netlify.tomlin the root of the repo:
1 2 3 4 5 6 7 8 9
[build] publish = "public" command = "hugo --gc --minify" [context.production.environment] HUGO_VERSION = "0.59.1" HUGO_ENV = "production" HUGO_ENABLEGITINFO = "true"
I signed up to Netlify with my git hosting provider by which I was hosting your Hugo repo.
Setting up a new Hugo site was pretty easy and straight forward. At last I selected my brach to which netlify will be looking for new updates.
More information about Netlify deployment can be found at https://gohugo.io/hosting-and-deployment/hosting-on-netlify/.
This was a journey from WordPress to Hugo, and was exaustive actually. Anyways, migrations are always painful than starting from scratch. And Hugo isn’t only used for blogging. I found out a theme which makes it easier to create dotumentation/book/tutorial.
For more updates like this one, please subscribe to this blog below.