【博客】生成文章唯一链接

  1. 前言
  2. 参考教程
  3. 安装插件
  4. 配置文件_config.yml
  5. 运行网站

前言

Hexo的默认文章链接格式是年,月,日,标题这种格式来生成的。如果你的标题是中文的话,那你的URL链接就会包含中文,复制后的URL路径就是把中文变成了一大堆字符串编码,如果你在其他地方用这边文章的url链接,偶然你又修改了改文章的标题,那这个URL链接就会失效。为了给每一篇文章来上一个属于自己的链接,写下此教程,利用 hexo-abbrlink 插件,A Hexo plugin to generate static post link based on post titles ,来解决这个问题。

参考教程

hexo-abbrlink

安装插件

npm install hexo-abbrlink --save

配置文件_config.yml

修改config.yml文件中的永久链接:

permalink: posts/:abbrlink.html
# or
# permalink: posts/:abbrlink/

再修改设置

# permalink: :year/:month/:day/:title/
- permalink: :year/:month/:day/:title/
# 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. This only updates abbrlink rather than other front variables.

运行网站

运行网站后文章Front-matter处自动生成abbrlink: 79dba5d2唯一链接

INFO  Start processing
INFO  Generate link [79dba5d2] for post [source/_posts/生成文章唯一链接.md][ 生成文章唯一链接 ]
INFO  Generated: categories [undefined] for post [source/_posts/生成文章唯一链接.md][ 生成文章唯一链接 ]

得到文章链接如下:https://tech.aligu.top/post/79dba5d2.html


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 3415226167@qq.com
资源 相册