Hello Hexo-NexT
Abstract
Hello Hexo and NexT !
Hexo and NexT yyds !
基于Hexo和NexT主题,我的第一个个人网站诞生啦!
这篇文章记录了建立网站的点点滴滴,并持续更新我对心肝宝贝My Website的持续美化、修缮。
建站
Hexo对中文的支持十分友好:Hexo , 直接按照Hexo官方文档进行即可。
1. 安装前提
首先确保计算机上已经安装Node.js 和Git。进不去网站的话,安装包已经屯好了:百度网盘 蓝奏云
2. 建立Hexo初始网站
- 安装Hexo(任意位置)
1 | npm install -g hexo-cli |
- 建立一个文件夹存放所有博客文件:
1 | benkangpeng@DESKTOP MINGW64 /d/Hexo |
- 在/d/Hexo文件夹使用如下方法创建一个blog(可修改名称) , 并进入:
1 | benkangpeng@DESKTOP MINGW64 /d/Hexo |
blog文件夹内存放的就是网站blog源文件,如果想再建立一个网站,同样在Hexo文件夹下使用hexo init blog_2
创建blog_2文件夹……
- 在blog文件夹中加入hexo相关配置:
1 | benkangpeng@DESKTOP MINGW64 /d/Hexo/blog |
- 查看网页
1 | benkangpeng@DESKTOP MINGW64 /d/Hexo/blog |
进入INFO中的端口http://localhost:4000/
即可看到hexo博客框架:

1 | hexo new "第一篇文章" |
Hexo即在/blog/source/_posts/
创建了一个第一篇文章.md
。
实时编辑,在https://localhost:4000
端口中刷新便可实时显示。
设置hexo主题
我们选择hexo-NexT主题——一个简洁、使用人数多、插件丰富的主题。更多主题可在Themes | Hexo找到。
配置NexT主题
我们选择hexo-NexT主题——一个简洁、使用人数多、插件丰富的主题。
Next的最新官网是NexT - Theme for Hexo (theme-next.js.org) , 而不是Home Page | Theme-Next , 原因详见:Issue
- 安装NexT
1 | benkangpeng@DESKTOP MINGW64 /d/Hexo/blog |
- 配置网站
你会发现文件中有两个配置文件,在blog中有一个_config.yml
, 即Hexo的配置文件 , \Hexo\blog_test\node_modules\hexo-theme-next
中有一个_config.yml
, 即NexT主题的配置文件。
However, we do not recommend directly modifying the NexT config file. It is quite often running into conflict status when updating NexT theme via
git pull
, or need to merge configurations manually when upgrading to new releases. For the theme installed through npm, it is also difficult to modify the NexT config file innode_modules
.
In order to resolve this issue, we recommend using the Alternate Theme Config feature to configure theme NexT.
官网提示我们,在修改NexT配置文件时不要直接修改 \Hexo\blog_test\node_modules\hexo-theme-next
, 否则可能引起冲突。官方提供给我们一个方法Alternate Theme Config , 简而言之将 \Hexo\blog_test\node_modules\hexo-theme-next\_config.yml
复制到blog\
下,更名为_config.next.yml
, 这样直接修改blog\
下的两个配置文件即可对Hexo和NexT均进行配置。
可手动配置,也可在相应位置执行命令:
1 | benkangpeng@DESKTOP MINGW64 /d/Hexo/blog |
- Hexo Configuration
Edit _config.yml
1 | # Site |
1 | # theme: landscape 记得修改主题为NexT |
- NexT Configuration
Edit:
1 | minify: true |
- Configuring Favicon
We can visit Favicon.ico图标生成器 to generate our favicon by inputting characters .
Put the favicon files in Hexo\blog_test\node_modules\hexo-theme-next\source\images
, then edit NexT config file
according to the filename:
1 | favicon: |
- Also add the avatar :
For example , I add GNU-Linux-Logo-Penguin-SVG.jpg
to Hexo\blog_test\node_modules\hexo-theme-next\source\images
Edit _config.next.yml
:
1 | avatar: |
- Configuring Menu
We can add the Menu items
by removing the comments in _config.next.yml
:
1 | menu: |
Menu settings item’s format : key: /link/ || icon
. Key
is the name of menu items(home , tags , etc.) , and link is the target link to relative url inside your site . For example , if the menu item is other: /other/ || icon
, it will go to https://benkangpeng.github.io/other/
when you click it .
Except home and archives, all custom pages under menu section need to be created manually.
Tips above means that , when you add new menu items , you should also create relative files except home and archives
as they can create relative files automatically .
For example , three steps to add menu item tags
:
①Removing the comment of tags :
1 | menu: |
②Create relative files :
1 | $ hexo new page tags |
③Editting the markdown file index.md
of \blog_test\source\tags\
1 | title: Tags |
That’s all . As for the ways of the offical doc , I’m absolutely confused ……
Beautify
Custom pages
If we want to add a .html
to the website and don’t want NexT to influence that .html
‘ s style , which means .html
can be displayed on its own style , how do we do ?
The answer is : Prevent Hexo from rendering my .html files.
- Now create a new page :
1 | hexo new page Other |
- Edit the
_config.next.yml
to displayOther
in menu
1 | menu: |
Find the name of font-awesome icons from Font Awesome
- Edit the
_config.yml
to make sure folder/Other
cann’t be rendered by Hexo .
1 | skip_render: |
- Delete the
index.md
in/source/Other
, and createindex.html
We can write something in index.html
, which will keep its style and not be rendered by hexo .
Read more
It’s a common need to show some part of article in home page and a Read more
button to view more .
The best way is : Use <!-- more -->
in the article to break the article manually .
Post Wordcount
Install plugin hexo-word-counter
:
1 | npm install hexo-word-counter |
Edit _config.yml
:
1 | symbols_count_time: |
Tag Icon
By default, tags at the bottom of posts have a symbol # at there left side.
If you prefer icon instead of symbol, edit _config.next.yml
like following:
Codeblock Style
You can go to Highlight (theme-next.js.org) to choose the theme you like and it will give the way to edit the .yml
.
1 | # _config.yml |
1 | # _config.next.yml |
Back To Top
1 | # _config.next.yml |
Reading Progress
1 | # _config.next.yml |
GitHub Banner
NexT provide Follow me on GitHub
banner on the right-top corner .
1 | # _config.next.yml |
Tag Plugin
Button
NexT provide the tag plugin button
, which can jump to corresponding link .
- Usage
1 | {% button url , text , icon[class] , [title] %} |
or
1 | {% btn url, text, icon [class], [title] %} |
url
: Absolute or relative path to URL.text
: Button text. Required if no icon specified.icon
: Font Awesome icon name. Required if no text specified.[class]
: Optional parameter. Font Awesome class(es):fa-fw
|fa-lg
|fa-2x
|fa-3x
|fa-4x
|fa-5x
[title]
: Optional parameter. Tooltip at mouseover.
eg.
1 | {% btn # , Text , home , mouseover %}{% btn # , Superpowers , fa fa-external-link , mouseon %} |
- We can also use
Button
inside text , for example :
1 | For search engineer , I prefer {% btn https://cn.bing.com , Bing , fa fa-search , Bing %} instead of {% btn https://baidu.com , Baidu , fa fa-bomb , Baidu %} |
For search engineer , I prefer Bing instead of Baidu.
Button margin
Well , maybe this feature is useful for me to build a aggregation of commonly used website .
1 | <div style = "display : flex ; align-items : center ; justify-content : center"> |
Group Pictures
Group Pictures
is also an awesome plugin ! Maybe I will use group picture
to build my photo repo .
- Usage
1 | {% gp [number]-[layout] %} |
[number]
: optional . Total number of pictures .
[layout]
: optional . The index of the layout, which can be obtained according to the figure below. For example, if you want to apply the second layout to 4 pictures, then use .
1 | {% grouppicture 4-2 %}{% endgrouppicture %} |







It’s recommended to enable fancybox
before using group pictures
.
1 | # _config.next.yml |
Link Grid
Link Grid
is simple to group pictures
, which may be called “Group Links” . It may be really awesome to code a page containing some commonly used links by link grid
, I think .
- Usage
1 | {% lg [image] [delimiter] [comment] %} |
[image]
: Optional parameter. Default image URL.[delimiter]
: Optional parameter. If the optional delimiter parameter is given, it is interpreted as the delimiter of items in each line.[comment]
: Optional parameter. If the optional comment parameter is given, it is interpreted as the symbol to comment out a line.
{% lg [image] %}
1 | {% lg %} |
Well , maybe I get in trouble …… I can’t add the code above here , otherwise there are many bugs after running hexo clean && hexo g && hexo s
. But in other file , such as External-link
in menu , it works .I can’t solve this problem ……
Mermaid & WaveDrom
Two plugins above is useful for flow chart painting .
Note
- Settings
1 | # NexT config file |
- Usage
1 | {% note [class] [no-icon] [summary] %} |
[class]
: Optional . Supported values : default
| primary
| success
| info
| warning
| danger
[no-icon]
: Optional . Disable icon in note .
[summary]
: Optional . Summary of note .
- Examples
1 | {% note %} |
without define class style
1 | {% note default %} |
default style
1 | {% note primary %} |
Primary Header
Welcome to Hexo!
1 | {% note info %} |
Info Header
Welcome to Hexo!
1 | {% note success %} |
Success Header
Welcome to Hexo!
1 | {% note danger %} |
Danger Header
Welcome to Hexo!
1 | {% note info no-icon %} |
1 | {% note primary This is a summary %} |
NexT also provide the PDF
plugin which can add the pdf viewer in the website .
Third Party Plugins
Pjax
Easily enable fast AJAX navigation on any website (using pushState() + XHR)
Pjax is a standalone JavaScript module that uses AJAX (XmlHttpRequest) and pushState() to deliver a fast browsing experience.
It allows you to completely transform the user experience of standard websites (server-side generated or static ones) to make users feel like they are browsing an app, especially for those with low bandwidth connections.
No more full page reloads. No more multiple HTTP requests.
Pjax does not rely on other libraries, like jQuery or similar. It is written entirely in vanilla JS.
"Make users feel like they are browsing an app"
? True or False ? Unbelievable !
Just Edit in _config.next.yml
:
1 | pjax: true |
Math Equations
NexT also provide some plugins to render math equations . As I don’t plan to write math notes on my blog (It’s convient to write them in LaTex , isn’t it ?) , so maybe next time !
Lazyload
It delays loading of images in long web pages. Images outside of viewport will not be loaded before user scrolls to them.
1 | # _config.next.yml |
Animation
NexT provide the animation behavoir . But for me , it’s unnecessary , and I can close animation function to speed my website .
1 | motion: |
Quicklink
Quicklink is a JavaScript plugin that faster subsequent page-loads by prefetching in-viewport links during idle time. Chrome, Firefox, Edge are supported without polyfills.
You can enable it by setting value quicklink.enable
to true
in NexT config file.
1 | # _config.next.yml |
AddToAny
Share your artical to external patform by AddToAny
.
On my view , it’s useless ………
1 | # AddToAny Share. See: https://www.addtoany.com |
Local Search
Plugin hexo-generator-searchdb
provide our website with a local search engineer .
- Installation
1 | npm install hexo-generator-searchdb |
- Edit in
_config.yml
1 | search: |
- Edit in
_config.next.yml
1 | local_search: |
All right , it’s all about Hexo beautifying !