这是啵啵的第一篇博客日志,就记录一下这个博客是怎么利用github和Hexo静态博客框架搭建起来的吧。
This is the first blog of Bobby. This guthub page is built under the perfect guidance from Sunwhut’s blog. Here I just mention some key steps to create this blog with Windows7 + Gitbub + Hexo. All the instructions and software have been tested on my Windows7. Also working on Mac OS High Sierra 10.13.6.
Software
The official Node.js and Github desktop:
The offline installers are available on CSDN:
- http://download.csdn.net/download/shshwzs/8038675
- http://download.csdn.net/download/lyg468088/8723039
Github
Github SSH key
Launch Git Shell on Windows. Type
When it’s done, this OS is authenticated to the github repository.
Create blog repo
Each Github account can set exactly one corresponding blog repo. For user tony, his github page repo should be named tony.github.io.
Hexo
Hexo Installation
Launch Git Shell on Windows. Type in
|
|
to install the Hexo. The npm should work with Node.js.
Hexo Deployment
Now we are going to create a workspace for our blog. Firstly we can shift from disk C to D with
Now create the workspace named Hexo with
Enter the workspace and install the blog content with
Hexo Theme NexT.Mist
The default theme of Hexo is landscape, which looks umm… There are a lot of themes provided in Hexo Themes. Take NexT.Mist for example. In the workspace Hexo, download the NexT theme with
In the workspace Hexo, edit file _config.yml and search for keyword theme:
To apply the Mist style of NexT, enter the NexT folder at D:\Hexo\themes\next, edit file _config.yml and search for keyword scheme:
|
|
Don’t forget the space after the colon. With this _config.yml, we can also modify the menu with
Note that corresponding page is required. For more information about the settings of NexT theme, please visit iissnan’s official guide.
Blog post
Create a new post
Launch Git Shell and enter the workspace.
More info: Writing
It’s OK to simply create a new .md file at D:\Hexo\source_posts. The markdown file will be transformed into html. The grammar of MD can refer to Introduction to Markdown and note for markdown. We can use Online markdown tool to preview .md file. Note that if you do not want an .md file to be transformed into html, like README.md on github, you can simply rename it as README.MDOWN.
Preview the post
To preview the post, firstly generate all the related static files with
More info: Generating
Then run the local server at localhost on port 4000:
More info: Server
Now we can preview the static post by visiting http://localhost:4000/
If you want to regenerate the files, use
to clear all the deprecated files.
Deploy to remote sites
When everything is done and generated, we need to deploy it to the remote github.io.
Edit the _config.yml at workspace Hexo and search for keyword deploy:
123456# Deployment## Docs: https://hexo.io/docs/deployment.htmldeploy:type: gitrepository: https://github.com/yourname/yourname.github.io.gitbranch: masterDeploy to the github page with
1$ hexo deployIf ERROR occurs try to install the deploy-git with
1$ npm install hexo-deployer-git --saveThen clean - generate - deploy.
Comment Service
This part is deprecated. See update below.
Comment added following the official guide this guidance. Since the Hexo is a static blog based on Node.js, the comment function has to be introduced from third-party comment service such as Duoshuo and Disqus. ~~
~~* Create a new account at Duoshuo. Edit the _config.yml at workspace *Hexo
Edit the _config.yml* at theme NexT
The Duoshuo userID can get in this way: Visit http://dev.duoshuo.com/. Then click your account at the top right and select “My home page” in the slide bar. The string of numbers at the end of the link is your userID in Duoshuo.
Duoshuo also provides a share system, which can simply activated by set the value of keyword duoshuo_share to true in the _config.yml in the folder of theme NexT. The blog url should also be set correctly in the _config.yml of the workspace Hexo(search for keyword url).
|
|
|
|
Picture Service
I am using sina weibo picture service on chrome extension, but I don’t think sina will keep this service available for free.
Pictures can also be added by path. Put the pictures into folder workspaceOfHexo\themes\next\source\images
or workspaceOfHexo\themes\next\source\uploads
. The settings for example can be set with
|
|
in the Hexo’s _config.yml file.
Page View Count
Credit to Doublemine’s blog
- Create an account at LeanCloud.
- Create a new application and name it as you like.
- Create a new class whose name must be Counter.
- Get the App ID and App Key and add them into the configuration file _config.yml of the NexT theme folder (search for keyword leancloud).
========2016.12.01=========
Show the update of each post
Credit to this deleted but cached page
Edit
...\Hexo\themes\next\layout\_macro\post.swig
, search for tag<div class="post-meta">
and add the following tags next to<span class="post-time">
:12345678{%if post.updated and post.updated > post.date%}<span class="post-updated"> | {{ __('post.updated') }}<time itemprop="dateUpdated" datetime="{{ moment(post.updated).format() }}" content="{{ date(post.updated, config.date_format) }}">{{ date(post.updated, config.date_format) }}</time></span>{% endif %}The class
post-updated
is used to retreive the corresponding value in the language configuration.Edit
...\Hexo\themes\next\languages\xx.yml
. For theen.yml
, search for keyword “post”:1234post:...updated: Updated on...Edit
workspaceOfHexo\Hexo\themes\next\_config.yml
and add a line at the bottom:1display_updated: trueNow each time you update your existing post, add “updated xxxx-xx-xx xx:xx:xx” below the “date xxxx-xx-xx xx:xx:xx” to manually set the updated date. Actually, once you modify the post, it would be displayed on the post.
========2017.04.13=========
The DuoShuo Comment Service is going to be closed in June, 2017. An alternative system named JiaThis/YouYan seems to be a good choice, though Hexo does not initially add support for it. Reference to this guidance.
- Register at YouYan and remember you uid.
Create youyan.swig at
workspaceOfHexo\themes\next\layout\_scripts\third-party\comments
:123456789101112131415{% if not (theme.duoshuo and theme.duoshuo.shortname)and not theme.duoshuo_shortnameand not theme.disqus_shortname %}{% if theme.youyan_uid %}{% set uid = theme.youyan_uid %}{% endif %}{% if page.comments %}<!-- UY BEGIN --><script type="text/javascript" src="//v2.uyan.cc/code/uyan.js?uid={{uid}}"></script><!-- UY END -->{% endif %}{% endif %}Edit
workspaceOfHexo\themes\next\layout\_scripts\third-party\comments.swig
and add include for youyan.swig:123{% include './comments/duoshuo.swig' %}{% include './comments/disqus.swig' %}{% include './comments/youyan.swig' %}Edit
workspaceOfHexo\themes\next\layout\_partials\comments.swig
and add element for YouYan comment:123{% elseif theme.youyan_uid %}<div id="uyan_frame"></div>Add your uid at theme config file
workspaceOfHexo\themes\next\_config.yml
:12# youyanyouyan_uid: UID_numbers...Unfortunately, the YouYan comment count is still unable to show the statistics in the row right below the Topic.
The Duoshuo Share is also replaced by JiaThis share. Enable it at theme config file
workspaceOfHexo\themes\next\_config.yml
:1234# Sharejiathis:enable: trueid: UID_numbers...Modify the JiaThis Share style by editing jiathis.swig at
workspaceOfHexo\themes\next\layout\_partials\share
:1234567891011121314151617181920212223242526<!-- JiaThis Button BEGIN --><div><a class="jiathis_like_tsina" data="width=120"></a></div><div class="jiathis_style"><span class="jiathis_txt">ShareTo: </span><a class="jiathis_button_tsina">Weibo</a><a class="jiathis_button_weixin">Wechat</a><a class="jiathis_button_douban">Douban</a><a class="jiathis_button_fb">Facebook</a><a class="jiathis_button_twitter">Twitter</a><a class="jiathis_button_googleplus">Google+</a><a class="jiathis_button_tumblr">Tumblr</a><a href="//www.jiathis.com/share?uid=xxx" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a><a class="jiathis_counter_style"></a></div><script type="text/javascript">var jiathis_config = {data_track_clickback: true,hideMore: false};</script><script type="text/javascript" src="//v3.jiathis.com/code/jia.js?uid=xxx" charset="utf-8"></script><!-- JiaThis Button END -->Unfortunately again, YouYan does not support HTTPS. Since github page uses https, request for http resources is blocked, which means YouYan is not able to show off on blog, even though this method is locally feasible.
So let turn to another system Disqus, which is blocked in mainland.
Firstly, recover Duoshuo share by modifying
workspaceOfHexo\themes\next\_config.yml
:1234# Shareduoshuo_share: trueduoshuo_shortname: xxxSince we don’t want to use Duoshuo comment, we need to put config of disqus in front of duoshuo in
workspaceOfHexo\themes\next\layout\_partials\comments.swig
- Add disqus shortname in
workspaceOfHexo\themes\next\_config.yml
. Theoratically done, but seem to be blocked in mainland…
========2016.12.01=========
Sort the posts by last update
Referred to this guide.
Modify node_modules/hexo-generator-index/lib/generator.js
like the following:
AddThis Share
Referred to this post.
Go to AddThis to register and customize your own sharing buttons. Get AddThis ID in Profile Options - General and paste it into workspaceOfHexo\Hexo\themes\next\_config.yml
. Supports HTTPS, though not stable.
========2019.01.05=========
Found another tutorial to make Hexo.Next even better.
Update Hexo
Simply run npm update -g hexo
in terminal.
Use scheme Gemini
Modify 「Next Theme config」:
I don’t like the black headband hanging at the top of the page, so I add custom setting in hexo/themes/next/source/css/_custom/custom.styl
:
Add local search
- Install local search plugin at the root of hexo with
npm install hexo-generator-search --save
. Modify the hexo config:
1234search:path: search.xmlfield: postcontent: trueEnable local search at the theme Next config:
123456789local_search:enable: true# if auto, trigger search by changing input# if manual, trigger search by pressing enter key or search buttontrigger: auto# show top n results per article, show all results by setting to -1top_n_per_article: 10# unescape html strings to the readable oneunescape: false
Add NeedMoreShare2
Simply enable the needmoreshare2 in the theme Next config.
Add site count at the bottom
Modify the theme Next config:
Add wordcount and reading time
Add following code to hexo config:
You can customize wordcount settings in theme Next’s config: