Hexo永久链接优化

使用hexo博客时,访问文章的默认链接看起来十分杂乱,

hexo-abbrlink插件可以完美解决这一痛点

食用教程

  1. 安装插件

    1
    2
    #安装插件
    npm install hexo-abbrlink --save --registry=https://registry.npmmirror.com
  2. 配置链接格式

    打开 hexo根目录/_config.yml

    修改permalink为如下内容,二选一即可

    1
    2
    3
    4
    #结尾无.html
    posts/:abbrlink/
    #结尾有.html
    posts/:abbrlink.html

  3. 插件配置

    在当前配置文件中添加如下代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    # hexo-abbrlink
    abbrlink:
    alg: crc16 #支持crc16和crc32算法(默认crc16)
    rep: hex #支持dec和hex值(默认dec)
    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.

    通过配置alg和rep参数可以改变链接大小,如下

    1
    2
    3
    4
    5
    6
    7
    8
    #crc16 & hex
    https://example.com/posts/64c8.html
    # crc16 & dec
    https://example.com/posts/67535.html
    # crc32 & hex
    https://example.com/posts/8dff18eb.html
    # crc32 & dec
    https://example.com/posts/1690092958.html