环境准备

  • 使用centos7镜像创建一个虚拟机,也可以使用Windows直接安装
  • 以linux运行环境为例
1
2
[root@github ~]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core)

node.js

  • Node.js® 是一个基于 Chrome V8 引擎 的 JavaScript 运行时环境。
  • 中文官网: https://nodejs.org/zh-cn 下载长期支持版
  • 下载node-v16.18.1-linux-x64.tar.xz,最新版的nodejs,centos7不支持
  • 安装好了之后,输入 node -v ,如果显示的是下载的版本号那就是安装成功了。
1
2
3
4
5
6
7
8
9
10
11
12
[root@github ~]# tar xf  node-v16.18.1-linux-x64.tar.xz 
[root@github ~]# mv node-v16.18.1-linux-x64 /usr/local/nodejs

#配置环境变量
[root@github ~]# vim /etc/profile
#最后一行添加
export PATH=$PATH:/usr/local/nodejs/bin/


[root@github ~]# source /etc/profile
[root@github ~]# node -v
v16.18.1

Git

  • Git是一个开源的分布式版本控制系统,可以有效、高速地处理从很小到非常大的项目版本管理。 也是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件
  • Git 官网: https://git-scm.com/downloads
  • 安装好了之后,输入 git --version ,如果显示的 Git 的版本号那就是安装成功了。
  • 通过centos7自带的网络yum源安装就可以
1
2
3
[root@github ~]# yum install git -y
[root@github ~]# git --version
git version 1.8.3.1

注册GitHub账号

  • GitHub是国外网站,访问较慢,可通过安装插件提速
  • Edge浏览器安装油猴插件,搜索github 镜像加速访问脚本,开启脚本
  • 因为我们需要把 Hexo 站点托管到 GitHub 上,所以我们需要一个 GitHub 账号。
  • 打开 GitHub 官网,点击 Sigh up,然后输入邮箱、密码、用户名,最后一个按自己需求来写,通过人机验证后,点击 Create account 创建账号就ok了。

系统创建密钥

1
2
3
[root@github ~]# ssh-keygen #下面一直回车就可以
[root@github ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC13Le1D0N1nQhtsajjIJmxaMqevoE1Bvc2xwFiJi9AvANxodGMHickUVnviUAj/QtH5LNK4okgsiv8veSEkqjzXgCdX/QV6WjqRuhhrRYmIq2jkh+WBwVI3/ULPDG9SUJyRgcIqtcocjOVRbCTPtTXdxGEm2vQxyC+is1TvKbZhGge89r0bNS1VYDz3uv4gkbCTGVncAeW9JzSfNUmeewVtxUTwr8GAqdUc6gShYPGHVvsWlR/6AadnYFVhXx5g2EjJGGvohKTjpQ+B3knNRnhf49U0ULd/K7i0CNeOmhEC0CNGM9x9ENZzXYaWC4VZBZP/a1ELik+RsI4B/iauavv root@client

现在github加密了需要添加一些配置

1
2
3
4
5
6
7
8
9
10
vim ~/.ssh/config
Host github.com
Hostname ssh.github.com
Port 443
User git
IdentityFile ~/.ssh/id_rsa

# 测试
ssh -T git@github.com
Hi username! You've successfully authenticated...

为GitHub添加公钥

1

2

3

4

安装Hexo

  • hexo中文官网: https://hexo.io/zh-cn/
  • 安装好后 输入 hexo -v 输入版本号 代表安装成功了
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@github ~]# npm install hexo-cli -g
[root@github ~]# hexo -v
hexo-cli: 4.3.0
os: linux 3.10.0-1160.el7.x86_64 CentOS Linux 7 (Core)
node: 16.18.1
v8: 9.4.146.26-node.22
uv: 1.43.0
zlib: 1.2.11
brotli: 1.0.9
ares: 1.18.1
modules: 93
nghttp2: 1.47.0
napi: 8
llhttp: 6.0.10
openssl: 1.1.1q+quic
cldr: 41.0
icu: 71.1
tz: 2022b
unicode: 14.0
ngtcp2: 0.8.1
nghttp3: 0.7.0

创建 blog 文件夹

  • 所有操作需要在此文件下

输入 hexo init 初始化文件夹,接着输入 cd blog 将目录切换到 blog 文件夹里, 然后输入 npm install 就会在文件夹里生成一些需要的文件。

输入 hexo -h 查看帮助

hexo clean all清除缓存,当修改一些配置文件后需要执行此命令

hexo g 生成静态网页

hexo s 打开本地服务器来查看网页

hexo d推送到GitHub(建议在本地查看确认无误后再推送

1
2
3
[root@github ~]# hexo init blog     #blog为要创建文件夹的名字,可随意
[root@github ~]# cd blog/
[root@github blog]# npm install #完成初始化,生成一些文件

butterfly主题

  • 在blog目录中拉取稳定版
1
2
[root@github ~]# cd blog/
[root@github blog]# git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly
  • 修改_config.yml应用主题
1
2
3
4
5
6
[root@github blog]# vim _config.yml
theme: butterfly #改为主题名

#主题存放在theme目录中
[root@github blog]# ls themes/
butterfly landscape
  • 安装插件
  • 安装 pug 以及 stylus 的渲染器
1
[root@github blog]# npm install hexo-renderer-pug hexo-renderer-stylus --save

在 hexo 的根目录创建一个文件 _config.butterfly.yml,并把主题目录的 _config.yml 内容复制到 _config.butterfly.yml 去。( 注意: 复制的是主题的 _config.yml ,而不是hexo的 _config.yml)

1
[root@github blog]# cat themes/butterfly/_config.yml >> ./_config.butterfly.yml
  • 目录中可能存在一个除了_config.butterfly.yml_config.yml之外的一个_config.landscape.yml空文件
  • 不需要使用,如果存在就删除它

主题美化

参考大佬博客

推送GitHub

  • 先在GitHub上创建项目
  • 配置ssh key
  • 修改配置文件

创建项目

  • 创建格式:用户名.github.io(必须是GitHub的用户名)

5

6

进入以.github.io结尾的项目里

7

  • 推送
1
2
3
4
5
6
7
8
9
10
11
12
13
14
sh

[root@github blog]# vim _config.yml
deploy:
type: git
repo: git@github.com:**github.io.git #刚才复制的github仓库地址
branch: master #默认是master分支,还请自行查看

#推送
[root@github blog]# hexo d

#要是报错Deployer not found: git

#执行npm install hexo-deployer-git --save
  • 推送过一段时间即可访问
  • 项目名.github.io