博客进阶——优化博客的永久链接

本文最后更新时间:2021年11月14日 晚上

之前的链接

之前给朋友分享博客的时候,发出去的链接经常这样:

旧链接

就像图片中这样,一长串的链接,非常的不美观。

于是我上网找了找,发现了一个使用 hexo-abbrlink 插件的解决办法。

安装

安装 hexo-abbrlink 插件,在 bash 中使用命令:

1
npm install hexo-abbrlink --save

配置

修改博客配置文件 _config.yml,ctrl + F 找到 permalink,修改成:

1
permalink: posts/:abbrlink/

当然也可以把posts/改成别的,比如p/或者不写,可以自行选择。

然后在 _config.yml 里新加一项:

1
2
3
4
# abbrlink config
abbrlink:
alg: crc16 # 算法:crc16(default) and crc32
rep: dec # 进制:dec(default) and hex

不同的算法和进制生成的例子如下(引用官方文档例子

1
2
3
4
5
6
7
8
9
10
11
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

我采用的是:

1
2
3
4
# abbrlink config
abbrlink:
alg: crc32 # 算法:crc16(default) and crc32
rep: hex # 进制:dec(default) and hex

然后三连本地查看效果:

1
2
3
hexo cl
hexo g
hexo s

确认无误之后就可以部署:

1
hexo d

以后就可以更优雅的分享博客连接了。

1
2
3
4
5
https://www.khlfyy.top/2021/08/10/KH%E7%9A%84%E5%8D%9A%E5%AE%A2%E6%98%AF%E5%A6%82%E4%BD%95%E5%BB%BA%E7%AB%8B%E7%9A%84/



https://www.khlfyy.top/posts/b637f248/

别忘了把 原先文章的评论 转移到 有了新链接的文章 下(比如 valine 评论模块 所用的 LeanCloud 数据库下,将原先文章评论的 url 换成 新url)


本文作者:Zhao Guihang/KHLFYY

版权声明:本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!