This blog site is powered by Hexo, the theme is NexT, the scheme is Pisces
. After I started building my blog with Hexo, I found that actually there are some more Static Site Generators which are considered better than Hexo. You can find a ranking list of the Static Site Generators here. (But if you have already get started with Hexo, it is O.K. At least I think it is good enough)
⚠ the generator named Next in the list is a different thing from the theme of Hexo I use.
Here I want to share about the problems I meet and my custom settings.
Problems I met
GitHub Pages says I am using a unsupported theme
This problem is very likely to occur if you simply commit your whole Hexo instance to your master branch.
In fact, only a few themes are supported by GitHub Pages and NexT or any Hexo theme is not included 🤦♂But here is a little trick: the files are rendered at your desktop, simple HTML pages are uploaded to the master branch as the source code of your site. In this way, anytheme can be applied to your blog😄
Therefore, you can not simply commit your Hexo instance to the master branch, what I did is to publish a new branch Root
to store my Hexo instance and use the hexo-deployer-git extension to deploy my site to the master branch.
:warning:your GitHub Pages can only published from the master branch if your repository is named username.github.io
If you haven't installed this plugin, use the following command at the root of your hexo instance.
1 | npm install hexo-deployer-git --save |
check here for the configuration.
Cannot commit theme/next to github
Therefore you cannot backup your theme simply committing it to github since it is a subproject. Although a cool solution is provided in #328
, it cannot solve my problem since I did further customization. But I did not try the solution fork+submodule mentioned in #932
. I simply deleted files declaring its identity of a subproject so the theme folder becomes totally a part of my hexo instance.🤦♂ You just need to left these files:
1 | . |
You can also change the theme's name from next
to whatever else, for example LeoJhonSong
:smile:. According to Hexo, you have to then modify the theme setting in your site’s _config.yml
, assigning the name of your theme folder to it.
Pages do not change after modification
the issue could be separated in to two situations.
The modification works on local server
the reason may be:
- sometimes your modification will be ignored if you do not run
hexo clean
to delete the cache file (db.json) - your setting is not first priority in CSS in all probability, the value is overwritten somewhere else
check if the attributes you changed is valid by Chrome DevTools. The invalid attributes will look like this: color: #fff
- you can specific the class name of the item to rise the priority of yuor custom attribute.
- another way is to use !important to force priority to rise. for example,
color: #fff !important
. It is often not recommanded since it ruins existing CSS and may cause difficulty when debugging. In addition, there is still a low risk it is not raised to first priority 😅 as examples are given here
The modification even does not work on local server🤦♂
The reason could be:
- your browser uses the cache data of the GitHub Page instead of reloading it
- there is grammar mistakes in your modification
The solution could be:
Ctrl + F5
orCtrl + Fn + F5
to force the browser to refresh the page- check the generation information to see if there is an error or run
hexo s
to run the site locally to see if something goes wrong
Cannot show emoji
add hexo-filter-github-emojis and then you can use Emojis as you want just like me.✌
if you want to type a emoji but you have no idea what its shortcut is, you could go to emojipedia for help.
Will line feed whenever there is a return in the markdown file
Actually this issue is mentioned in github.
this happened to me because I uninstalled hexo-renderer-marked
and installed hexo-renderer-markdown-it
since the markdown-it markdown parser has plenty of plugins🤦♂.
Sitemap error
Google Search Console may tells you that there is errors in your site if you did not changed your site's url from http://yoursite.com
to your own root url
in your site's _config.yml
...
Error word-count
It had been mentioned here.
I enabled word count provided by Hexo but the count is definitely larger than it should be. But that is not a problem, it can be seen as a decoration 🙈
My custom settings
I am proud of some settings because I tried and achieved it by myself, despite from simply copying others' code. 😝
Commit site to Google
Unfortunately, Baidu crawler is blocked by GitHub because Baidu has been used to attack GitHub. Actually poor Baidu did not mean to do this... But to be honest, Baidu is not a lovely search engine since it puts plenty of ads in its search results🙄. So I won't bother solving the issue that Baidu con not find my blog. Besides, this blog is mainly wrote for myself✌.
install hexo-generator-sitemap
go to Google Search Console and add your site.verify it by
HTML tag
. There you get a <meta> tag like this:1
<meta name="google-site-verification" content="blablablablablabla" />
the
content
is your verification code.add following code to your site's
_config.yml
:1
2
3
4sitemap:
path: sitemap.xml
google_site_verification: your coderun the following code:
1
hexo d -g
now your site should have be added the verification tag.
go back to google search console and commit your sitemap. Your sitemap should be named
sitemap.xml
.DONE!
Multi-Language
This part! Guys, this is my proud since I worked out my own solution. My work is based on this and this
It is described very clearly in Keep Velocity High's post that a multilingual blog implemented with current tools is not good enough. He's idea of running two isolated blog is a good try and thanks to his great work I don't have to do those works again. But just as the second post pointed out, it becomes too hassle that we have to run two independent site if we just want our site could be shown in more than one language. As a individual blogger I do not have that much time to maintain my blog. I have to run three sites, if I want it can be shown in Chinese, English and Japanese! In addition, if we want to change the style of the blog, we have to repeat the work for each language😨.
The solution mentioned in the second post is also very smart, but there is still some problems.
His idea of deploy two site to one repository is impossible since a repository can only have one home page.
In addition, you need a repository namedzh-CN
if you want your chinese site's root url ishttps://yourname.github.io/zh-CN
it definitely waste a lot of time if we have to copy the markdown files to the source folder every time we generate the public folder.
As we can see, most multilingual site will give each site a different root url. Therefore, I decided to use https://leojhonsong.github.io to be the home of my english site and https://leojhonsong.github.io/zh-CN for Chinese site. That is to say, I need a repository called leojhonsong.github.io and a repository called zh-CN for my blog.
Things are simple until now, but here is the trick: since hexo allows us to add alternate config, we use the site's _config.yml
for settings of the english site as well as the basic settings of the blog and create _config.zh-CN.yml
for settings of Chinese site that differs from english site to override settings in _config.yml
. There, we are able to set different source folder path, public folder path for each language and even different repository to deploy the site😄
The following code are my settings.
in _config.yml
:
1 | # Site |
in _config.zh-CN.yml
:
1 | # Site |
Then after generation your directory should look like this:
1 | . |
By this method, you can easily set up a multilingual blog!
:warning: notice that db.json
is the cache file for generation, that is to say, if you generate the files for Chinese site right after generating files for English site, the English files will be mixed into public/zh-CN, which is annoying. So you should run hexo clean
to delete db.json
every time before generating files for different language.
We can also write a batch script and python script to shorten the commands.
put a.bat
in the root directory:
1 | @echo off |
put multi-language.py
in the root directory:
1 | # -*- coding: UTF-8 -*- |
These will make things much easier. You just need to put these two file in the root of your hexo instance and you are good to go. %1, %2 in the code are the parameters passed to the batch. For example, you can type a c g
in cmd in the root of your hexo instance to generate the Chinese files. a is te name of my batch file as I named it a.bat but of course you can change it to want ever you want. By the way, the file name is also a parameter passed to the batch file, %0. c is the second parameter (%1) passed to the batch and g is %2. It is interesting that the parameter's value could be null, that is to say, if you simply type a
, the English files will be generated and deployed then Chinese files will be generated and deployed. The commands a ne
, a nc
, a na
are used to generate new post.But the best part is that the command a na
will call the multi-language.py to write HTML code to link the Chinese post and the corresponding English post. For example, if you want to new a English post named Hello World and its Chinese version 你好世界, the command should be a na 'Hello World' '你好世界'
Categories, About page
Reference here
Search
install the dependencies hexo-generator-searchdb and hexo-generator-search by:
1
2npm install hexo-generator-search --save
npm install hexo-generator-searchdb --saveconfigure settings for hexo-generator-search in site's
_config.yml
:1
2
3
4
5search:
path: search.xml
field: post
format: html
limit: 10000configure settings for hexo-generator-searchdb in theme's
_config.yml
:1
2
3
4local_search:
enable: true
trigger: auto
top_n_per_article: 1
Better response for mobile devices
In themes/next/source/css/_custom/custom.styl
:
1 | @media (max-width: 425px){ |
Custom colors
To customize the background colors of your site, I recommend this site to you as it provides a lot of cool colors.
Things could be quite simply as most colors can be reset using variables in themes/next/css/_variables/base.styl
and themes/next/css/_variables/YourScheme.styl
. You can preview your custom settings utilizing developer tools of your browser. (Here is how we do this in Chrome DevTools.) After decided your custom settings, you reassign the variables which had been defined in the two yml files mentioned above in themes/next/css/_variables/custom.styl
.
:warning: you have to notice that only if your reassignments are in themes/next/css/_variables/custom.styl
will they take effect. They are invalid if they are put in themes/next/source/css/_custom/custom.styl
. Similarly, any other setting not related to the variables should be written in themes/next/source/css/_custom/custom.styl
.
you could find my custom.styl at the end.
Colorful icons for social links in sidebar
As I see it, the single color font icons used by NexT are a little bit dual. In addition, fontawsome does not have some icons I want.
So I use icons from iconfont instead. This site even provides colorful font icons!
in
themes/next/layout/_macro/sidebar.swig
:1
{% set sidebarIcon = '<i class="fa fa-fw fa-' + link.split('||')[1] | trim | default('globe') + '"></i>' %}
comment out but not delete
line 108
(the line above) by replacing it with the following line, in case one day you want it back. Then we add a line to use font icons from iconfont.1
2{# % set sidebarIcon = '<i class="fa fa-fw fa-' + link.split('||')[1] | trim | default('globe') + '"></i>' % #}
{% set sidebarIcon = '<svg class="icon" aria-hidden="true"><use xlink:href="#' + link.split('||')[1] | trim + '"></use></svg>' %}Then add a line after
line 100
to import the source code of the icons:1
<script src="https:{{ theme.social_icons.source }}"></script>
create a project in iconfont to collect icons you want to use in your blog.
here is the tutorial of iconfont.
You can log in with GitHub. After added icons you like to your project, choose quote as
symbol
andView the Online Link
, copy it and put it in your theme's_config.yml
under the social_icons settings like this:1
2
3
4
5social_icons:
enable: true
icons_only: false
transition: false
source: //at.alicdn.com/t/font_980470_nj2qfdk05jb.jssimply put the code of your icons after your social links in your theme's
_config.yml
like this:1
2
3
4
5
6social:
GitHub: https://github.com/LeoJhonSong || icon-github
E-Mail: mailto:LeoJhon.Song@outlook.com || icon-OUTLOOK
FB Page: https://www.facebook.com/jhon.leo.100 || icon-Facebook
QQ: https://user.qzone.qq.com/719957017 || icon-QQ
WakaTime: https://wakatime.com/@LeoJhonSong || icon-waka-time😆 quite easy right?
Visitor number
find busuanzi_count
in your theme's _config.yml
and enable it.
Post word count
Reference can be found here
Improved the arrangement of images in asset folder
Now suppose there is a image wow.jpg in the asset folder of a post named Hello. We could to use ![wow](wow.jpg)
to insert this image. But the annoying problem is that the image won't show up in your markdown preview unless you use ![wow](Hello/wow.jpg)
. But... the image won't show up on your server if Hello/wow.jpg
is used🤦♂
This is because hexo will put the HTML page index.html of the post Hello and the image wow.jpg into the same folder Hello in public folder.
So I modified following file to create a subfolder of the same name of the post in the folder where the post's index.html is put.
in node_modules/hexo/lib/models/post_asset.js
1 | return pathFn.join(post.path.replace(/\.html?$/, ''), this.slug); |
change line23
from ⬆ to ⬇
1 | return pathFn.join(post.path.replace(/\.html?$/, ''), post.path.replace(/\.html?$/, ''), this.slug); |
Unfortunately, according to my test, the tag method to insert images provided by Hexo does not work as it supposed to anymore after modifying the post_asset.js🤦♂. Since I would use anything but the tags so this doesn't bothers me😁. But if you want to improve this situation, I suppose you should modify **node_modules_img.js**
Valine comment system
Search for Valine in your theme's
_config.yml
then you just need to follow instructions here.
My custom.styl
Although as I mentioned here, some settings only take effet if is put in themes/next/source/css/_custom/custom.styl
while some other should be put in themes/next/source/css/_variables/custom.styl
, but it is a little bit annoying that I have to decide where do I put my settings. So I simply put all the settings in both styl custom.styl😆.
1 | // Custom styles. |
Thank you for reading!