Hexo-Fluid主题-文章生成永久链接

本文最后更新于:December 3, 2021 pm

Hexo 默认文章链接生成规则是按照年、月、日、标题来生成的。一旦文章标题或者发布时间被修改,URL 就会发生变化,之前文章地址也会变成 404,而且 URL 层级很深,不利于分享和搜索引擎收录。如果文章标题中有中文,URL 被转码后会很长。

目录

abbrlink插件可以帮助我们很好的解决这个问题。

1.安装插件

1
npm install hexo-abbrlink --save

2.修改配置

修改博客根目录配置文件 _config.yml 的 permalink:

1
2
3
4
5
# permalink: :year/:month/:day/:title/
permalink: p/:abbrlink.html # p 是自定义的前缀,.html是自定义的后缀。
abbrlink:
alg: crc32 #算法: crc16(default) and crc32
rep: hex #进制: dec(default) and hex

也可以用其他的算法和进制:

1
2
3
4
5
6
7
8
9
crc16 & hex
https://post.zz173.com/posts/66c8.html
crc16 & dec
https://post.zz173.com/posts/65535.html

crc32 & hex
https://post.zz173.com/posts/8ddf18fb.html
crc32 & dec
https://post.zz173.com/posts/1690090958.html

3.重新生成部署

📢注意:使用hexo clean一定要把public目录下的自定义文件要备份!!!

1
2
3
hexo clean
hexo g
hexo s

之后再打开对应的MarkDown文件,会发现配置中多了一个abbrlink配置,你也可以修改此属性的值(相当于自定义文章链接了)。