永久链接(Permalinks)

您可以在 _config.yml 配置中调整网站的永久链接或者在每篇文章的 Front-matter 中指定。

变量

除了下列变量外,您还可使用 Front-matter 中的所有属性。

变量 描述
: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位16进制数)

您可在 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

而网址会是:

http://localhost:4000/tw/hello-world/