hexo链接持久化终极解决之道
来源:互联网 发布:php 数字转二进制 编辑:程序博客网 时间:2024/06/05 12:40
背景
大家知道hexo默认的链接是http://xxx.yy.com/2013/07/14/hello-world
这种类型的,这源于站点目录下的配置_config.yml
里的配置:permalink: :year/:month/:day/:title/
.这种默认配置的缺点就是一般文件名是中文,导致url链接里有中文出现,这会造成很多问题,如使用gitment,也不利于seo。另外就是年月日都会有分隔符。本文介绍经过作者研究总结出的最终解决方案。
过时解决方案
在md文件的Front-matter
区域,增加一个urlname属性,用来放文章的英文名字。如下图所示:
title: hexo链接持久化终极解决之道urlname: hexo_permalinkdate: 2017-08-31 23:53:24comments: truecategories:- 综合tags:- hexo
然后修改 _config.yml
里的配置:
permalink: posts/:category/:year:month:day-:urlname.htmlpermalink_defaults: urlname: index
后缀增加.html
给人以静态页面感觉,利于seo.这里面:urlname
表示引用的这个变量。前面是分类/年月日。另外增加一个urlname这个属性的默认值,当md文档里不填这个属性,就用这个值。这里设的是index
,也就是说如果不填这个属性,其链接为:http://xxx.com/posts/uncategorized/20170828-index.html
。当然最好写上这个属性,偶尔某天不写这个属性也没关系。
另外还要解决一个问题,就是:category
分类有可能为中文。为此在站点下配置文件里设置:
default_category: uncategorizedcategory_map: 综合: common
这样在Front-matter
里,分类该写中文写中文,最终的链接会翻译成英文。
终极方案
无意中看到http://muyunyun.cn/posts/f55182c5/#more,最终决定采用这种方案使用hexo-abbrlink
这个插件,猜测是根据时间点算出的最终链接,后期不管怎么修改永久链接都不会变.一来自己不用再增加什么属性了,也不用考虑分类中文化的问题。二来后面的层级更短,更利于SEO。(一般SEO只爬三层)
npm install hexo-abbrlink --save
站点配置文件里:
permalink: post/:abbrlink.htmlabbrlink: alg: crc32 # 算法:crc16(default) and crc32 rep: hex # 进制:dec(default) and hex
另外可以修改scaffolds
里的模版文件,修改post.md
为:
---title: {{ title }}date: {{ date }}comments: truecategories:tags:---
不建议的写法
- 有的人采用了md文件的名字是英文,在
Front-matter
里将title
写成正常的中文呢,这个将来文章多了,都是英文不利于收藏整理。
参考链接
- https://hexo.io/zh-cn/docs/permalinks.html
- https://yq.aliyun.com/articles/8607
- http://muyunyun.cn/posts/f55182c5/#more
- http://blog.csdn.net/mrDiordna/article/details/66472673
- hexo链接持久化终极解决之道
- EXCEL导出乱码终极解决之道
- Hexo 百度提交链接
- hexo 学习链接
- [转贴]Java/J2EE中文问题终极解决之道
- Java/J2EE中文问题终极解决之道
- Java/J2EE中文问题终极解决之道[转]
- Java/J2EE中文问题终极解决之道
- Java/J2EE中文问题终极解决之道
- Java/J2EE中文问题终极解决之道
- Java/J2EE中文问题终极解决之道
- Java/J2EE中文问题终极解决之道
- Java/J2EE中文问题终极解决之道
- Java/J2EE中文问题终极解决之道
- Java/J2EE中文问题终极解决之道
- Java/J2EE中文问题终极解决之道
- Java/J2EE中文问题终极解决之道(转)
- Java/J2EE中文问题终极解决之道
- 八大排序算法的 Python 实现
- Linux下fork函数的使用
- 2015-2016 Samara Regional Intercollegiate Programming Contest G
- Hbase 启动后 HMaster 很快就挂掉 TableExistsException: hbase:namespace
- ThrottleStop CPU频率调节
- hexo链接持久化终极解决之道
- NYOJ题目69-数的长度(斯特林算法)
- light oj 1118 Incredible Molecules
- RandomAccessfile
- java 映射 的示例
- Servlet会话跟踪技术
- 《Effective Java》经典建议系列(3)
- Leetcode 73. Set Matrix Zeroes
- ARM.CMSIS.3.20.4.pack 和 Keil.STM32F1xx_DFP.1.0.5.pack 这两个文件的意义