本文效果可以访问:www.mculover666.cn 查看效果!

1. 问题描述

Hexo默认使用的文章永久链接格式是:

year/:month/:day/:title/

这种链接,如果遇上个中文标题,简直要爆炸,如下:

https://www.mculover666.cn/2019/08/10/2-STM32Cube/【STM32Cube-20】STM32CubeMX系列教程(完结)/

这种方式不仅导致链接变得非常长,而且一旦修改文章发布日期或者标题,链接立马失效,造成大量死链,所以:

不换掉它准备留着过年?

abbrlink插件可以帮助我们很好的解决这个问题,Github仓库如下:

2. 安装abbrlink插件

在博客根目录(执行hexo命令的地方)安装插件:

npm install hexo-abbrlink --save

Hexo搭建个人博客(十四) | 修改文章永久链接为随机编号_其他

3. 编辑站点配置文件

打开博客根目录下的站点配置文件_config.yml,修改如下配置:

#permalink: :year/:month/:day/:title/
#permalink_defaults:
permalink: posts/:abbrlink/
abbrlink:
  alg: crc32 #support crc16(default) and crc32
  rep: dec   #support dec(default) and hex

下面解释说明一下:

首先指定Hexo文章永久链接的格式,接下来两个是abbrlink插件的设置:

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 & 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
4. 重新生成部署

使用hexo clean && hexo g重新生成博客,在博客源文件可以看到自动生成的abbrlink编号:

Hexo搭建个人博客(十四) | 修改文章永久链接为随机编号_根目录_02
接下来使用hexo d部署,使用浏览器查看:

Hexo搭建个人博客(十四) | 修改文章永久链接为随机编号_html_03