Hexo设置永久链接

官方:rozbo/hexo-abbrlink: create one and only link for every post for hexo (github.com)
参考:Hexo的SEO优化-使用abbrlink设置永久链接为随机值 - 腾讯云开发者社区-腾讯云 (tencent.com)

安装

1
npm install hexo-abbrlink --save #提示错误可以加上sudo

配置

以下设置均修改博客根目录下的配置文件.config.xml

1
2
3
4
5
6
7
8
9
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: https://blog.baiyz.top/ #替换为你自己的链接
root: /
permalink: posts/:abbrlink/ #这里就是永久链接的参数设置
permalink_defaults:
pretty_urls:
trailing_index: true # false会移出永久链接里面的index.html
trailing_html: true # false会移出永久链接中的.html

参数意义:

  • alg 对应随机值算法参数,可选为 crc16 和 crc32
  • rep 对应生成链接的表示方法,hex:十六进制,dec:十进制

    对于 crc16 算法生成的随机值,具有一个最大限度,为 65536。

示例:

  • crc16 & hex:https://blog.baiyz.top/posts/33a6.html
  • crc16 & dec:https://blog.baiyz.top/posts/34212.html
  • crc32 & hex:https://blog.baiyz.top/posts/1ed16a3c.html
  • crc32 & dec:https://blog.baiyz.top/posts/1453217752.html

使用

使用前执行:hexo clean & hexo g