Introduction to Hugo

Previously, I used Hexo to build my blog. As I’ve been using Go more and more, I’ve wanted to migrate my blog to Hugo. Hugo is a static site generator written in Go—simple, easy to use, efficient, extensible, and fast to deploy.

Installing Hugo

Here’s how to install Hugo on macOS:

1
2
3
4
5
6
brew install hugo
hugo new site wanzi
cd wanzi
git clone https://github.com/xianmin/hugo-theme-jane.git --depth=1 themes/jane
cp -r themes/jane/exampleSite/content ./
cp themes/jane/exampleSite/config.toml ./

Update config.toml with your own blog information.

My website directory structure looks like this:

 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
27
28
29
30
31
32
33
.
├── LICENSE
├── archetypes # Stores default.md, the template for post headers
│   └── default.md
├── config.toml
├── content # Global configuration for the entire site
│   ├── about.md
│   └── post
├── data # Stores data or configurations (JSON, TOML, YAML)
├── layouts # Contains template files for the site
├── public # Static files generated after Hugo compilation
│   ├── 404.html
│   ├── about
│   ├── atom.xml
│   ├── categories
│   ├── css
│   ├── favicon.ico
│   ├── fonts
│   ├── icons
│   ├── index.html
│   ├── js
│   ├── manifest.json
│   ├── mark
│   ├── posts
│   ├── robots.txt
│   ├── rss.xml
│   ├── sitemap.xml
│   └── tags
├── resources
│   └── _gen
├── static # Stores static assets like images, CSS, JS
└── themes # Stores website themes
    └── jane

Writing Posts

1
hugo new content/posts/git-commands-base.md

Push to GitHub

1
2
3
4
5
6
7
cd wanzi/public
git init 
git remote add origin https://github.com/iwz2099/wanzi
echo "wnote.com" > CNAME
git add -A
git commit -m "initialization"
git push -u origin master

If you’re using a custom domain, simply create a CNAME file in your GitHub repository and add your domain name (e.g., wnote.com). This will allow visitors to access your blog via your custom domain.