Hexo 博客搭建记录

记录本博客搭建历程

基本框架

Hexo 建站

https://hexo.io/zh-cn/docs/setup.html

1
2
3
$ hexo init hexo_xblog
$ cd hexo_xblog/
$ npm install

使用 NexT 主题

http://theme-next.iissnan.com/getting-started.html

下载

1
$ git clone https://github.com/iissnan/hexo-theme-next themes/next

启用

打开 站点配置文件, 找到 theme 字段,并将其值更改为 next。

1
$ vim _config.yml
1
theme: next

本地运行

1
hexo s --debug

next 主题提供了多个样式以供选择,我使用了 Mist 样式:

1
vim themes/next/_config.yml

1
scheme: Mist

部署到 github.io

https://hexo.io/zh-cn/docs/deployment.html

在站点配置文件中配置 deploy 字段

1
$ vim _config.yml
1
2
3
4
5
deploy:
type: git
repo: git@github.com:shenxgan/shenxgan.github.io.git
branch: master
message:

安装 hexo-deployer-git

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

部署

1
$ hexo deploy

如果是重新部署,则最好先进行 clean,不然修改了配置后部署并不会生效。

1
$ hexo clean; hexo deploy

集成第三方服务

http://theme-next.iissnan.com/third-party-services.html

搜索

个人觉得 Local Search 就比较好用。具体使用方法官网已经写着很明细了,照着弄就行。
http://theme-next.iissnan.com/third-party-services.html#local-search

评论

选用的是 gitment 作为博客的评论系统。
gitment 使用 github 的 issue 来达到评论的目的,个人觉得非常不错。

因为在 next 主题的配置文件中发现了 gitment, 说明 next 主题已经直接支持 gitment 了。
所以没有再使用 gitment 作者这篇文章中介绍的方式来使用 gitment;而是直接在 next 主题配置文件中配置相应的参数即可。

安装 gitment

1
$ npm install --save gitment

启动 gitment 并添加配置

1
vim themes/next/_config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
gitment:
enable: true
mint: true
count: true
lazy: false
cleanly: false
language:
github_user: shenxgan
github_repo: shenxgan.github.io
client_id: 5e1xxxxxxxxxx87c1
client_secret: 1c7xxxxxxxxxxxxxxxxxxx409b
proxy_gateway:
redirect_protocol:

千万注意不要将 github_user 和 github_repo 弄错

我在刚开始的时候弄错了,事情大概是这样的:

  1. github_user 以为是 github 中用户的 id,还使用这个 api (https://api.github.com/users/shenxgan) 来获取自己的 id 来着。
  2. 当时一直以为是 github_repo 的问题,因为刚开始我写这个值的时候是带着 git 的;后来查到这个 issue 中写的,又认为值应该是 shenxgan … 一直都不对

还好,最终搞了两天终于弄好了 (*^_^*)

client_id 和 client_secret 可参照 gitment 作者写的:https://imsun.net/posts/gitment-introduction/#1-注册-OAuth-Application

修改主题样式

其它的一些小改动

首页中显示“阅读全文”

在文章中添加 <!-- more --> 来精确控制摘要内容;会将 <!-- more --> 之前的内容定位为摘要;且在阅读文章的时候并不会显示这个标签
还有一个优点是可以保留样式