Hexo 中permalink使用 Hexo-abbrlink生成唯一永久文章链接及小优化

Hexo原有的链接生成permalink包含中文,且标题更改之后原链接失效,现在采用

 1.原有的链接格式

permalink: :year/:month/:day/:title/  #这是原有的

 缺陷:title本身如果更改,那么原有的链接就将失效,所有的引用就无效了。

几点备注说明

a。其中title为Front-matter内的title,而非文件的名称。

 

2. 采用hexo-abbrlink实现永久唯一链接

a。安装abbrlink插件

npm install hexo-abbrlink --save 

安装后,hexo 会自动(保存文章时、或者hexo g时都可以)在Front-matter中自动加入abbrlink字段。

 !!!abbrlink一旦生成,即使修改title,其内容也不会再更改了,除非将abbrlink字段手动删除,然后hexo会重新根据title自动生成。

b。_config.yml 中修改

permalink: posts/:abbrlink.html     # 将原来文章的地址修改为这个

# 并添加如下配置:
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.
permalink_defaults:
pretty_urls:
  trailing_index: true # Set to false to remove trailing 'index.html' from permalinks
  trailing_html: true # Set to false to remove trailing '.html' from permalinks

 关键地方

permalink: posts/:abbrlink.html     # 将原来文章的地址修改

几点备注说明

a。其中 .html, posts/ 也不重要,可以随便写,也可以不写。

b。其中abbrlink这个比较关键。

abbrlink:为title生成的一堆十六进制字符串。

问题缺陷

因为abbrlink是由title生成的,所以,所有post文章不可以有相同的title!那么这时候问题就来了,我们写很多的文章,会难免出现title相同的情况,这就导致生成的链接只能指向固定的一个,也就是说有两篇相同title的文章,此时只有一个有效。

改进的方法

permalink: posts/:year:month:day:hour:minute:second-:abbrlink.html

这样将year、month、day、hour、second、hour、minute、second加入后,即使存在同title的情况,大概率也不会有相同的date时间,因此可以较大概率防止出问题。

!!!其中:year、month、day、hour、second、hour、minute、second,一定必须是front-matter中的date字段,并且严格按照格式

必须有date字段!如果没有date字段,上述将替换为文件的创建时间(文件一旦移动、拷贝,文件创建时间将完全改变,链接也就全变了,就完蛋了)。

 效果

 3.date格式快捷键设置

采用搜狗输入法的自定义格式

 

 自定义代码

下面的这些,根据不同版本,其写法不太一样。

#$year-$month_mm-$day_dd $fullhour_hh:$minute:$second

 参考文章:(注意该文章较老,有些代码不太对)

搜狗输入时间日期格式输入及自定义 - H5W3

 

 搜狗输入输入sj即可

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值