Hexo + Github博客搭建小白教程

Posted by Lucky Xue on 2019-07-01

本文主要分享通过Hexo Beantech主题和Github从零开始搭建博客之后,添加一些个性化功能以及处理主题自身bug的方法。
包括一些参考链接和Bean Tech提供的Markdown Demo写法。

Mac安装Node.js

1
2
3
4
5
6
7
8
brew link node # 查看
brew uninstall node # 卸载node
brew install node # 安装node
npm -v # 正确显示表示node安装成功
node -v # 正确显示表示node安装成功
brew list # brew list显示node

npm install -g cnpm --registry=https://registry.npm.taobao.org

个性化设置及Bug处理

超详细Hexo+Github博客搭建小白教程
Hexo博客踩坑
为博客添加Gitalk评论插件

注释BeanTech主题遗留的Disqus插件

通过上面步骤,我们为博客添加了Gittale评论插件,但是BeanTech主题原先自带的Disqus评论插件还在起作用,如果不进行修改就会在文章的最后显示下面的报错信息:

We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

1
2
3
4
5
6
7
8
9
将多说评论插件注释掉即可取消报错信息
vim _config.yml
# Disqus settings
# disqus_username: your-disqus-ID

# Duoshuo settings
# duoshuo_username: kaijun
# Share component is depend on Comment so we can NOT use share only.
# duoshuo_share: false # set to false if you want to use Comment without Sharing

删除BeanTech主题的CNAME文件

如果我们没有将自己的博客绑定域名,提交给Github仓库就会报下面的信息:

The page build completed successfully, but returned the following warning for themasterbranch: The CNAMEyoursite-urlis not properly formatted. See https://help.github.com/articles/troubleshooting-custom-domains/#github-repository-setup-errors for more information.

1
rm source/CNAME #删除CNAME文件即可取消报错信息

Markdown编写示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
> Ported Theme of [Hux Blog](https://github.com/Huxpro/huxpro.github.io), Thank [Huxpro](https://github.com/Huxpro) for designing such a flawless theme.
>
> This BeanTech theme created by [YuHsuan](http://beantech.org) modified from the original Porter [Kaijun](http://kaijun.rocks/hexo-theme-huxblog/)

# [Live Demo](http://beantech.org)
---
<img src="http://beantech.org/img/beantech-desktop.png" alt = "BeanTech Desktop" data-action="zoom" />

# Usage
---
I publish the whole project for your convenience, so you can just follow the instruction down below, then you can easily customiz your own blog!

Let's begin!!!

## Init
---
```bash
git clone https://github.com/YenYuHsuan/hexo-theme-beantech.git ./hexo-beantech
cd hexo-beantech
npm install
```

## Modify
---
Modify `_config.yml` file with your own info.
Especially the section:

### Deployment
Replace to your own repo!
```yml
deploy:
type: git
repo: https://github.com/<yourAccount>/<repo>
branch: <your-branch>
```

### Sidebar settings
Copy your avatar image to `<root>/img/` and modify the `_config.yml`:
```yml
sidebar: true # whether or not using Sidebar.
sidebar-about-description: "<your description>"
sidebar-avatar: img/<your avatar path>
```
and activate your personal widget you like
```yml
widgets: # here are widget you can use, you can comment out
- featured-tags
- short-about
- recent-posts
- friends-blog
- archive
- category
```
if you want to add sidebar widget, please add at `layout/_widget`.

### Signature Setup
Copy your signature image to `<root>/img/signature` and modify the `_config.yml`:
```yml
signature: true # show signature
signature-img: img/signature/<your-signature-ID>
```

### Go to top icon Setup
My icon is using iron man, you can change to your own icon at `css/image`.

### Post tag
You can decide to show post tags or not.
```yml
home_posts_tag: true
```
![home_posts_tag-true](home_posts_tag-true.png)
```yml
home_posts_tag: false
```
![home_posts_tag-false](home_posts_tag-false.png)

### Markdown render
My markdown render engine plugin is [hexo-renderer-markdown-it](https://github.com/celsomiranda/hexo-renderer-markdown-it).
```yml
# Markdown-it config
## Docs: https://github.com/celsomiranda/hexo-renderer-markdown-it/wiki
markdown:
render:
html: true
xhtmlOut: false
breaks: true
linkify: true
typographer: true
quotes: '“”‘’'
```
and if you want to change the header anchor 'ℬ', you can go to `layout/post.ejs` to change it.
```javascript
async("https://cdn.bootcss.com/anchor-js/1.1.1/anchor.min.js",function(){
anchors.options = {
visible: 'hover',
placement: 'left',
icon: // this is the header anchor "unicode" icon
};
```

## Hexo Basics
---
Some hexo command:
```bash
hexo new post "<post name>" # you can change post to another layout if you want
hexo clean && hexo generate # generate the static file
hexo server # run hexo in local environment
hexo deploy # hexo will push the static files automatically into the specific branch(gh-pages) of your repo!
```

# Have fun ^_^
---
<!-- Place this tag in your head or just before your close body tag. -->
<script async defer src="https://buttons.github.io/buttons.js"></script>
<!-- Place this tag where you want the button to render. -->

Please <a class="github-button" href="https://github.com/YenYuHsuan/hexo-theme-beantech" data-icon="octicon-star" aria-label="Star YenYuHsuan/hexo-theme-beantech on GitHub">Star</a> this Project if you like it! <a class="github-button" href="https://github.com/YenYuHsuan" aria-label="Follow @YenYuHsuan on GitHub">Follow</a> would also be appreciated!
Peace!

关注【憨才好运】微信公众号,了解更多精彩内容⬇️⬇️⬇️

continuous_deployment