Building a Blog on GitHub
2023 Blog Migration from hexo to hugo
The main reason was getting tired of hexo taking forever to generate each time, plus the npm package dependency management issues — maintenance was indeed a burden. And hugo, as a static site generator written in Go, is genuinely much faster.
- Chose hugo as the tool
- Chose Hugo.NexT as the theme
- Chose CloudFlare for CDN
The migration process was quite a hassle, mainly converting front matter format from YAML to TOML, and the various configuration differences between themes were quite significant, but eventually it all worked out.
Migration Process
Setting Up the New hugo Environment
| |
This CI workflow mainly automates pulling code, installing hugo, generating static files, and then automatically pushing to GitHub Pages — completely liberating the manual deployment process.
Building github ci workflows
flowchart LR
classDef primary fill:#e3f2fd,stroke:#1976d2
classDef process fill:#f3e5f5,stroke:#7b1fa2
classDef network fill:#fff3e0,stroke:#ff9800
classDef storage fill:#e8f5e9,stroke:#4caf50
classDef alert fill:#fce4ec,stroke:#e53935
A@{ shape: process, label: "push to main" } --> B@{ shape: process, label: "Checkout + Submodules" }
B --> C@{ shape: process, label: "Setup Hugo" }
C --> D@{ shape: process, label: "hugo build" }
D --> E@{ shape: process, label: "Deploy to GitHub Pages" }
class A process
class B primary
class C process
class D process
class E network | |
Looking back, it’s quite interesting — over 6 years, the blog toolchain went from hexo to hugo, from the JavaScript ecosystem to the Go ecosystem. It feels like the entire technology stack has been replaced.
2017 Blog Construction
At that time, hexo was chosen mainly because the Node.js ecosystem was quite active, and the Chinese community had plenty of resources. After all, it was my first time setting up a personal blog, so choosing a familiar language ecosystem was the safer bet.
- Chose hexo as the tool
- Chose NexT.Mist as the theme
- Chose CloudFlare for CDN
Setting Up the Local hexo Environment
For detailed steps, please refer to the official website. Here we only mention the noteworthy points during the process.
- Refer to hexo for local installation. I was using a
debiansystem. - In China, you often encounter the GFW issue. It’s recommended to use Taobao’s cnpm. Back then, npm frequently failed to install due to network issues, and cnpm really saved a lot of trouble.
| |
Then use the cnpm command to install hexo-cli
| |
- Customize your own configuration, and create an
xxx.github.iorepository onGitHub. - Initialize a git repository in hexo’s local
sourcedirectory, and manage it on your own git repository.
Configuring CDN and HTTPS
- Create a
CNAMEfile in hexo’s localpublicdirectory with your domain name as the content. - Register for CloudFlare, and switch your domain’s NS to CloudFlare management.
- In CloudFlare’s Crypto page, set SSL to Flexible. This allows CDN to GitHub Pages access via HTTP.
- CloudFlare provides Page Rules functionality,
which can set routing rules. Through the
Always use httpsoption in the rules, you can force redirect users to HTTPS.
| |
CloudFlare was chosen mainly because it was free, and the access speed from within China was decent. For a personal blog, it was good enough.
Using Docker to Build Blog Static Files
- Build a local
hexoimage using aDOCKERFILE. This was mainly for cross-machine deployment consistency, avoiding issues caused by Node version differences across environments.
| |
- Run locally after building to debug
hexo
| |
Finally Package and Merge into GIT Repository Management
The workflow back then was simple: write articles locally, generate static files, and push to the GitHub Pages repository. That’s it.
| |