博客文章永久链接设置
配置文章的永久链接有利于 SEO,当然也更好看。
在站点的_config.yml
中,生成的文章链接默认为:
1 | permalink: :year/:month/:day/:title/ |
这种情况下,文章名称一旦是中文,那生成的链接简直就是灾难…
1 | https://xxx.com/post/%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E4%BB%AC%E7%9A%84%E5%A4%A7%E8%84%91-%E6%9B%B4%E5%AE%B9%E6%98%93%E6%B2%89%E8%BF%B7%E6%B8%B8%E6%88%8F-%E8%80%8C%E4%B8%8D%E6%98%AF%E5%AD%A6%E4%B9%A0.html#more |
解决方案一(已过时)
在 md 文件的 Front-matter 区域,增加一个 urlname
属性,用来放文章的英文名字。
1 | title: hexo链接持久化终极解决之道 |
然后修改 _config.yml
里的配置:
1 | permalink: posts/:category/:year:month:day-:urlname.html |
不再详细介绍,参考:Jingbin’s Home
解决方案二
hexo-abbrlink 是一个 Hexo 插件,用于根据帖子标题生成静态帖子链接。
安装
1 | npm install hexo-abbrlink --save |
在站点配置文件 _config.yml
中查找代码 permalink,将其更改为:
1 | # posts/ 部分可自行更换,我的是 :year:month:day/:abbrlink.html |
然后在站点配置文件中添加如下代码:
1 | # abbrlink config |
生成后的文章样式:
1 | # crc16 & hex |
完美解决问题!🎉
配置之后常见问题:按照给的方法添加配置后生成链接都是undefined
,执行以下命令即可:
1 | hexo clean |
参考
JingBin’s Home
Time Flying
Github - hexo-abbrlink
Github - issues