Hexo Setup General
Preface
As a new year resolution, I would like to be better than last year. In the technical aspect, I think starting a blog might be a good way (provided I could keep this habit). I used hexo before, however, due to issues with organizing blog articles and the ugly defaul theme, I stopped after a few articles. After organizing all my browser bookmarks last week, I got some inspirations on how to organize things, hence I am starting a new hexo blog again. Let’s see how far this time I could go.
But firstly, I decided to fix some issues I faced before, to keep my interest and form a habbit of good structure with tags and categories.
Requirements
More could be found on Hexo website:
- Nodejs
- Git
Installation
Install Hexo globally with npm
on the machine:
1 | npm install -g hexo-cli |
Setup
Once Hexo is installed, run following commands to initialize Hexo in the target <folder>
.
1 | hexo init <folder> |
Configuration
Note: This section contains my preference (Marked with Personally).
Hexo
Site settings could be modified in _config.yml
.
Personally, I feel categories
in the permalink
can help with better organization.
1 | # URL |
Difference between :title
and :name
:
:title
is filename relative to source/_posts
folder, whereas :name
is just filename.
For example, content below at the start of the markdown file with different permalink
setting generates different permalink
. (Note the extra 2022 for :title
setting)
1 | title: Hello World |
Setting | Result |
---|---|
:year/:month/:day/:title/ |
2022/01/21/2022/hello-world/ |
:year/:month/:day/:name/ |
2022/01/21/hello-world/ |
Post Layout
Personally, I prefer to add updated
and categories
in the default post layout, this two extra properties can help with better organization. I also like to have a Preface section with a more button to provide a quick summary of the blog post without occupying lots of space by showing the whole article.
1 | --- |
Theme
Personally, the default theme is not very aesthetic appealing to me. I decided to change to Next
1 | cd <hexo_folder> |
Change theme to next:
1 | # Extensions |
Customize next theme (Copy theme config file to hexo_folder
root directory):
1 | # copy command for installation with npm |
My preferred Scheme is Gemini.
1 | # --------------------------------------------------------------- |
Frequently Used Commands
new
1 | hexo new [layout] <title> -p [path_to_article_file] |
Creates a new article.
If no layout
is specified, default_layout
from _config.yml
is used. (That is why I changed scaffolds/post.md
described in Configuration
sections.)
If title
contains space inside, surround it with quotation marks.
Personally, I prefer to specify the path to article file when creating a new article, hence I added this -p [path_to_article_file]
to the command.
Note:
| path_to_article_file
parameter | Actual file path created |
| — | ———– |
| setup
| setup.md
|
| setup/hexo_1.md
| setup/hexo_1.md
|
| setup/
| setup/.md
|
server
1 | hexo server |
Starts a local server at http://localhost:4000
by default.
generate
1 | hexo generate |
Generates static files locally.
clean
1 | hexo clean |
Cleans the cache file (db.json) and generated files (public).
If changing a certain setting does not take effect in the generated static files, running this command and generate static files again could solve the problem. (The favorite restart/reset solves the issue🤣)