优化Hexo文章默认URL配置

  • Hexo 版本
1
2
3
$ hexo -v
hexo: 7.2.0
hexo-cli: 4.3.2
  • 在 Hexo 全局配置 _config.yaml 中 URL 默认配置为
1
2
3
4
5
6
7
permalink: :year/:month/:day/:title/
permalink_defaults:
pretty_urls:
trailing_index: true
trailing_html: true

// https://xxx.xxx/年/月/日/文章标题为 URL,这里的 :title 是基于 source/_post 目录相对路径下的文章标题
  • 修改为
1
2
3
4
5
6
7
permalink: /article/:hash
permalink_defaults:
pretty_urls:
trailing_index: false # 设置为 false 将从链接中删除 'index.html'
trailing_html: false # 设置为 false 将从链接中删除 '.html'

// 每次生成文章时,将会为文章自动生成hash值,如:http://xxx.xxx/article/d2e777559a62/

Hexo URL自定义规则

变量 描述
:year 文章的发表年份(4 位数)
:month 文章的发表月份(2 位数)
:i_month 文章的发表月份(去掉开头的零)
:day 文章的发表日期(2 位数)
:i_day 文章的发表日期(去掉开头的零)
:hour 文章发表时的小时(2 位数)
:minute 文章发表时的分钟(2 位数)
:second 文章发表时的秒钟(2 位数)
:title 文件名称(relative to “source/_posts/“ folder)
:name 文件名称
:post_title 文章标题
:id 文章ID(not persistent across cache reset)
:category 分类,如果文章没有分类,则是 default_category 配置信息。
:hash SHA1 hash of filename(same as :title) and date(12-hexadecimal)