13 Hexo 配置文件详解

13 Hexo 配置文件详解

Hexo 是一个快速、简洁且高效的静态博客框架,它使用 YAML 格式的配置文件来管理网站的设置。本文将详细介绍 Hexo 的配置文件及相关选项,让你能够根据自己的需求进行灵活配置。

1. 配置文件位置

Hexo 的配置文件一般位于博客根目录下的 _config.yml 文件,这个文件是 Hexo 的核心配置文件,涵盖了一系列重要的设置。

2. 基本配置选项

2.1. title

1
title: My Blog
  • 说明: 这是你博客的标题,会在页面的 <title> 标签和站点的首页展示。

2.2. subtitle

1
subtitle: A place to share my thoughts
  • 说明: 这是博客的副标题,可以用于描述博客的主题或内容。

2.3. author

1
author: Your Name
  • 说明: 博客作者的名字。用于文章底部的作者信息。

2.4. description

1
description: This is my personal blog where I share my ideas.
  • 说明: 博客的简短描述,一般用于搜索引擎和社交媒体的链接摘要。

3. 语言与时区

3.1. language

1
language: en
  • 说明: 设置博客使用的语言,常见的如 en (英语)、zh-CN (简体中文) 等。

3.2. timezone

1
timezone: Asia/Shanghai
  • 说明: 设置博客的时区,确保发表的文章时间的准确性。

4. URL 配置

4.1. url

1
url: https://your-blog.com
  • 说明: 博客的基础 URL,生成的链接路径以及 RSS 源都将基于此设置。

4.2. root

1
root: /
  • 说明: 博客的根路径。如果你的博客不是部署在根目录下,需要修改此项。例如,如果部署在 https://your-blog.com/blog/,应设为 /blog/

5. 目录设置

5.1. source_dir

1
source_dir: source
  • 说明: 文件源目录,Hexo 默认使用 source 作为文件存储目录,可以自定义。

5.2. public_dir

1
public_dir: public
  • 说明: 生成的静态文件存放目录,默认为 public

5.3. plugins_dir

1
plugins_dir: node_modules
  • 说明: 插件目录,Hexo 默认从 node_modules 中加载插件。

6. 主题设置

6.1. theme

1
theme: landscape
  • 说明: 设置当前使用的主题。Hexo 提供多种主题可供选择。

6.2. 主题特定配置

许多主题还具有特定的配置项,通常在 theme_config.yml 文件中。例如:

1
2
3
menu:
Home: /
Archive: /archives

6.3. 主题自定义示例

1
2
3
4
theme_config:
menu:
Home: /
Tags: /tags

7. Markdown 配置

7.1. markdown

1
2
markdown:
preset: commonmark
  • 说明: 设置 Markdown 解析器和解析选项,如 presetsextensions

8. 其他高级配置

1
permalink: :year/:month/:day/:slug/
  • 说明: 设置文章链接格式,使用特殊变量如 :year:month:day:slug

8.2. archive

1
2
archive:
per_page: 10
  • 说明: 配置归档页面的每页文章数量。

8.3. pagination

1
2
pagination:
per_page: 5
  • 说明: 配置每页显示的文章数量。

9. 示例配置文件

以下是一个完整的 _config.yml 示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
title: My Blog
subtitle: A place to share my thoughts
author: Your Name
description: This is my personal blog where I share my ideas.
language: en
timezone: Asia/Shanghai
url: https://your-blog.com
root: /

source_dir: source
public_dir: public
plugins_dir: node_modules

theme: landscape

markdown:
preset: commonmark

permalink: :year/:month/:day/:slug/
pagination:
per_page: 5

结论

Hexo 的配置文件是一个非常灵活且强大的工具,可以帮助你根据个人需求定制博客。通过了解和配置这些选项,你可以创建一个符合自己需求的博客系统。希望本篇教程能够帮助你更好地理解和使用 Hexo 配置文件。

13 Hexo 配置文件详解

https://zglg.work/hexo-api-tutorial/13/

作者

AI教程网

发布于

2024-08-08

更新于

2024-08-10

许可协议