Set Up a Blog With Hexo
This is a simple record of my further attempt to set up a blog with Hexo. I built one on GitHub Page before, using Hexo with the Icarus theme. This time I want to try something different. I also cleaned up my old blog and selectively migrated some old posts here.
Installation
You need to install Node.js and Git before installing Hexo.
After that, you could run the command below to install Hexo.
1 | npm install -g hexo-cli |
The -g
flag indicates that Hexo is installed globally.
Learn more in Hexo Docs.
Setup
You need to make a directory <folder>
to store your Hexo blog. Here I use fishpond
.
1 | hexo init fishpond |
Learn more in Hexo Docs.
Theme
Before starting to use your blog, you may choose a theme you like.
Here I choose the NexT theme. To install it, run:
1 | npm install hexo-theme-next --save |
After installing your own theme, you could uninstall the default theme hexo-theme-landscape
:
1 | npm uninstall hexo-theme-landscape --save |
Also, clean the folder of the default theme landscape in theme/
.
To enable NexT, open Hexo's config file and set the variable theme
to next
.
1 | theme: next |
Basic configuration
Hexo configuration
To configure your Hexo blog, modify the _config.yml
file.
Learn more in Hexo Docs.
NexT theme configuration
Before configuring, you are recommended to copy the configuration file (so that you don't change the node module). Run:
1 | cp node_modules/hexo-theme-next/_config.yml _config.next.yml |
Then you can follow Configuration | NexT (theme-next.js.org) and customize the NexT theme as your wish.
Plugins
You can install plugins to make your blog more powerful. The plugins are actually all packages managed by npm, so to list all the plugins you have installed, just run:
1 | npm list --depth 0 |
Here are some of the plugins I'm using:
hexo-abbrlink
hexo-abbrlink is a Hexo plugin to generate static post link based on title and data in the post front.
To install it, run:
1 | npm install hexo-abbrlink --save |
To configure it, modify _config.yml
:
1 | # URLs |
hexo-auto-category
hexo-auto-category is a Hexo plugin which generates categories automatically from folder structure for each post.
To install it, run:
1 | npm install hexo-auto-category --save |
To configure it, modify _config.yml
:
1 | # Extensions |
hexo-blockquote2note
hexo-blockquote2note is a little plugin that renders blocks of quotes in Markdown to the note tag of the NexT theme. If you also use the NexT theme, it maybe helpful.
To install it, run:
1 | npm install hexo-blockquote2note --save |
Preview: Introducing hexo-blockquote2note
hexo-generator-feed
hexo-generator-feed helps generate Atom 1.0 or RSS 2.0 feed.
To install it, run:
1 | npm install hexo-generator-feed --save |
To configure it, modify _config.yml
. Here is my configuration:
1 | # Extensions |
hexo-generator-searchdb
hexo-generator-searchdb provides a local search service.
To install it, run:
1 | npm install hexo-generator-searchdb --save |
hexo-generator-sitemap
hexo-generator-sitemap generates sitemap.
To install it, run:
1 | npm install hexo-generator-sitemap --save |
Configuration:
1 | ### hexo-generator-sitemap |
hexo-pangu
hexo-pangu severs side pangu.js filter for Hexo.
To install it, run:
1 | npm install hexo-pangu --save |
Deployment
Manual deployment
hexo-deployer-git helps deploy your blog to your GitHub Page.
To install it, run:
1 | npm install hexo-deployer-git --save |
Modify _config.yml
:
1 | deploy: |
Learn more in One-Command Deployment | Hexo.
Automatic deployment
Using GitHub Action to Deploy to GitHub Pages
By using GitHub Action, our workflow of writing posts will be like this:
- Writes a post.
- Uses
git push
to push your new post to your source repo. - A GitHub Action automatically starts, generating our blog pages.
- Your GitHub Page repo updates automatically.
Here are the steps:
Create a new repository to store your source
*.md
posts. We call thissource repo
. It is recommended to make it private.Add a
./.github/workflows/auto_build_and_deploy.yml
file. It may look like this:
1 | # Based on https://hexo.io/docs/github-pages.html |
<your_token>
: Generate it here. Make sure that its scope includes workflow
.
Learn more in Creating a personal access token - GitHub Docs.
- Configure the local git repo.
1 | # initialize |
Learn more in GitHub Pages | Hexo.
Deploying to Netlify
Go to the create a new site page, select your source repo from GitHub, and follow the prompts.
Learn more in One-Command Deployment | Hexo
Using Vercel
See
Q&A
Where is my index.html in /categories and /tags ?
To generate index.html in /categories
, run:
1 | hexo new page "categories" |
or
1 | hexo n page "categories" |
Then, edit source/categories/index.md
like this:
1 | --- |
You can generate the index.html file in /tags
similarly.
Why did the straight quotes in the text automatically become curved quotes?
If you also use marked (the default) renderer, add the config below to your _config.yml
:
1 | marked: |
Also see 6.4.0 版本之后的两个问题・Issue #462・theme-next/hexo-theme-next.
Old content
Here are some old content migrated from my previous Icarus blog.
Use Bulma to beautify your blog
Change fonts of Icarus.
Modify the
<blog_path>/node_modules/hexo-theme-icarus/include/style/base.styl
:1
2$family-sans-serif ?= Ubuntu, Roboto, 'Open Sans', 'Microsoft YaHei', sans-serif
$family-code ?= 'Source Code Pro', monospace, 'Microsoft YaHei'
This operation modifies the node module! So it's NOT recommended.
Officially supported tags in Icarus