前言
Hexo的默认文章链接格式是年,月,日,标题这种格式来生成的。如果你的标题是中文的话,那你的URL链接就会包含中文,生成的链接如下图
![图片[1]-利用Hexo-abbrlink插件生成唯一文章链接-忽然笔记](https://unpkg.zhimg.com/hexo-img-post/20211205103011.png)
复制后的URL路径就是把中文变成了一大堆字符串编码,如果你在其他地方用这边文章的url链接,偶然你又修改了改文章的标题,那这个URL链接就会失效。为了给每一篇文章来上一个属于自己的链接,写下此教程,利用hexo-abbrlink
插件,A Hexo plugin to generate static post link based on post titles,来解决这个问题。 参考github官方: hexo-abbrlink 按照此教程配置完之后如下:
![图片[2]-利用Hexo-abbrlink插件生成唯一文章链接-忽然笔记](https://unpkg.zhimg.com/hexo-img-post/20211205103230.png)
安装
在Hexo根目录安装插件:
npm install hexo-abbrlink --save
插件安装成功后,修改根目录的配置文件_config.yml
找到permalink
permalink: :year/:month/:day/:title/
#修改为
permalink: post/:abbrlink.html # post为自定义前缀
abbrlink:
alg: crc32 #算法: crc16(default) and crc32
rep: hex #进制: dec(default) and hex
有两种设置:
alg -- Algorithm (currently support crc16 and crc32, which crc16 is default)
rep -- Represent (the generated link could be presented in hex or dec value)
crc16的最大数值为65535。如果一个缩写的链接已经存在,它会更改成另一个,并一次又一次地尝试…所以推荐使用crc32
样本
生成的链接将如下所示:
crc16 & hex
https://blog.huran.xyz/posts/66c8.html
crc16 & dec
https://blog.huran.xyz/posts/65535.html
crc32 & hex
https://blog.huran.xyz/posts/8ddf18fb.html
crc32 & dec
https://blog.huran.xyz/posts/1690090958.html
验证
一切修改完毕后,清理本地的文件hexo clean
,然后重新生成hexo g
然后找到你的文章打开,该插件会在每篇文章的开头增加内容
预览一下hexo s
,访问一下你的本地连接查看成果吧。
没问题就可以上传hexo d
使用了
Tips
欢迎收藏和转发,感谢你的支持!(๑•̀ㅂ•́) ✧

Use this card to join the candyhome and participate in a pleasant discussion together .
Welcome to Knlde's candyhome,wish you a nice day .
请登录后发表评论
注册
社交帐号登录