Hexo

Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown 解析文章,在几秒内,即可利用靓丽的主题生成静态网页。

安装

安装Node.js

安装完成后可通过以下命名查询版本和安装目标路径信息:

1
2
$ node -v
$ where node

安装Git

安装完成后可通过以下命名查询版本和安装目标路径信息:

1
2
$ git --version
$ where git

安装Hexo

安装完成后可通过以下命名查询版本和安装目标路径信息:

1
2
3
4
$ where npm
$ npm install -g hexo-cli
$ hexo -v
$ where hexo

建站

安装 Hexo 完成后,请执行下列命令,Hexo 将会在指定文件夹中新建所需要的文件。

1
2
3
4
$ mkdir your-hexo-site
$ cd your-hexo-site
$ hexo init
$ npm install

新建完成后,指定文件夹的目录如下:

1
2
3
4
5
6
7
8
site
+-- _config.yml ##网站的配置信息
+-- package.json ##应用程序的信息
+-- scaffolds ##模版文件夹
+-- source ##资源文件夹
| +-- _drafts ##draft布局对应的路径
| +-- _posts ##post布局对应的路径
+-- themes ##主题文件夹

测试

1
2
3
$ cd your-hexo-site
$ hexo generate
$ hexo server

部署

Hexo 生成的所有文件都放在 public 文件夹中,您可以将它们复制到您喜欢的地方。

Git

hexo-deployer-git

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

主配置文件

1
2
3
4
5
deploy:
type: git
repo: git@github.com:lugavin/lugavin.github.io.git
branch: master
#message: [message]

GitHub Actions配置

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
name: Build and Deploy
on:
push:
branches:
- master
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# See https://github.com/actions/checkout
- name: Checkout
uses: actions/checkout@v1

- name: Setup
env:
# [PRIVATE KEY](https://github.com/lugavin/blog/settings/secrets)
# [PUBLIC KEY](https://github.com/settings/keys)
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
run: |
mkdir -p ~/.ssh/
echo "$ACCESS_TOKEN" | tr -d '\r' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
git config --global user.name 'lugavin'
git config --global user.email 'lugavin@outlook.com'
- name: Build
run: |
npm install
npm run clean
npm run build
- name: Deploy
run: |
npm run deploy

插件

hexo-all-minifier

1
$ npm install hexo-all-minifier --save

安装完成后,修改站点配置文件_config.yml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
html_minifier:
enable: false
ignore_error: false
exclude:
css_minifier:
enable: true
exclude:
- '*.min.css'
js_minifier:
enable: true
mangle: true
output:
compress:
exclude:
- '*.min.js'
image_minifier:
enable: true
interlaced: false
multipass: false
optimizationLevel: 2
pngquant: false
progressive: false

hexo-generator-searchdb

1
$ npm install hexo-generator-searchdb --save

安装完成后,修改主题配置文件_config.yml:

1
2
3
4
5
search:
path: search.xml
field: post
content: true
format: html

hexo-generator-feed

1
$ npm install hexo-generator-feed --save

安装完成后,修改主题配置文件_config.yml:

1
rss: atom.xml

hexo-generator-sitemap

1
$ npm install hexo-generator-sitemap --save

安装完成后,修改主题配置文件_config.yml:

1
2
3
menu:
home: /
sitemap: /sitemap.xml

主题配置

标签

  1. 新建页面

    1
    2
    $ cd your-hexo-site
    $ hexo new page tags
  2. 设置页面类型
    执行上述命令后将会自动创建source/tags/index.md文件,编辑该文件,将页面的类型设置为 tags ,主题将自动为这个页面显示标签云:

    1
    2
    3
    4
    5
    ---
    title: tags
    date: 2017-05-18 07:49:30
    type: "tags"
    ---
  3. 修改菜单
    编辑主题配置文件,添加 tags 到 menu 中:

    1
    2
    3
    4
    menu:
    home: /
    archives: /archives
    tags: /tags

分类

  1. 新建页面

    1
    2
    $ cd your-hexo-site
    $ hexo new page categories
  2. 设置页面类型
    执行上述命令后将会自动创建source/categories/index.md文件,编辑该文件,将页面的 type 设置为 categories ,主题将自动为这个页面显示分类:

    1
    2
    3
    4
    5
    ---
    title: categories
    date: 2017-05-18 07:52:11
    type: "categories"
    ---
  3. 修改菜单
    编辑主题配置文件,添加 categories 到 menu 中:

    1
    2
    3
    4
    menu:
    home: /
    archives: /archives
    categories: /categories

关于我

执行以下命令后将会自动创建source/about/index.md文件,可编辑该文件录入作者相关信息。

1
2
$ cd your-hexo-site
$ hexo new page about