hexo基础使用

hexo基础使用

创建新的文章,默认是post

1
hexo new [layout] <title>

常用参数

参数描述默认值
layout布局config.default_layout
title标题文章的文件名
date建立日期文件建立日期
updated更新日期文件更新日期
comments开启文章的评论功能true
tags标签(不适用于分页)
categories分类(不适用于分页)
permalink覆盖文章网址

分类标签写法:

1
2
3
4
5
6
tags:
- PS3
- Games
categories:
- Diary
- Life

多分类写法

1
2
3
4
categories:
- [Diary, PlayStation]
- [Diary, Games]
- [Life]

此时这篇文章同时包括三个分类: PlayStation 和 Games 分别都是父分类 Diary 的子分类,同时 Life 是一个没有子分类的分类。

引用图片

1
2
3
![](example.jpg)
or
<img src="/2020/01/02/foo/image.jpg">

部署Github

私有 Repository

下面的指示基于 一键部署 编写。

  1. 安装 hexo-deployer-git.
1
cnmp install hexo-deployer-git
  1. _config.yml(如果有已存在的请删除)添加如下配置:
1
2
3
4
5
deploy:
type: git
repo: https://github.com/<username>/<project>
# example, https://github.com/hexojs/hexojs.github.io
branch: gh-pages
  1. 运行 hexo clean && hexo deploy
  2. 查看 username.github.io 上的网页是否部署成功。

配置永久链接

变量描述
:year文章的发表年份(4 位数)
:month文章的发表月份(2 位数)
:i_month文章的发表月份(去掉开头的零)
:day文章的发表日期 (2 位数)
:i_day文章的发表日期(去掉开头的零)
:hour文章发表时的小时 (2 位数)
:minute文章发表时的分钟 (2 位数)
:second文章发表时的秒钟 (2 位数)
:title文件名称 (relative to “source/_posts/“ folder)
:name文件名称
:post_title文章标题
:id文章 ID (not persistent across cache reset)
:category分类。如果文章没有分类,则是 default_category 配置信息。
:hashSHA1 hash of filename (same as :title) and date (12-hexadecimal)

您可在 permalink_defaults 参数下调整永久链接中各变量的默认值:

1
2
permalink_defaults:
lang: en

示例

1
2
3
4
5
source/_posts/hello-world.mdtitle: Hello World
date: 2013-07-14 17:01:34
categories:
- foo
- bar
参数结果
:year/:month/:day/:title/2013/07/14/hello-world/
:year-:month-:day-:title.html2013-07-14-hello-world.html
:category/:title/foo/bar/hello-world/
:title-:hash/hello-world-a2c8ac003b43/
1
2
3
4
5
source/_posts/lorem/hello-world.mdtitle: Hello World
date: 2013-07-14 17:01:34
categories:
- foo
- bar
参数结果
:year/:month/:day/:title/2013/07/14/lorem/hello-world/
:year/:month/:day/:name/2013/07/14/hello-world/

多语种支持

若要建立一个多语种的网站,您可修改 new_post_namepermalink 参数,如下:

1
2
new_post_name: :lang/:title.md
permalink: :lang/:title/

当您建立新文章时,文章会被储存到:

1
2
$ hexo new "Hello World" --lang tw
# => source/_posts/tw/Hello-World.md

而网址会是:

1
http://localhost:4000/tw/hello-world/

目录介绍

1
2
3
4
5
6
.
├── _config.yml #主题的配置文件
├── languages #语言文件夹
├── layout #布局文件夹
├── scripts #脚本文件夹
└── source #资源文件夹

开启代码高亮

1
2
3
4
5
6
7
8
9
10
11
12
13
# _config.yml
highlight:
enable: true
auto_detect: false
line_number: true
line_threshold: 0
tab_replace: ' '
exclude_languages:
- example
wrap: true
hljs: false
prismjs:
enable: false