0%

用Hexo搭建属于自己的免费博客

之前一直使用 hexo 和 next 的主题,后来做了一些自定义的修改,然后发现 hexo 和 next theme 官方都做了升级,我也跟着升级了。但升级的部分和我自定义修改的 layout 部分就产生冲突了。搞了很久,也没能修复,所以还是重新搭建一套吧,然后把再自定义部分添加上去。

安装 hexo-cli 客户端

根据官方文档,安装最新的 hexo-cli。

1
2
3
4
5
$ npm install hexo-cli -g

/usr/local/bin/hexo -> /usr/local/lib/node_modules/hexo-cli/bin/hexo
+ hexo-cli@3.1.0
added 27 packages from 12 contributors, removed 238 packages and updated 38 packages in 6.648s

搭建博客

初始化博客

创建一个你将用于放置博客系统的目录,然后在此目录下执行如下命令:

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
$ hexo init blog

INFO Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
Cloning into '/Users/simon/Development/workspace/blog'...
remote: Enumerating objects: 30, done.
remote: Counting objects: 100% (30/30), done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 161 (delta 12), reused 12 (delta 4), pack-reused 131
Receiving objects: 100% (161/161), 31.79 KiB | 5.00 KiB/s, done.
Resolving deltas: 100% (74/74), done.
Submodule 'themes/landscape' (https://github.com/hexojs/hexo-theme-landscape.git) registered for path 'themes/landscape'
Cloning into '/Users/simon/Development/workspace/blog/themes/landscape'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 1067 (delta 0), reused 0 (delta 0), pack-reused 1063
Receiving objects: 100% (1067/1067), 3.22 MiB | 3.00 KiB/s, done.
Resolving deltas: 100% (585/585), done.
Submodule path 'themes/landscape': checked out '73a23c51f8487cfcd7c6deec96ccc7543960d350'
INFO Install dependencies
yarn install v1.21.1
info No lockfile found.
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
[4/4] 🔨 Building fresh packages...
success Saved lockfile.
warning Your current version of Yarn is out of date. The latest version is "1.22.4", while you're on "1.21.1".
info To upgrade, run the following command:
$ curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
✨ Done in 5.11s.
INFO Start blogging with Hexo!

提示说 Yarn 版本低了,所以按提示方法更新了 Yarn。

安装依赖包

1
2
$ cd blog
$ npm install

本地运行博客

1
hexo s

就可以通过 http://localhost:4000/ 本地访问到博客了。

安装 Next 主题

主题各有所爱,我在这里演示安装 Next 主题。

1
2
$ cd blog
$ git clone https://github.com/theme-next/hexo-theme-next themes/next