Hexo 默认的永久链接配置为:year/:month/:day/:title/,这样生成的链接会成为一个四级目录,对于搜索引擎来说并不是很友好。这里介绍一个 Hexo 插件 hexo-abbrlink,它能将 Hexo 生成的永久链接转化为一个固定的随机值,极大的缩短了永久链接的长度。一旦生成一个随机值,之后对文章的标题或者时间进行任何修改,这个随机的 abbrlink 是不会发生任何变化的,也为 Hexo 的维护提供了便利。
博客目录下执行 npm 安装指令
$ npm install hexo-abbrlink --save #提示错误可以加上sudo像下面一样
#npm install hexo-abbrlink --save
以下设置均修改博客根目录下的配置文件.config.xml
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: https://ifibe.com/ #替换为你自己的链接
root: /
permalink: posts/:abbrlink/ #这里就是永久链接的参数设置
permalink_defaults:
当永久链接参数为permalink: posts/:abbrlink/
时,生成的文章链接类似于/post/cd6eb56d/
,例如https://ifibe.com/post/cd6eb56d/
。
# abbrlink config
abbrlink:
alg: crc32 #support crc16(default) and crc32
rep: hex #support dec(default) and hex
参数:alg
对应随机值算法参数,可选为 crc16 和 crc32
参数:rep
对应生成链接的表示方法,hex:十六进制,dec:十进制
两种参数的生成区别:
crc16+hex
/posts/66c8/
crc16+dec
/posts/65535/
crc32+hex
/posts/8ddf18fb/
crc32+dec
/posts/1690090958/
对于 crc16 算法生成的随机值,具有一个最大限度,为 65536。
使用前执行
$ hexo clean & hexo g
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有