永久連結

您可以在 _config.yml 中或每篇文章的 front-matter 中指定您網站的永久連結。

變數

除了以下變數之外,您可以在永久連結中使用任何屬性,但 :path:permalink 除外。

變數 描述
:year 文章發布年份(4 位數字)
:month 文章發布月份(2 位數字)
:i_month 文章發布月份(不帶前導零)
:day 文章發布日期(2 位數字)
:i_day 文章發布日期(不帶前導零)
:hour 文章發布小時(2 位數字)
:minute 文章發布分鐘(2 位數字)
:second 文章發布秒數(2 位數字)
:title 檔案名稱(相對於「source/_posts/」資料夾)
:name 檔案名稱
:post_title 文章標題
:id 文章 ID(快取重置後不會持續存在
:category 分類。如果文章未分類,則會使用 default_category 值。
:hash 檔案名稱(與 :title 相同)和日期的 SHA1 雜湊值(12 個十六進位數字)

您可以通過 permalink_defaults 設定定義永久連結中每個變數的預設值

permalink_defaults:
lang: en

範例

source/_posts/hello-world.md
title: 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.html 2013-07-14-hello-world.html
:category/:title/ foo/bar/hello-world/
:title-:hash/ hello-world-a2c8ac003b43/
source/_posts/lorem/hello-world.md
title: 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 設定,如下所示

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

當您建立新文章時,文章將會儲存到

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

URL 將會是

https://127.0.0.1:4000/tw/hello-world/