hexo+yilia添加URL持久化


URL持久化

参考:你的Hexo博客SEO优化了吗?

我们可以发现hexo默认生成的文章地址路径是 【网站名称/年/月/日/文章名称】。比如这篇博客:
http://localhost:4000/2019/11/10/hexo+yilia添加URL持久化
这种链接对搜索爬虫是很不友好的,第一它的url结构超过了三层,太深了。第二使用了中文路径。这样会导致一个问题,在某些聊天工具或分享链接的时候会造成url转码变成很长一串难以读写的链接。而且如果你的页面之前被收录或被转载后,当你再次编辑过后可能会造成之前的url失效带来不必要的404, 比如下面这样:
http://localhost:4000/article/faa5d14。别担心,我们有好办法来解决它。

第一种方式:

打开_config.yml配置文件,找到permalink

#permalink: :year/:month/:day/:title/ 注释掉
# 改为下面这样
permalink:   /article/:title.html

上面这种方式是去掉了年月日,保持网站最多三层。

第二种方式:(推荐)

安装 hexo-abbrlink插件:

npm install hexo-abbrlink --save

配置_config.yml,查找permalink,修改成这样:

# permalink: :title/  将之前的注释掉
permalink: article/:abbrlink.html
abbrlink:
  alg: crc32  # 算法:crc16(default) and crc32
  rep: hex    # 进制:dec(default) and hex

安装后的网址:http://localhost:4000/article/c5f6d65b.html

注意:配置成功需要重新生成文件hexo clean,hexo g,不然会出现undefined的问题,如下:

$ npm install hexo-abbrlink --save
npm WARN babel-eslint@10.0.2 requires a peer of eslint@>= 4.12.1 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ hexo-abbrlink@2.0.5
added 15 packages from 13 contributors and audited 26333 packages in 27.509s
found 21 vulnerabilities (8 low, 6 moderate, 6 high, 1 critical)
  run `npm audit fix` to fix them, or `npm audit` for details

yansheng@MECHREVO MINGW64 /h/Hexo (blog)
$ hexo s
(node:1612) [DEP0061] DeprecationWarning: fs.SyncWriteStream is deprecated.
INFO  Start processing
INFO  Generating Baidu urls for last 100 posts
INFO  Posts urls generated in baidu_urls.txt
https://yansheng836.github.io/archives/undefined.html
https://yansheng836.github.io/archives/undefined.html
https://yansheng836.github.io/archives/undefined.html
https://yansheng836.github.io/archives/undefined.html
https://yansheng836.github.io/archives/undefined.html
https://yansheng836.github.io/archives/undefined.html

INFO  Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.

弊端

其实使用这个也有弊端:

  • 按照原格式,发布后,在github仓库中你能很清楚的看到你写博客的日期,因为是按照网址分文件夹的。使用该插件后就看不到了。
    file

分类和标签路径名英文化

上面我们已经实现将文章的URL简短化和英文化了,但是如果我们的标签和分类有中文,这个插件是控制不了的,

如有个生活的标签,该标签下的所有文章汇总如下:http://localhost:4000/tags/生活/,还是会出现中文,其实这个问题hexo官方自带解决方法,详见:https://hexo.io/zh-cn/docs/configuration.html#%E5%88%86%E7%B1%BB-amp-%E6%A0%87%E7%AD%BE

截个图:
image

站点的配置文件有category_maptag_map配置,即分类和标签的别名(映射),举个例子:

# Category & Tag
default_category: uncategorized
category_map:
    编程: programming
tag_map:
    生活: life

这样标签生活的访问网址为:http://localhost:4000/tags/life/,分类同理。

参考:https://yq.aliyun.com/articles/8607?spm=0.0.0.0.TP5ICj


文章首发于:hexo+yilia添加URL持久化

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值