Hexo博客的配置文件_config.yml的说明

Hexo构建博客还是比较容易的,在完成博客搭建之后,作为博客最重要的组成部分,其实就是博客根目录下的 _config.yml 文件,想来大家都一定很熟悉,主要是对Hexo的配置以及站点的相关配置,下面开始进行分段详细的说明

1.站点配置

这个主要是网站的基本配置,需要按照自己的网站设置来填写。

1
2
3
4
5
6
7
8
# Site
title: # 网站标题
subtitle: # 网站子标题
description: # 网站描述
keywords: # 网站关键词
author: # 网站作者,也就是您的名字
language: # 网站使用的语言,这需要注意:看你的主题文件下的language包下有什么语言包就些什么。后面详细说明!
timezone: # 网站时区。Hexo 预设使用您电脑的时区。

2.网址配置

这个地方一般根据情况修改 url 和 root 即可。

1
2
3
4
5
6
7
8
# URL
url: # 博客网址
root: / # 网站根目录
permalink: # 文章的永久链接格式
permalink_defaults: # 永久链接中各部分的默认值
pretty_urls:
trailing_index: true # Set to false to remove trailing 'index.html' from permalinks
trailing_html: true # Set to false to remove trailing '.html' from permalinks

3.目录配置

这个地方一般直接取默认值不用修改。

1
2
3
4
5
6
7
8
9
# Directory                # 目录
source_dir: source # 资源文件夹,这个文件夹用来存放内容,例如我们用markdown编写的博文
public_dir: public # 公共文件夹,这个文件夹用于存放生成的静态博客文件。
tag_dir: tags # 标签文件夹
archive_dir: archives # 归档文件夹
category_dir: categories # 分类文件夹
code_dir: downloads/code # Include code 文件夹
i18n_dir: :lang # 国际化(i18n)文件夹
skip_render: # 跳过指定文件的渲染,您可使用 glob 来配置路径。

4.文章配置

这个地方一般直接取默认值不用修改。

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
# Writing
new_post_name: :title.md # 新文章的文件名称
default_layout: post # 预设布局
titlecase: false # 把标题转换为 titlecase(titlecase指的是将每个单词首字母转换成大写)
external_link: # 在新标签中打开链接
enable: true # Open external links in new tab # 在新窗口打开页面
field: site # Apply to the whole site
exclude: ''
filename_case: 0 # 把文件名称转换为 (1) 小写或 (2) 大写, 0表示不变
render_drafts: false # 显示草稿
post_asset_folder: false # 启动 Asset 文件夹
relative_link: false # 把链接改为与根目录的相对位址
future: true # 显示未来的文章
syntax_highlighter: highlight.js
highlight: # 代码块的设置
enable: true
line_number: true # 是否显示行号
auto_detect: true # 是否自动监测
tab_replace: # 将 tab 替换成其他字符串
wrap: true # 是否自动换行
hljs: false # 为 highlight 的 css 文件中的类添加 hljs-* 前缀
prismjs:
preprocess: true
line_number: true
tab_replace: ''

5.首页设置

这个地方一般直接取默认值不用修改。

1
2
3
4
5
6
7
8
# Home page setting                                                   # 主页设置
# path: Root path for your blogs index page. (default = '') # 博客索引页面的根路径。(默认值=“”)
# per_page: Posts displayed per page. (0 = disable pagination) # 每页显示的帖子。(0 =禁用分页)
# order_by: Posts order. (Order by date descending by default) # 发布订单。(默认情况下按日期降序排序)
index_generator:
path: ''
per_page: 10
order_by: -date

6.分类和标签配置

这个地方一般直接取默认值不用修改。

1
2
3
4
# Category & Tag
default_category: uncategorized # 默认分类, uncategorized表示未分类
category_map: # 分类别名
tag_map: # 标签别名

7.元数据元素

这个地方一般直接取默认值不用修改。

1
2
3
# Metadata elements
## https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
meta_generator: true

8.时间格式

这个地方一般直接取默认值不用修改。

1
2
3
4
5
6
7
8
# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD # 日期格式
time_format: HH:mm:ss # 时间格式
## updated_option supports 'mtime', 'date', 'empty'
updated_option: 'mtime'

9.分页配置

这个地方一般根据自己的需求修改 per_page 设置每页显示的文章数量即可,一般情况下也不需要修改。

1
2
3
4
# Pagination
## Set per_page to 0 to disable pagination
per_page: 10 # 每页显示的文章量,如果设置值为0,则表示禁止分野
pagination_dir: page # 分页目录

10.拓展设置

包括或不包括目录和文件,这个地方一般直接取默认值不用修改。

1
2
3
4
5
# Include / Exclude file(s)
## include:/exclude: options only apply to the 'source/' folder
include:
exclude:
ignore:

11.主题配置

一般从这里开始,都是属于Hexo拓展插件的配置了,下面是配置博客所要使用的主题,想要获取更多的主题。结合自己的主题情况修改。

1
2
3
4
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: anzhiyu # 主题设置,默认是 landscape

12.部署配置

这一块涉及到博客发布,需要结合自己的部署方式进行修改或者删除,这里可以先不用修改配置。

1
2
3
# Deployment
deploy:
type: # 设置发布类型,如git,rsync

在下面就是结合自己网站博客添加的插件,自己添加的一些配置了。在这里不多说。有一些代码解释的不是很好,以后有机会再说吧。