Hexo部署个人博客到GitHub

准备工作

创建GitHub仓库

先在GitHub创建一个名字为username.github.io的项目,其中username替换成你自己的用户名

修改配置文件

打开_config.yml配置文件,找到deploy,修改成如下配置,其中username替换成你自己的用户名

1
2
3
4
5
6
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: git@github.com:username/username.github.io
branch: master

Click and drag to move

安装Deployer

部署前还需要安装Deployer部署器,否则会报如下错误

1
ERROR Deployer not found: git

Click and drag to move

输入如下命令安装hexo-deployer-git

1
$ npm install hexo-deployer-git --save

Click and drag to move

安装成功

1
2
3
4
5
6
npm WARN babel-eslint@10.0.1 requires a peer of eslint@>= 4.12.1 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ hexo-deployer-git@1.0.0
added 59 packages in 15.847s

Click and drag to move

Git设置user.email和user.name

本来以为准备工作已做完,直接运行$ hexo deploy部署,结果报如下错误

大致意思就是说要设置user.email和user.name

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
*** Please tell me who you are.

Run

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'Him@hongxiaoxin.(none)')
error: src refspec HEAD does not match any.
error: failed to push some refs to 'git@github.com:ghxiaoxiao/ghxiaoxiao.github.io'
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Error: Spawn failed
at ChildProcess.<anonymous> (d:\hexo\blog\node_modules\hexo-util\lib\spawn.js:52:19)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at ChildProcess.cp.emit (d:\hexo\blog\node_modules\cross-spawn\lib\enoent.js:40:29)
at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)

Click and drag to move

那就设置一下呗,其中email是你的GitHub绑定的邮箱,用户名是你的GitHub用户名

1
2
3
$ git config --global user.email "youremail@demo.com"

$ git config --global user.name "whatisyourname"

Click and drag to move

Deploy部署

首先进入hexo博客的根目录

1
$ cd /d/hexo/blog

Click and drag to move

然后运行

1
$ hexo deploy

Click and drag to move

或者

1
$ hexo d

Click and drag to move

然后就可以看到类似如下的输出,开始部署上传

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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
INFO  Deploying: git
INFO Clearing .deploy_git folder...
INFO Copying files from public folder...
INFO Copying files from extend dirs...
warning: LF will be replaced by CRLF in 2019/06/16/hello-world/index.html.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in archives/2019/06/index.html.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in archives/2019/index.html.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in archives/index.html.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in css/main.css.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in css/style.css.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in fancybox/helpers/jquery.fancybox-buttons.css.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in fancybox/helpers/jquery.fancybox-buttons.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in fancybox/helpers/jquery.fancybox-media.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in fancybox/helpers/jquery.fancybox-thumbs.css.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in fancybox/helpers/jquery.fancybox-thumbs.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in fancybox/jquery.fancybox.css.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in fancybox/jquery.fancybox.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in fancybox/jquery.fancybox.pack.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/affix.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/algolia-search.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/exturl.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/js.cookie.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/motion.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/next-boot.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/post-details.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/schemes/muse.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/schemes/pisces.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/script.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/scroll-cookie.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/scrollspy.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/utils.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in lib/font-awesome/css/font-awesome.css.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in lib/font-awesome/css/font-awesome.min.css.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in lib/jquery/index.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in lib/velocity/velocity.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in lib/velocity/velocity.min.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in lib/velocity/velocity.ui.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in lib/velocity/velocity.ui.min.js.
The file will have its original line endings in your working directory
[master (root-commit) a25c173] Site updated: 2019-06-17 19:14:40
72 files changed, 20010 insertions(+)
create mode 100644 2019/06/16/hello-world/index.html
create mode 100644 archives/2019/06/index.html
create mode 100644 archives/2019/index.html
create mode 100644 archives/index.html
create mode 100644 css/fonts/FontAwesome.otf
create mode 100644 css/fonts/fontawesome-webfont.eot
create mode 100644 css/fonts/fontawesome-webfont.svg
create mode 100644 css/fonts/fontawesome-webfont.ttf
create mode 100644 css/fonts/fontawesome-webfont.woff
create mode 100644 css/images/banner.jpg
create mode 100644 css/main.css
create mode 100644 css/style.css
create mode 100644 fancybox/blank.gif
create mode 100644 fancybox/fancybox_loading.gif
create mode 100644 fancybox/fancybox_loading@2x.gif
create mode 100644 fancybox/fancybox_overlay.png
create mode 100644 fancybox/fancybox_sprite.png
create mode 100644 fancybox/fancybox_sprite@2x.png
create mode 100644 fancybox/helpers/fancybox_buttons.png
create mode 100644 fancybox/helpers/jquery.fancybox-buttons.css
create mode 100644 fancybox/helpers/jquery.fancybox-buttons.js
create mode 100644 fancybox/helpers/jquery.fancybox-media.js
create mode 100644 fancybox/helpers/jquery.fancybox-thumbs.css
create mode 100644 fancybox/helpers/jquery.fancybox-thumbs.js
create mode 100644 fancybox/jquery.fancybox.css
create mode 100644 fancybox/jquery.fancybox.js
create mode 100644 fancybox/jquery.fancybox.pack.js
create mode 100644 images/algolia_logo.svg
create mode 100644 images/apple-touch-icon-next.png
create mode 100644 images/avatar.gif
create mode 100644 images/cc-by-nc-nd.svg
create mode 100644 images/cc-by-nc-sa.svg
create mode 100644 images/cc-by-nc.svg
create mode 100644 images/cc-by-nd.svg
create mode 100644 images/cc-by-sa.svg
create mode 100644 images/cc-by.svg
create mode 100644 images/cc-zero.svg
create mode 100644 images/favicon-16x16-next.png
create mode 100644 images/favicon-32x32-next.png
create mode 100644 images/loading.gif
create mode 100644 images/logo.svg
create mode 100644 images/placeholder.gif
create mode 100644 images/quote-l.svg
create mode 100644 images/quote-r.svg
create mode 100644 images/searchicon.png
create mode 100644 index.html
create mode 100644 js/affix.js
create mode 100644 js/algolia-search.js
create mode 100644 js/exturl.js
create mode 100644 js/js.cookie.js
create mode 100644 js/motion.js
create mode 100644 js/next-boot.js
create mode 100644 js/post-details.js
create mode 100644 js/schemes/muse.js
create mode 100644 js/schemes/pisces.js
create mode 100644 js/script.js
create mode 100644 js/scroll-cookie.js
create mode 100644 js/scrollspy.js
create mode 100644 js/utils.js
create mode 100644 lib/font-awesome/HELP-US-OUT.txt
create mode 100644 lib/font-awesome/bower.json
create mode 100644 lib/font-awesome/css/font-awesome.css
create mode 100644 lib/font-awesome/css/font-awesome.css.map
create mode 100644 lib/font-awesome/css/font-awesome.min.css
create mode 100644 lib/font-awesome/fonts/fontawesome-webfont.eot
create mode 100644 lib/font-awesome/fonts/fontawesome-webfont.woff
create mode 100644 lib/font-awesome/fonts/fontawesome-webfont.woff2
create mode 100644 lib/jquery/index.js
create mode 100644 lib/velocity/velocity.js
create mode 100644 lib/velocity/velocity.min.js
create mode 100644 lib/velocity/velocity.ui.js
create mode 100644 lib/velocity/velocity.ui.min.js
Enumerating objects: 94, done.
Counting objects: 100% (94/94), done.
Delta compression using up to 4 threads
Compressing objects: 100% (85/85), done.
Writing objects: 100% (94/94), 941.35 KiB | 4.32 MiB/s, done.
Total 94 (delta 9), reused 0 (delta 0)
remote: Resolving deltas: 100% (9/9), done.
To github.com:ghxiaoxiao/ghxiaoxiao.github.io
+ 7e2ebc3...a25c173 HEAD -> master (forced update)
Branch 'master' set up to track remote branch 'master' from 'git@github.com:ghxiaoxiao/ghxiaoxiao.github.io'.
[32mINFO [39m Deploy done: [35mgit[39m

Click and drag to move

浏览博客

大功告成,一切顺利的话可以直接在浏览器输入https://username.github.io/浏览博客

我的博客地址是https://ghxiaoxiao.github.io/,欢迎参观

参考