About a month ago, I came across Hexo while reading a Termux tutorial. The description stuck with me: Hexo is a fast, minimal blog framework built on Node.js. You write posts in Markdown, and with a good theme it can generate static pages in seconds. That was enough to make me want to build a blog, using Termux as my working environment on Android.
Termux provides a Linux-like shell, so the steps are close to what you would do on Linux or macOS. On Windows, adapt the commands as needed; WSL is also an option.
What you need
- Node.js
- npm or pnpm
- Termux or a comparable terminal
Install the toolchain
The commands below use Termux; substitute your platform's package manager where necessary.
Install Node.js:
pkg install nodejs
Install pnpm:
pkg install pnpm
Check the versions:
node -v
npm -v
# pnpm -v
Install the Hexo CLI globally:
npm i -g hexo-cli
npm i is shorthand for npm install.
Create a Hexo project
# Create the blog project
hexo init my-blog
# Enter the project directory
cd my-blog
# Install dependencies
npm install
my-blog is only an example; use whatever name you prefer.
Start the local server
hexo s
Open http://localhost:4000 in a browser to preview the site.
Commands worth keeping nearby
<table> <thead> <tr> <th>Command</th> <th>Purpose</th> <th>Short form</th> </tr> </thead> <tbody> <tr> <td>hexo server</td>
<td>Start the server</td>
<td>hexo s</td>
</tr>
<tr>
<td>hexo generate</td>
<td>Generate static files</td>
<td>hexo g</td>
</tr>
<tr>
<td>hexo deploy</td>
<td>Deploy</td>
<td>hexo d</td>
</tr>
<tr>
<td>hexo clean</td>
<td>Clear the cache</td>
<td>hexo cl</td>
</tr>
<tr>
<td>hexo new "标题"</td>
<td>Create a new post</td>
<td>hexo n</td>
</tr>
</tbody>
</table>
Common combinations:
hexo cl && hexo g && hexo s
hexo cl && hexo g && hexo d
Add a new post
hexo new "我的第一篇博客"
The file is created at source/_posts/我的第一篇博客.md.
Change the theme (Butterfly as an example)
- Install the theme:
npm i hexo-theme-butterfly --save
- Set the theme in
_config.yml:
theme: butterfly
- Configure it by copying the theme config file to the project root as
_config.butterfly.yml. The Butterfly theme documentation covers the available options.
Deploy to GitHub Pages
- Install the deployment plugin:
npm install hexo-deployer-git --save
- Add the deployment settings in
_config.yml:
deploy:
type: git
repo: [email protected]:<user.name>/<user.repo>.git
branch: main
Replace <user.name> with your username and <user.repo> with the repository that will hold the generated pages.
- Generate and deploy:
hexo cl && hexo g && hexo d
Keep a backup
A blog is also source code, so it is worth backing up. Initialize a Git repository, commit the files, and push them to a separate remote:
# Initialize the Git repository
git init
# Set the local default branch name
git branch -m "main"
# Add all files
git add .
# Commit changes
git commit -m "博客备份"
# Push to the remote repository
git remote add origin [email protected]:<user.name>/<user.repo>.git
git push -u origin main
Replace <user.name> and <user.repo> with your own username and backup repository.
The resulting project layout
.
├── _config.yml
├── _config.butterfly.yml
├── package.json
├── source/
│ └── _posts/
│ ├── 我的第一篇博客.md # Markdown file
│ └── 我的第一篇博客/ # Same-name asset folder
│ └── cover.jpg # Post cover
└── themes/
└── butterfly/
In newer versions, the theme files often sit under node_modules. If you want to customize the theme itself, copy it into themes first.
Maintenance commands
# Daily update flow
hexo cl && hexo g && hexo d
# Create a new post
hexo new "文章标题"
# Local debugging
hexo cl && hexo g && hexo s
Netlify and Vercel
Netlify and Vercel are often faster and smoother than GitHub Pages, so they are worth trying.
Netlify:
- Push the code to a GitHub repository.
- Log in to Netlify.
- Choose "New site from Git" > GitHub.
- Set the build command to
hexo generateand the publish directory topublic. - Click "Deploy site".
Vercel:
- Log in to Vercel.
- Click "Add New Project".
- Import the GitHub repository.
- Choose Hexo as the framework preset and set the output directory to
public. - Click "Deploy".
For a domain, you can look for free options such as .us.kg or .dpdns.org, or buy a professional domain from a paid registrar. With the blog deployed and backed up, the setup is mostly done; after that, it is just a matter of writing, previewing, and deploying when you have something new.