_config.yml 文件中修改大部分的配置。点击 下载 Hexo 配置文件中文注释版。
阅前说明:如果你安装了 Hexo 主题,那么大多数设置都将在主题配置文件 _config.[theme].yml 中进行操作,因为主题配置文件的优先级高于 Hexo 配置文件,因此下面关于 Hexo 配置文件的介绍大多可不必理会,我将会在最后介绍几个常用的 Hexo 配置文件的设置。

Hexo 配置文件详解

1、网站(Site) ⚓︎

1
2
3
4
5
6
7
title: Hexo # 网站标题
subtitle: '' # 网站副标题
description: '' # 网站描述
keywords: # 网站的关键词
author: John Doe # 作者名字
language: en # 网站使用的语言
timezone: '' # 网站时区,国内建议选择 Asia/Shanghai

2、网址(URL) ⚓︎

1
2
3
4
5
6
7
url: http://example.com # 网站地址
root: / # 网站根目录
permalink: :year/:month/:day/:title/ # 文章的永久链接格式
permalink_defaults: # 永久链接中各部分的默认值
pretty_urls: # 改写 permalink 的值来美化 URL
trailing_index: true # 是否在永久链接中保留尾部的 index.html,设置为 false 时去除
trailing_html: true # 是否在永久链接中保留尾部的 .html,设置为 false 时去除,对尾部的 index.html 无效

3、目录(Directory) ⚓︎

1
2
3
4
5
6
7
8
9
10
11
12
13
source_dir: source # Source 文件夹存储内容的位置
public_dir: public # Public 文件夹生成静态站点的位置
tag_dir: tags # 标签文件夹
archive_dir: archives # 归档文件夹
category_dir: categories # 分类文件夹
code_dir: downloads/code # Include code 文件夹,source_dir 下的子目录
i18n_dir: :lang # 国际化(i18n)文件夹
skip_render: # 跳过渲染
# - "_posts/test-post.md" # 跳过单个文件,格式:path/file
# - "_posts/*" # 跳过指定目录下所有文件,格式:dir/*
# - "_posts/**" # 跳过整个目录(包含所有子目录/文件),格式:dir/**
# - "*.js" # 跳过所有 js 文件,格式:*.ext
# - "scripts/*.js" # 跳过 scripts 目录下所有 js 文件,格式:dir/*.ext

4、文章(Writing) ⚓︎

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
new_post_name: :title.md # 新文章的文件名称
default_layout: post # 预设布局
titlecase: false # 把标题转换为 title case
external_link:
enable: true # 在新标签中打开链接
field: site # 对整个网站(site)生效或仅对文章(post)生效
exclude: '' # 需要排除的域名
filename_case: 0 # 值为 1,文件名转换为小写形式;值为 2,文件名转换为大写形式
render_drafts: false # 显示草稿
post_asset_folder: false # 启用资源文件夹
relative_link: false # 把链接改为与根目录的相对位址
future: true # 显示未来的文章
syntax_highlighter: highlight.js # 语法高亮工具
highlight:
line_number: true # 代码的行号显示
auto_detect: false # 自动检测代码语言
tab_replace: '' # 将代码中的 Tab 符替换为空字符串
wrap: true # 开启代码的包裹容器
hljs: false # 禁用 highlight.js 自带的 hljs-* 类名
prismjs:
preprocess: true # 代码的预处理
line_number: true # 代码的行号显示
tab_replace: '' # 将代码中的 Tab 符替换为空字符串

5、首页设置(Home page setting) ⚓︎

1
2
3
4
index_generator: # 生成帖子归档
path: '' # 博客索引页面的根路径
per_page: 10 # 每页显示帖子数
order_by: -date # 帖子排列顺序
  • 此处 index_generator.per_page: 10 为首页专属分页,仅控制网站首页(主页) 每页展示多少篇文章,优先级高于 per_page: 10

6、分类 & 标签(Category & Tag) ⚓︎

1
2
3
default_category: uncategorized # 默认分类
category_map: # 分类别名
tag_map: # 标签别名

7、Meta generator 标签(Metadata elements) ⚓︎

1
meta_generator: true # 是否开启生成 <meta name="generator" ...> 标签

8、日期 / 时间格式(Date / Time format) ⚓︎

1
2
3
date_format: YYYY-MM-DD # 日期格式
time_format: HH:mm:ss # 时间格式
updated_option: 'mtime' # 当 Front Matter 中没有指定 updated 时 updated 的取值

9、分页(Pagination) ⚓︎

1
2
per_page: 10 # 每页显示的帖子数
pagination_dir: page # URL 格式
  • 此处 per_page: 10 为全站通用默认分页,作用于分类页、标签页、归档页、搜索结果等所有分页页面。

10、包括或不包括目录和文件(Include / Exclude file) ⚓︎

1
2
3
include:  # 包含隐藏文件
exclude: # 排除文件或文件夹
ignore: # 忽略文件/文件夹

11、扩展(Extensions) ⚓︎

1
theme: landscape # 当前主题名称

12、部署(Deployment) ⚓︎

部署配置见:部署到 GitHub Pages

1
2
3
4
5
6
deploy:
type: git
repo: <repository url> # https://github.com/huyongshuang/huyongshuang.github.io.git
branch: [branch]
token: [token]
message: [message]

常用 Hexo 配置 ⚓︎

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
# 网站使用的语言,一般为中文
language: zh-CN

# 使用以下配置,可以在保留生成的 HTML 文件后缀的情况下,去除永久链接中尾部的 .html 和 index.html
permalink: :year/:month/:day/:title.html
pretty_urls:
trailing_index: false
trailing_html: false

# 跳过渲染
skip_render:
- "_posts/test-post.md" # 跳过单个文件,格式:path/file
- "_posts/*" # 跳过指定目录下所有文件,格式:dir/*
- "_posts/**" # 跳过整个目录(包含所有子目录/文件),格式:dir/**
- "*.js" # 跳过所有 js 文件,格式:*.ext
- "scripts/*.js" # 跳过 scripts 目录下所有 js 文件,格式:dir/*.ext

# 如果想要更有规律地提供图片和其他资源以及想要将他们的资源分布在各个文章上,请开启下面的设置,执行命令 hexo new post Blog 后在 source/_posts 文件夹里生成了和文章同名的资源目录
post_asset_folder: true

# 如果你安装了 Hexo 主题,当你设置完主题配置后,需要开启下面的设置,才会读取你的主题的配置
theme: redefine

# 使用 hexo-deployer-git 一键部署时,需要进行以下配置
deploy:
type: git
repo: <repository url> # https://github.com/huyongshuang/huyongshuang.github.io.git
branch: [branch]
token: [token]
message: [message]