工具08:Hexo博客搭建过程

本博客采用Hexo搭建在Github上,Hexo是基于Node.js的博客框架,并配合大量的主题,定制个性化的博客。写文章采用Markdown语法,简单快速,再也不必为各种HTML样式而烦恼。
本文记录下搭建的过程。

环境

操作系统:CentOS 7。
必备软件:文本编辑器,Git

Node.js安装

执行如下命令。

1
2
3
# curl --silent --location https://rpm.nodesource.com/setup | bash -
# yum makecache fast
# yum install -y nodejs

Hexo安装

执行如下命令。

1
2
3
# npm install -g hexo-cli --https-proxy=http://192.168.80.2:808 \
--proxy=http://192.168.80.2:808 \
--registry=https://registry.npm.taobao.org

参数--https-proxy--https-proxy是Http代理设置;--registry是从某宝的库安装,原因是Nodejs的官方库被墙了,你懂的。
执行过程的时间比较长,需耐心等待。

博客初始化

执行如下命令。

1
2
3
4
5
6
$ mkdir blog
$ cd blog
$ hexo init
$ npm install --https-proxy=http://192.168.80.2:808 \
--proxy=http://192.168.80.2:808 \
--registry=https://registry.npm.taobao.org

安装插件

我只是用四个插件,hexo-deployer-git是发布到Git托管服务器上的插件,hexo-generator-feed是博客RSS的插件,hexo-generator-sitemap是给Google搜索使用的插件,hexo-generator-search是内部搜索插件。(2017.02.01更新hexo-generator-search)
执行如下命令。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ npm install hexo-deployer-git --save \
--https-proxy=http://192.168.80.2:808 \
--proxy=http://192.168.80.2:808 \
--registry=https://registry.npm.taobao.org

$ npm install hexo-generator-feed --save \
--https-proxy=http://192.168.80.2:808 \
--proxy=http://192.168.80.2:808 \
--registry=https://registry.npm.taobao.org

$ npm install hexo-generator-sitemap --save \
--https-proxy=http://192.168.80.2:808 \
--proxy=http://192.168.80.2:808 \
--registry=https://registry.npm.taobao.org

$ npm install hexo-generator-search --save \
--https-proxy=http://192.168.80.2:808 \
--proxy=http://192.168.80.2:808 \
--registry=https://registry.npm.taobao.org

Hexo 常用命令

执行hexo help可调出命令参考。而hexo命令支持简写。即s可代表servercl代表clean
常用命令如下。

命令 含义
hexo cl 清空生产的文件和缓存
hexo n 生成标题为的文章
hexo g 生成静态网页
hexo d 部署到网站
hexo d -g 生成静态网页并部署到网站
hexo s 开启Web服务
–debug 开启调试模式

全局配置

修改博客目录下_config.yml文档,请遵循YAML语言规范,尤其要注意:后必须有空格
修改的参数记录如下:

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
# Site
title: XXX
subtitle: XXX
description: XXX
author: XXX
language: XXX

# URL
url: XXX

# Extensions
theme: XXX
stylus:
compress: true

plugins:
- hexo-generator-feed
- hexo-generator-sitemap

feed:
type: atom #feed 类型 (atom/rss2)
path: atom.xml #rss 路径
limit: 20 #在 rss 中最多生成的文章数(0显示所有)

sitemap:
path: sitemap.xml

# Deployment
deploy:
type: git
repo: XXX

# Local Search
search:
path: search.xml
field: post
format: html
limit: 10000

基本过程就是这样,执行hexo s后开启浏览器访问http://IP:4000就可看到博客的样貌了。(2017.02.21更新Local Search配置)

(2017.02.21更新) 若主题支持本地搜索,那么修改主题的配置文件。

1
2
3
# Local search
local_search:
enable: true

参考文档:
Hexo Docs
Hexo系列教程

如果本文对你有所帮助,请小额赞助
~~ EOF ~~