Hexo搭建个人博客

准备工作

  • 安装Node.js
  • 安装Git

安装hexo

命令:npm install hexo-cli -g

1
2
3
4
5
6
7
8
D:\>cd D:/hexo
D:\hexo>npm install hexo-cli -g
C:\Users\Him\AppData\Roaming\npm\hexo -> C:\Users\Him\AppData\Roaming\npm\node_modules\hexo-cli\bin\hexo
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\hexo-cli\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-cli@2.0.0
added 189 packages in 48.578s

Click and drag to move

创建博客项目

命令:hexo init blog

命令最后的blog为项目名,也可以设置自己喜欢的名字

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
D:\hexo>hexo init blog
INFO Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
Cloning into 'D:\hexo\blog'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 74 (delta 2), reused 4 (delta 2), pack-reused 68
Unpacking objects: 100% (74/74), done.
Submodule 'themes/landscape' (https://github.com/hexojs/hexo-theme-landscape.git) registered for path 'themes/landscape'
Cloning into 'D:/hexo/blog/themes/landscape'...
remote: Enumerating objects: 21, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 917 (delta 4), reused 10 (delta 0), pack-reused 896
Receiving objects: 100% (917/917), 2.56 MiB | 682.00 KiB/s, done.
Resolving deltas: 100% (484/484), done.
Submodule path 'themes/landscape': checked out '73a23c51f8487cfcd7c6deec96ccc7543960d350'
[32mINFO [39m Install dependencies
npm WARN deprecated core-js@1.2.7: core-js@<2.6.8 is no longer maintained. Please, upgrade to core-js@3 or at least to actual version of core-js@2.
npm notice created a lockfile as package-lock.json. You should commit this file.
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"})

added 420 packages in 43.278s
INFO Start blogging with Hexo!

Click and drag to move

安装博客项目

以上命令执行成功后会创建一个blog文件夹,进入该文件夹,执行install安装命令

1
2
3
4
5
6
7
D:\hexo>cd blog

D:\hexo\blog>npm install
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"})

up to date in 5.243s

Click and drag to move

打包生成

命令:hexo g

或者命令:hexo generate

会打包生成静态文件

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
D:\hexo\blog>hexo g
INFO Start processing
INFO Files loaded in 540 ms
INFO Generated: index.html
INFO Generated: fancybox/jquery.fancybox.css
INFO Generated: fancybox/fancybox_overlay.png
INFO Generated: archives/index.html
INFO Generated: archives/2019/06/index.html
INFO Generated: fancybox/blank.gif
INFO Generated: fancybox/fancybox_loading@2x.gif
INFO Generated: fancybox/fancybox_loading.gif
INFO Generated: fancybox/fancybox_sprite.png
INFO Generated: fancybox/fancybox_sprite@2x.png
INFO Generated: fancybox/jquery.fancybox.pack.js
INFO Generated: fancybox/jquery.fancybox.js
INFO Generated: archives/2019/index.html
INFO Generated: fancybox/helpers/fancybox_buttons.png
INFO Generated: css/fonts/FontAwesome.otf
INFO Generated: css/fonts/fontawesome-webfont.woff
INFO Generated: fancybox/helpers/jquery.fancybox-buttons.css
INFO Generated: fancybox/helpers/jquery.fancybox-buttons.js
INFO Generated: fancybox/helpers/jquery.fancybox-thumbs.js
INFO Generated: css/fonts/fontawesome-webfont.eot
INFO Generated: fancybox/helpers/jquery.fancybox-media.js
INFO Generated: js/script.js
INFO Generated: fancybox/helpers/jquery.fancybox-thumbs.css
INFO Generated: css/style.css
INFO Generated: css/fonts/fontawesome-webfont.ttf
INFO Generated: css/images/banner.jpg
INFO Generated: css/fonts/fontawesome-webfont.svg
INFO Generated: 2019/06/16/hello-world/index.html
INFO 28 files generated in 907 ms

Click and drag to move

开启服务

命令:hexo s

或者命令:hexo server

1
2
3
D:\hexo\blog>hexo s
INFO Start processing
INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.

Click and drag to move

发开博客服务成功后,在浏览器输入http://localhost:4000回车,就可以在本地浏览博客了

关闭服务

在命令行中输入命令:Ctrl+C

再输入Y,回车确认退出服务

1
2
3
4
INFO  Have a nice day
Terminate batch job (Y/N)? Y

D:\hexo\blog>

Click and drag to move