Skip to content

永久链接

使用

Hexo_config.yml中设置属性permalink属性用于设置文章在静态文件生成后的路径

permalink: :year/:month/:day/:title/
permalink_defaults:

比如文章hello-world.md的源路径为

/source/_posts/hello-world.md

生成静态文件后的路径为

/path/to/public/2021/03/10/hello-world/index.html

变量

Hexo提供了以下变量来生成永久链接

变量 描述
:year 发表年份(4位数字)
:month 发表月份(2位数字)
:i_month 发表月份(没有前置0)
:day 发表日(2位数字)
:i_day 发表日(没有前置0)
:title 文件名
:post_title 文章标题
:post_title 文章ID
:category 类别。如果没有分类,那么使用属性default_category的值

比如文章配置块内容如下:

title: Hello World
date: 2013-07-14 17:01:34
categories:
    - foo
    - bar

那么可以定义如下的永久链接

:year/:month/:day/:title/ 
:year-:month-:day-:title.html
:category/:title

生成的静态文件如下

2013/07/14/hello-world/index.html
2013-07-14-hello-world.html
foo/bar/hello-world

语言设置

可以使用属性permalink_defaults:指定默认值,比如使用语言

permalink_defaults:
  lang: en

插件rozbo/hexo-abbrlink支持生成更加常见的永久链接,其实现方式

对标题+时间进行md5然后再转base64,保存在front-matter中。

安装

npm install hexo-abbrlink --save

修改_config.yml

permalink: posts/:abbrlink.html

可以修改生成的算法和表示方式

算法:crc16(默认)或crc32
表示:dec(默认,十进制)或hex(十六进制)

配置方式

# abbrlink config
abbrlink:
  alg: crc32  #support crc16(default) and crc32
  rep: hex    #support dec(default) and hex

编译后会在源文件的配置块中插入

abbrlink: xxxxx