Hexo:hexo利用hexo-abbrlink插件生成永久链接


封面

原文链接:Hexo:hexo利用hexo-abbrlink插件生成永久链接 | Elvin

前言

  • Hexo默认的静态URL格式是 :year/:month/:day/:title,即按年、月、日、标题的形式生成固定链接

​ 例如:http://www.xxx.com/2022/11/08/文章标题

​ 默认URL的格式会产生很多斜杠,百度蜘蛛在抓取网页时会根据网页权重抓取网页,比如最先抓取的首页(一般都是自己的域名,比较简短),因此在链接里不宜出现过多的斜杠,最好不要超过两个

​ 还有一个问题就是,如果文章的标题使用了中文,经过转码后,URL会变得特别长,在最后我会贴上对比图。

  • 使用hexo-abbrlink插件便可解决以上出现的问题,以往修改标题会导致原始链接失效,使用这个插件后只要不更改文章中的abbrlink值,文章的链接就会是持久的

操作

1、安装插件

npm install hexo-abbrlink --save

具体插件链接:hexo-abbrlink

2、配置

修改_config.yml配置文件

## permalink: :year/:month/:day/:title/
permalink: posts/:abbrlink.html  ## 此处可以自己设置,也可以直接使用 :/abbrlink

_config.yml配置文件下增加以下配置

如果你是butterfly主题,应该都有自己创建了一个主题配置的yml(我的是_config.butterfly.yml),以下的配置放在自定义的主题配置的yml文件中也是可以的

## 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.
  • alg: 算法(目前支持crc16crc32算法,默认值是crc16)
  • rep: 形式(生成的链接可以是十六进制格式也可以是十进制格式,默认值是十进制格式)

示例

crc16 & hex
https://test.com/posts/55c6.html
crc16 & dec
https://test.com/posts/43212.html

crc32 & hex
https://test.com/posts/6ec16a2c.html
crc32 & dec
https://test.com/posts/1521457752.html

更多配置可查看具体插件链接:hexo-abbrlink

效果展示

默认生成的URL

pic_1

使用插件生成的URL

pic_2

插件生成的URL会更简洁明了

借鉴链接

Hexo 博客生成永久链接

SEO优化:Hexo-abbrlink插件生成永久固定链接


更多知识持续更新中!!!

声明

借鉴部分均注明了原文出处,可在文章的借鉴链接处获取原文出处

文中若内容有涉及原版权,请邮件联系[email protected],涉及的相关文章或内容将会及时更改或取消发布

猜你喜欢

转载自blog.csdn.net/weixin_42464282/article/details/130982114
今日推荐