场景:由于hexo 默认的链接是 http://xxx.yy.com/2019/12/22/hello-world 这种类型的,这源于站点目录下的配置 _config.yml 里的配置 :permalink: :year/:month/:day/:title/,这种默认配置的缺点就是一般文件名是中文,导致 url 链接里有中文出现,这会造成很多问题,如文末的版权声明会很臃肿不美观,也不利于 SEO。

image.png

hexo-abbrlink插件很好的解决了这个问题,它会自动根据文章时间点生成最终博客文章链接,后期不管怎么修改文章永久链接都不会再变。同时文章链接层级更短,使得博客文章更利于SEO。

安装

在站点根目录使用 git bash 执行命令:

npm install hexo-abbrlink --save

配置

打开根目录下的 _config.yml 文件,搜索permalink,注释掉之前的设置,修改为如下配置

# permalink: :year/:month/:day/:title/
# permalink_defaults:
permalink: posts/:abbrlink.html
abbrlink:
  alg: crc32  # 算法:crc16(default) and crc32
  rep: hex    # 进制:dec(default) and hex

样品

算法和进制设置不同的话会有不同的效果:

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

局限

由于crc16的最大帖子数是65535。(对于个人博客网站,此数字可能不错)

完成

接下来重新部署三连,可以看到我们的文章路径变成了 /posts/xxxxx.html,接下来就算我们将文字标题命名为中文也没问题了。

参考链接


滑稽场|高性价比|支持SSR,V2ray,Trojan协议
Last modification:October 25th, 2020 at 01:46 am
如果觉得我的文章对你有用,请随意赞赏