Hexo-abbrlink博客URL持久化、优化

前言

为什么要优化URL?

  1. 对搜索引擎比较友好
  2. URL缩短

Hexo默认的都是年/月/日/md的标题
localhost:4000/2020/06/10/hello-world/

方式一

URL优化前:
image.png

URL优化后:
image.png

弊端:上方的文章标题是 hello-world,是没多大区别,如果文章标题含有中文

image.png

方式二(推荐)

安装 hexo-abbrlink 插件:

COPY
1
npm install hexo-abbrlink --save

C:\Hexo-Blog\_config.yml中找到permalink注释掉,加入如下代码

COPY
1
2
3
4
5
6
7
8
9
10
11
12
13
#permalink: :year/:month/:day/:title/
permalink: article/: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
# Generate categories from directory-tree
# depth: the max_depth of directory-tree you want to generate, should > 0
auto_category:
enable: true
depth:

效果:
image.png

注意:因为你的文章目录结构已经改变,和之前的年月日文章路径产生冲突,所以你需要重新生成文章 hexo cleanhexo g,不然会报 undefined 错

Authorship: Lete乐特
Article Link: https://blog.imlete.cn/article/3a86607d.html
Copyright: All posts on this blog are licensed under the CC BY-NC-SA 4.0 license unless otherwise stated. Please cite Lete乐特 's Blog !