待优化问题

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

1
year/:month/:day/:title/

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

而且这种中文链接,由于编码的问题,在分享文章链接的时候往往变成:

就问你 ___ 难受不难受 ___

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

不换掉它准备留着过年?

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

https://github.com/rozbo/hexo-abbrlink

安装abbrlink插件

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

1
npm install hexo-abbrlink --save

编辑站点配置文件

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

1
2
3
4
5
6
#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插件的设置:

1
2
alg -- Algorithm (currently support crc16 and crc32, which crc16 is default)
rep -- Represent (the generated link could be presented in hex or dec value)

这两个设置的示例如下:

1
2
3
4
5
crc16 & hex
https://post.zz173.com/posts/66c8.html

crc16 & dec
https://post.zz173.com/posts/65535.html
1
2
3
4
5
crc32 & hex
https://post.zz173.com/posts/8ddf18fb.html

crc32 & dec
https://post.zz173.com/posts/1690090958.html

重新生成部署

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

接下来使用hexo d部署,使用浏览器查看:

这样优化后的优点有以下几个:

  • 纯英文和数字链接非常有利于SEO;
  • 只要abbrlink编号不变,该文章的url就不变,可以随意修改文件名,文章标题;
    第一篇Hexo优化教程就到这儿,快去试试吧~

原作者:Mculover666 原文链接:https://cloud.tencent.com/developer/article/1662763