New Blog, New Beginning
The Node.js, Hexo and Next themes used in previous blogs are outdated, causing a lot of compatibility issues. So I reconfigured my blog and this post records my configuration and development process.
Install Hexo
Install Node.js, use the command
node --version
to view the installed version, the version I installed is 16.17.0.Install Hexo using
npm install -g hexo-cli
.Use the following commands to initialize and complete the most basic website building.
1
2
3hexo init <BlogDir>
cd <folder>
npm install
My Hexo version is 6.3.0. For more detailed commands, please refer to This Doc.
Using Next theme
There are currently three versions of the hexo next theme: the earliest version, the second version, these two versions have been stopped maintenance, and the latest version is still being maintained. Please refer to this doc for the relationship between the three versions.
All subsequent configurations are based on the latest version.
Download and install the Next theme:
1
2$ cd hexo-site
$ git clone https://github.com/next-theme/hexo-theme-next themes/nextSet
theme: next
inHexo site __config.yml
to enable the Next theme.Set
scheme: Pisces
inNext Theme __config.yml
(You can use other scheme).
Use abbrlink
Hexo uses the Markdown file name as the link by default. If the file name has Chinese, Hexo need to escape the it. In addition, it may lead to a very long link . Modifying the article title causes the article title to not match the file name. Modifying the file name will cause the article link to be modified. None of these above is helpful for search engines to search your blog.
So I hash the filename and use the hash as the link to the article. In this way, the article link will never change, which is convenient for search engines to search.
Install hexo-abbrlink
:
1 | npm install hexo-abbrlink --save |
In Hexo site __config.yml
set:
1 | permalink: /post/:abbrlink/ |
Please refer to this doc for more information.
Modify blog image link
When using hexo-abbrlink
, the address
in
the default Markdown syntax for adding images

is not converted,
resulting in the image not being displayed. Referring to the previous
hexo-asset-image
plugin, I wrote a new plugin to solve this
problem.
Install the plugin:
1 | npm install https://github.com/littlesevenmo/hexo-asset-image2.git --save |
in the Hexo site __config.yml
set:
1 | post_asset_folder: true |
In this way, your blog's post structure will look like this:
1 | YourBlogDoc |
Insert image image.jpg
by

or

.
Then use hexo clean
, hexo g
,
hexo server
to preview.
Blog appearance modification
Modify hyperlink color
In
<BlogDir>/themes/next/source/css/_common/components/post/post-body.styl
,
add:
1 | .post-body p a{ |
Delete have XX posts in total
In
<BlogDir>/themes/next/source/css/_common/components/post/post-collapse.styl
,
add display: none
in .collection-title
:
1 | .collection-title { |
Delete year and date from archives
In
<BlogDir>/themes/next/source/css/_common/components/post/post-collapse.styl
,
add display: none
in .collection-year
:
1 | .collection-year { |
In
<BlogDIr>/themes/next/layout/_macro/post-collapse.njk
,
delete:
1 | <div class="post-meta-container"> |
Delete powered by Hexo
In Hexo site __config.yml
, set:
1 | footer |
Set posts tags from # to tag icon
In Hexo site __config.yml
, set
tag_icon: true
Set categories, tags, etc.
In
Next Theme __config.yml
, set:1
2
3
4
5
6
7
8
9menu:
home: / || fa fa-home
about: /about/ || fa fa-user
tags: /Tags/ || fa fa-tags
categories: /Categories/ || fa fa-th
archives: /archives/ || fa fa-archive
#schedule: /schedule/ || fa fa-calendar
#sitemap: /sitemap.xml || fa fa-sitemap
#commonweal: /404/ || fa fa-heartbeatCreate a catalog file:
1
2cd <BlodDir>
$ hexo new page categoriesIn
<BlogDir>/source/categories/index.md
, add:1
type: "categories"
to article header.
In this way, the content in the page is Category content. Tag is the same.
Add the follows to the head of the blog post:
1
2
3
4
5categories:
- Your categorie
tags:
- Tag1
- Tag2Then you set categories and tags for articles.
AboutMe content can be written in the About page.
Turn off motion
In Next Theme __config.yml
, set:
1 | motion: |
You can also modify other motion configurations in
motion
.
Enable article loading progress bar
In Next Theme __config.yml
, set:
1 | pace: |
Enable math formulas
The syntax of the original math formula rendering plugin is not compatible with Markdown syntax, so I use pandoc for rendering.
Install pandoc.
Uninstall the original math formula editing plugin
1
$ npm uninstall hexo-renderer-marked
Install the plugin using pandoc:
1
npm install hexo-renderer-pandoc
In
Next Theme __config.yml
, set the follows to enable mathjax:1
2
3
4mathjax:
enable: true
# Available values: none | ams | all
tags: noneAdd the follows in the head of the blog post you want to render with Mathjax:
1
mathjax: true
In
Hexo site __config.yml
, set:1
2pandoc:
pandoc_path: C:/Program Files/Pandoc/pandoc.exe # Your real program address
Add search function
Use local search
Install the search plugin:
1
$ npm install hexo-generator-searchdb --save
In
Hexo site __config.yml
, set:1
2
3
4
5search:
path: search.xml
field: post
content: true
format: htmlIn
Next Theme __config.yml
, set:1
2local_search:
enable: true
When clicking search, the index file search.xml
needs to
be downloaded and then searched.
Pros:
- The index file
search.xml
coexists with the blog, which is stable and reliable. - No search restrictions.
Cons:
- When the number of blogs is large, the
search.xml
file will be large and slow to load.
I use this search method on my Chinese site.
Use Algolia to search
There are two plugins that support Algolia search:
hexo-algolia
and hexo-algoliasearch
, the
former can only search article titles, while the latter can search
article content. I use the latter for the English site.
Create an
index
in AlgoliaRecord
Application ID
,Search-Only API Key
,Admin Key
Install
npm install hexo-algoliasearch --save
In
Hexo site __config.yml
, set:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15algolia:
appId: "Your App ID"
apiKey: "Your Search Only API Key"
adminApiKey: "40321c7c207e7f73b63a19aa24c4761b"
chunkSize: 5000
indexName: "Your Index Name"
fields:
- content:strip:truncate,0,500
- excerpt:strip
- gallery
- permalink
- photos
- slug
- tags
- titleIn
Next Theme __config.yml
, set:1
2
3
4algolia_search:
enable: true
hits:
per_page: 10
I think this way will be better: If it is found, it will display the found results, instead of showing that XXX is found within XXX milliseconds, like Google, Baidu does. If it is not found, it will display "not found".
In
<BlogDir>/themes/next/source/js/third-party/search/algolia-search.js
,
delete:
1 | instantsearch.widgets.stats({ |
Pros:
- No need to preload, fast speed
Cons:
- The free version has a limit of 10,000 searches per month.
- Every time you update an article, you need to create a new index.
- In China, search may be slow due to slow internet.
Reference:Next reference doc,hexo-algolia reference doc,Hexo Algoliasearch
Add comment system
The comment system that comes with the Next theme is valine, which is a comment system without a backend, and it is said that there are some information security issues. So I use waline. First we need to follow waline's configuration document to set the required components, and also install the plugin Hexo NexT Waline:
1 | npm install @waline/hexo-next --save |
In Hexo site __config.yml
, set:
1 | # Waline Config File |
If you don't want to enable comments on a page, please set the follows in the header of the article:
1 | comments: false |
The default comment description is Waline
, which is very
strange. In <BlodDir>\themes\next\languages\en.yml
,
add it under post
:
1 | post: |
then you modify Waline
to Comments
.
Set up FTP synchronization
Currently I use a virtual host to host my blog and need to use FTP to upload files. According to ChaosTong/hexo-deployer-ftpsync, I simply modified it to accommodate the latest node.js.
Install:
1 | npm install git@github.com:littlesevenmo/hexo-deployer-ftpsync.git --save |
In Hexo site __config.yml
, set:
1 | deploy: |
Then you can use hexo d
to deploy your blog.
Force access to blog with SSH
Use FTP to upload a file named .htaccess
to the root
directory of the site, the content is
1 | RewriteEngine On |
Since the contents of the public
folder will change
after hexo d
, it has to be copied, pasted and uploaded
again each time. I use the alias command (function in Windows
PowerShell) to execute multiple commands at a time, as follows:
1 | function blogd {cd D:\Blog ; hexo clean ; hexo g ; hexo algolia; Copy-Item -Path .\.htaccess -Destination .\public\; hexo d} |
Please note that the setting method may be different under different virtual hosts
Conclusion
The results of the above tests in my local are 0 Error, 0 Warning