0%

hexo 博客搭建之文章链接地址

以本文文章链接地址为例,默认URL地址:http://localhost:4000/2020/12/01/hexo-博客搭建之文章链接地址/

在浏览器中则是:http://localhost:4000/2020/12/01/hexo-%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA%E4%B9%8B%E6%96%87%E7%AB%A0%E9%93%BE%E6%8E%A5%E5%9C%B0%E5%9D%80/

而本文将介绍如何将其转换成简短的URL地址:http://localhost:4000/posts/3ace8d52.html

1. 安装转化插件

Github: hexo-abbrlink

1
$ npm intall hexo-abbrlink --save
2. 编辑 站点配置文件:_config.yml,启用插件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#permalink: :year/:month/:day/:title/
permalink: posts/:abbrlink.html

# abbrlink config
abbrlink:
alg: crc32 #support crc16(default) and crc32
rep: hex #support dec(default) and hex
drafts: false #(true)Process draft,(false)Do not process draft. false(default)
# Generate categories from directory-tree
# depth: the max_depth of directory-tree you want to generate, should > 0
auto_category:
enable: true #true(default)
depth: #3(default)
over_write: false
auto_title: false #enable auto title, it can auto fill the title by path
auto_date: false #enable auto date, it can auto fill the date by time today
force: false #enable force mode,in this mode, the plugin will ignore the cache, and calc the abbrlink for every post even it already had abbrlink.

不同算法和进制转换官方示例:

1
2
3
4
5
6
7
8
9
10
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
参考