設定

您可以在 _config.yml替代的設定檔中修改網站設定。

網站

設定 描述
title 您的網站標題
subtitle 您的網站副標題
description 您的網站描述
keywords 您網站的關鍵字。支援多個值。
author 您的名字
language 您網站的語言。使用雙字母 ISO-639-1 代碼,或選擇性地使用其變體。預設值為 en
timezone 您網站的時區。Hexo 預設使用您電腦上的設定。您可以在這裡找到可用的時區列表。一些範例是 America/New_YorkJapanUTC

網址

設定 描述 預設
url 您的網站網址,必須以 http://https:// 開頭
root 您網站的根目錄 網址的路徑名稱
permalink 文章的永久連結格式 :year/:month/:day/:title/
permalink_defaults 永久連結中每個區段的預設值
pretty_urls permalink變數重寫為美觀網址
pretty_urls.trailing_index 尾隨的 index.html,設定為 false 以移除它 true
pretty_urls.trailing_html 尾隨的 .html,設定為 false 以移除它 (不適用於尾隨的 index.html) true
子目錄中的網站

如果您的網站位於子目錄中 (例如 http://example.org/blog),請將 url 設定為 http://example.org/blog 並將 root 設定為 /blog/

範例

# e.g. page.permalink is http://example.com/foo/bar/index.html
pretty_urls:
trailing_index: false
# becomes http://example.com/foo/bar/

目錄

設定 描述 預設
source_dir 來源資料夾。您的內容儲存在此處 source
public_dir 公開資料夾。將在此處產生靜態網站 public
tag_dir 標籤目錄 tags
archive_dir 歸檔目錄 archives
category_dir 分類目錄 categories
code_dir 包含程式碼目錄 (source_dir 的子目錄) downloads/code
i18n_dir i18n 目錄 :lang
skip_render 將直接複製到 public 的路徑,而無需渲染。您可以使用glob 表達式進行路徑比對。

範例

skip_render: "mypage/**/*"
# will output `source/mypage/index.html` and `source/mypage/code.js` without altering them.

## This also can be used to exclude posts,
skip_render: "_posts/test-post.md"
# will ignore the `source/_posts/test-post.md`.

寫作

設定 描述 預設
new_post_name 新文章的檔案名稱格式 :title.md
default_layout 預設版面配置 post
titlecase 將標題轉換為首字母大寫嗎? false
external_link 在新分頁中開啟外部連結嗎?
external_link.enable 在新分頁中開啟外部連結嗎? true
external_link.field 僅適用於整個 sitepost site
external_link.exclude 排除主機名稱。在適用的情況下指定子網域,包括 www []
filename_case 將檔案名稱轉換為 1 小寫;2 大寫 0
render_drafts 顯示草稿嗎? false
post_asset_folder 啟用資源資料夾嗎? false
relative_link 使連結相對於根資料夾嗎? false
future 顯示未來的文章嗎? true
syntax_highlighter 程式碼區塊語法高亮設定,請參閱語法高亮部分以取得使用指南 highlight.js
highlight 程式碼區塊語法高亮設定,請參閱Highlight.js 部分以取得使用指南
prismjs 程式碼區塊語法高亮設定,請參閱PrismJS 部分以取得使用指南

首頁設定

設定 描述 預設
index_generator 產生文章的歸檔,由 hexo-generator-index 提供支援
index_generator.path 您部落格首頁的根路徑 ''
index_generator.per_page 每頁顯示的文章數量。 10
index_generator.order_by 文章順序。預設依日期降序排列 (從新到舊)。 -date
index_generator.pagination_dir 網址格式,請參閱下方的分頁設定 page

分類 & 標籤

設定 描述 預設
default_category 預設分類 uncategorized
category_map 覆寫分類 slug
tag_map 覆寫標籤 slug

範例

category_map:
"yesterday's thoughts": yesterdays-thoughts
"C++": c-plus-plus

日期 / 時間格式

Hexo 使用 Moment.js 來處理日期。

設定 描述 預設
date_format 日期格式 YYYY-MM-DD
time_format 時間格式 HH:mm:ss
updated_option 當前言中未提供時,使用的 updated mtime
updated_option

當前言中未提供時,updated_option 控制 updated

  • mtime:使用檔案修改日期作為 updated。自 Hexo 3.0.0 以來,這是 Hexo 的預設行為
  • date:使用 date 作為 updated。通常與 Git 工作流程一起使用,當檔案修改日期可能不同時。
  • empty:當未提供時,直接捨棄 updated。可能與大多數主題和外掛程式不相容。

use_date_for_updated 已在 v7.0.0+ 中移除。請改用 updated_option: 'date'

分頁

設定 描述 預設
per_page 每頁顯示的文章數量。0 停用分頁 10
pagination_dir 網址格式 page

範例

pagination_dir: 'page'
# http://example.com/page/2

pagination_dir: 'awesome-page'
# http://example.com/awesome-page/2

擴充

設定 描述
theme 主題名稱。false 停用主題
theme_config 主題設定。在此鍵下包含任何自訂主題設定,以覆寫主題預設值。
deploy 部署設定
meta_generator Meta generator 標籤。false 停用標籤的注入。

包含/排除檔案或資料夾

使用以下選項來明確處理或忽略某些檔案/資料夾。支援使用 glob 表達式進行路徑比對。

includeexclude 選項僅適用於 source/ 資料夾,而 ignore 選項適用於所有資料夾。

設定 描述
include 包含隱藏檔案 (包括名稱以底線開頭的檔案/資料夾,但有一個例外*)
exclude 排除檔案/資料夾
ignore 忽略檔案/資料夾

範例

# Include/Exclude Files/Folders
include:
- ".nojekyll"
# Include 'source/css/_typing.css'.
- "css/_typing.css"
# Include any file in 'source/_css/'.
- "_css/*"
# Include any file and subfolder in 'source/_css/'.
- "_css/**/*"

exclude:
# Exclude 'source/js/test.js'.
- "js/test.js"
# Exclude any file in 'source/js/'.
- "js/*"
# Exclude any file and subfolder in 'source/js/'.
- "js/**/*"
# Exclude any file with filename that starts with 'test' in 'source/js/'.
- "js/test*"
# Exclude any file with filename that starts with 'test' in 'source/js/' and its subfolders.
- "js/**/test*"
# Do not use this to exclude posts in the 'source/_posts/'.
# Use skip_render for that. Or prepend an underscore to the filename.
# - "_posts/hello-world.md" # Does not work.

ignore:
# Ignore any folder named 'foo'.
- "**/foo"
# Ignore 'foo' folder in 'themes/' only.
- "**/themes/*/foo"
# Same as above, but applies to every subfolders of 'themes/'.
- "**/themes/**/foo"

列表中的每個值都必須用單引號/雙引號括起來。

include:exclude: 不適用於 themes/ 資料夾。請使用 ignore:,或者,在檔案/資料夾名稱前加上底線以排除。

* 值得注意的例外是 source/_posts 資料夾,但該資料夾下任何名稱以底線開頭的檔案或資料夾仍將被忽略。不建議在該資料夾中使用 include: 規則。

使用替代的設定

可以透過在您的 hexo 命令中新增 --config 旗標,並指定替代的 YAML 或 JSON 設定檔的路徑,或以逗號分隔 (無空格) 的多個 YAML 或 JSON 檔案列表,來指定自訂設定檔路徑。

# use 'custom.yml' in place of '_config.yml'
$ hexo server --config custom.yml

# use 'custom.yml' & 'custom2.json', prioritizing 'custom2.json'
$ hexo server --config custom.yml,custom2.json

使用多個檔案會合併所有設定檔,並將合併的設定儲存到 _multiconfig.yml。後面的值優先。它適用於任何數量的 JSON 和 YAML 檔案,具有任意深度的物件。請注意,列表中不允許有空格

例如,在上述範例中,如果 foo: barcustom.yml 中,但 "foo": "dinosaur"custom2.json 中,_multiconfig.yml 將包含 foo: dinosaur

替代的主題設定

Hexo 主題是獨立的專案,具有個別的 _config.yml 檔案。

您可以從其他地方設定主題,而無需 fork 主題並維護具有您設定的自訂版本

從網站主要設定檔中的 theme_config

自 Hexo 2.8.2 起支援

# _config.yml
theme: "my-theme"
theme_config:
bio: "My awesome bio"
foo:
bar: "a"
# themes/my-theme/_config.yml
bio: "Some generic bio"
logo: "a-cool-image.png"
foo:
baz: 'b'

產生主題設定

{
"bio": "My awesome bio",
"logo": "a-cool-image.png",
"foo": {
"bar": "a",
"baz": "b"
}
}

從專用的 _config.[theme].yml 檔案

自 Hexo 5.0.0 起支援

該檔案應放置在您的網站資料夾中,同時支援 ymljson。必須為 Hexo 設定 _config.yml 內的 theme,才能讀取 _config.[theme].yml

# _config.yml
theme: "my-theme"
# _config.my-theme.yml
bio: "My awesome bio"
foo:
bar: "a"
# themes/my-theme/_config.yml
bio: "Some generic bio"
logo: "a-cool-image.png"
foo:
baz: 'b'

產生主題設定

{
"bio": "My awesome bio",
"logo": "a-cool-image.png",
"foo": {
"bar": "a",
"baz": "b"
}
}

我們強烈建議您將主題設定儲存在一個位置。但是,如果您必須單獨儲存主題設定,則需要了解這些設定的優先順序:網站主要設定檔內的 theme_config 在合併期間具有最高的優先順序,其次是專用的主題設定檔。
主題目錄下的 _config.yml 檔案具有最低的優先順序。