Migration from Hexo to Hugo

How this blog was created

In 2015, I built this blog with Hexo and Theme Octo.

Why I migrate to Hugo

Hugo is written in Golang and it’s much faster.

How to migrate

1
brew install hugo
1
hugo new site blog

There are a bunch of Hugo Themes for you to pick. I picked the DoIt theme.

There are so many exciting features, like mobile-friendly, search, i18n, emoji. The full feature list is here

There are two ways to use the theme you chose above.

1
2
git init
git clone https://github.com/HEIGE-PCloud/DoIt.git themes/DoIt

or

1
git clone https://github.com/HEIGE-PCloud/DoIt.git themes/DoIt

Create a blog post

1
hugo new posts/first_post.md

Execute the following commands in the root directory, which is blog here.

1
2
cd content
mkdir posts

Then copy all your Hexo posts to the folder posts

After the site was created, there would be a template for new post like below in the file $site$/archetypes/default.md

1
2
3
4
5
---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
---

You should assign false to the draft item to publish your blog.

Just run the command below to preview your site at http://localhost:1313/

1
hugo server

Before publishing, you have to create a repo on Github like this

1
https://$USERNAME$.github.io/

Commands for publishing your blog posts.

1
2
3
4
5
6
7
cd public
git init
git remote add upstream https://github.com/$USERNAME$/$USERNAME$.github.io.git

git add .
git commit -m  "first commit"
git push -u origin main

To do the deployment easier, you can build a shell script named deploy.sh in the root directory of you site with the content below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash

echo -e "\033[0;32mDeploying updates to GitHub...\033[0m"

# build the project
hugo -t even

cd public

git add .

msg="rebuilding site `date`"

if [ $# -eq 1 ]
  then msg="$1"
fi

git commit -m "$msg"

# push source to github

git push upstream master

# come back to blog root

cd ..

And assign execution permission to deploy.sh

1
chmod u+x deploy.sh

Next time when you need to publish, you just run

1
./deploy.sh

TO BE UPDATED.