I recently moved my blog here using Hexo instead of previous Jekyll, though the old version is still available. Hexo is a fast, simple & powerful blog framework. Compared with Jekyll, Hexo is more flexible in terms of setup, post writing via Markdown, tags, themes, content searching, 3rd-part plugin support, etc.
This post summarizes the setup steps of Hexo in Windows 10, which I hope will somehow help those who want to blog using Hexo as well.
Install
- Install Node.js. Verify installation via running
node -v
in cmd. - Install Git. Verify installation via running
git version
in cmd. Install Hexo (using the following command in cmd). Verify installation via running
hexo version
in cmd.1
npm install -g hexo-cli
Note: If encountering with “Error: Cannot find module ‘hexo’”, try install Hexo using the following command instead
1
npm install hexo
Init blog
- Open cmd in the target base folder.
- Run the following commands (assume blog root folder as
blog
):1
2
3hexo init blog
cd blog
npm install
Config
Setup deploy repo1
- Create a Git repo, e.g.
blog
underme
GitHub account. - Add SSH Key to
me
GitHub account (assuming assocaited with email accountme@gmail.com
).- Open Git Bash.
- Run commands
1
ssh-keygen -t rsa -C me@gmail.com
- Open created
id_rsa.pub
and copy all its content tome
GitHub account.
- Setup user info by running following commands in Git Bash
1
2git config --global user.name "user_name"
git config --global user.email "email_address"
Use NexT theme
- Download NexT releases and put it to
blog/themes/next
. - Enable it by editing
blog/_config.yml
.1
theme: next
Support global search2
- Install plugin
hexo-generator-searchdb
. Run following commands in cmd.1
npm install hexo-generator-searchdb --save
- Add following config to
blog/_config.yml
.1
2
3
4
5
6# search
search:
path: search.xml
field: post
format: html
limit: 10000 - Enable in theme config, i.e.
blog/themes/next/_config.yml
.1
2
3# Local search
local_search:
enable: true
Support images via standard Markdown5
- Enable in config
blog/_config.yml
.1
post_asset_folder: true
- Run commend in cmd.
1
npm i -s hexo-asset-link
- Done! Add image in post using
1
![Alt Text](Post-Asset-Folder/image-name.png)
Support LaTex math equations3
- Install Kramed to replace Marked.
1
2npm uninstall hexo-renderer-marked --save
npm install hexo-renderer-kramed --save - Config
blog/node_modules/hexo-renderer-kramed/lib/renderer.js
. Replaceby1
2
3
4
5// Change inline math rule
function formatText(text) {
// Fit kramed's rule: $$ + \1 + $$
return text.replace(/`\$(.*?)\$`/g, '$$$$$1$$$$');
}1
2
3
4// Change inline math rule
function formatText(text) {
return text;
} - Install
hexo-renderer-mathjax
to replacehexo-math
.1
2npm uninstall hexo-math --save
npm install hexo-renderer-mathjax --save - Config Mathjax CDN in
blog/node_modules/hexo-renderer-mathjax/mathjax.html
. Config<script>
as1
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"></script>
- Config
blog/node_modules/kramed/lib/rules/inline.js
.- Replace by
1
escape: /^\\([\\`*{}\[\]()#$+\-.!_>])/,
1
escape: /^\\([`*\[\]()# +\-.!_>])/,
- Replace by
1
em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
1
em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
- Replace
- Enable Mathjax in
blog/themes/next/_config.yml
1
2mathjax:
enable: true - Enable in given post (only enable when needed for speed).
1
2
3
4
5---
title: ...
date: ...
mathjax: true
---
Support Disqus comments4
- Setup on Disqus.
- Create an account and log into Disqus.
- Click the
GET STARTED
button. - Click
I want to install Disqus on my site
. - Enter
Website Name
, which will serve as your Disqus shortname, and select aCategory
. - Click
Create Site
button. - In
2. Install Disqus
, clickI don't see my platform listed, install manually with Universal Code
, and then clickConfigure
. - Click
Complete Setup
.
- Config in
blog/themes/next/_config.yml
.1
2
3
4disqus:
enable: true
shortname: your-short-disqus-name
count: true
Write, preview & deploy
- Create a post, e.g.
first post
. This will addblog/source/_posts/first-post.md
, which can be edited using any text/Markdown editor you want.1
hexo new "first post"
- Build and preview posts (preview at http://localhost:4000)
1
hexo generate && hexo server
Note: While in preview, post edits will be updated in realtime (may require refreshing the preview page).
- Deploy/publish. By default, it will be available at https://me.github.io.
1
hexo clean && hexo g -d
1. 针对github权限导致hexo部署失败的解决方案 ↩
2. hexo - Next 主题添加搜索功能 ↩
3. 如何在 hexo 中支持 Mathjax? ↩
4. Comment Systems ↩
5. Adding Images to Hexo Posts with Markdown ↩