我想,每个程序员都希望有一个专属于自己的博客网站,用来分享知识,记录成长,督促形成产出。

搭建博客的方式我已知的有以下几种:

  • 自己从头到尾手撸一个博客网站,这里安利我们的姜同学写博客的小姜
  • 使用WordPress搭建
  • 使用hexo搭建

在分别尝试使用WordPress和hexo搭建博客网站之后,基于hexo简单易搭建,轻量的特点,最终基于hexo搭建了属于自己的博客。

相关资料可在hexo官网地址 中获得


快速搭建

我的博客搭建在阿里云云服务器中,没有自己的服务器的小伙伴可参考搭建git托管的hexo博客

安装基础环境

安装nodejs

由于hexo基础环境需要Node.js和Git,需要先安装Node.js

1
yum -y install nodejs #安装npm

验证nodejs环境是否安装正常

1
node -v #显示nodejs版本号

出现版本nodejs版本号即成功

安装hexo

1
npm install -g hexo-cli #安装hexo-cli

hexo butterfly主题

hexo默认主题不够美观,butterfly主题简约大气
butterfly主题官网

安装butterfly主题

安装核心组件

1
npm install hexo-renderer-pug hexo-renderer-stylus --save

安装butterfly主题

1
npm i hexo-theme-butterfly

配置hexo和butterfly主题

butterfly主题相关配置可见官方配置文档
官方配置页面直达

以下为我的配置,可参考

_config.yml配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Site
title: 何知令の博客
subtitle: ''
description: ''
keywords:
author: 何知令
language: zh-CN
timezone: ''
email: 1605489109@qq.com

# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: http://hezhiling.cn
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: butterfly

_config.butterfly.yml配置文件(改动部分)

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
# Site
title: 何知令の博客
subtitle: ''
description: ''
keywords:
author: 何知令
language: zh-CN
timezone: ''
email: 1605489109@qq.com

# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: http://hezhiling.cn

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: butterfly

# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: ''
menu:
首页: / || fas fa-home
时间轴: /archives/ || fas fa-archive
标签: /tags/ || fas fa-tags
分类: /categories/ || fas fa-folder-open
友链: /link/ || fas fa-link
关于: /about/ || fas fa-heart

#菜单栏
nav:
fixed: true #是否固定状态栏
display_title: false #是否显示网站标题

#代码块配置
highlight_theme: light #代码高亮主题
highlight_copy: true #代码支持复制
highlight_shrink: false #false代码框展开,有'>'点击按钮,true全部代码框不展开,需点击>打开,none不显示>按钮
highlight_height_limit: false #代码高度限制

#社交图标
social:
fab fa-github: https://github.com/hezhiling123 || Github
fas fa-envelope: mailto:1605489109@qq.com || Email

#顶部图
#index_img: /img/saber王座.jpg
index_img: /img/saber王座-middle.jpg
default_top_img: /img/saber王座-middle.jpg
top_img: false

#头像
avatar:
img: /img/avatar.jpg

几个要点

  1. _config.yml中主题theme得设置为butterfly才会使butterfly主题生效
  2. _config.yml中的url地址用于分享文章链接等拼接使用,将其改为对应的nginx配置
  3. 这两个文件中有我自己的配置部分,需要将其改为你自己的文件地址和配置。