hexo生成的默认文章链接格式是这样的:https://blog.mariojd.cn/2013/07/14/<Markdown file name>/
,这个配置在hexo根目录下的_config.yml
里面:permalink: :year/:month/:day/:title/
,这种默认的配置缺点很明显,当文件名是中文的时候url链接里就有中文出现,看起来low的同时也非常不利于seo优化,下面介绍两种解决方案。
Before
After
在md文件的Front-matter区域新增urlname属性,可以是文章的英文Title也可以是其它自定义标识,所以每次编写Markdown你都得这么做,参考如下:
---
title: 解决百度蜘蛛无法爬取Hexo博客的问题
urlname: solve-the-problem-that-baidu-spider-cannot-crawl-hexo-blog
date: 2018-6-28
categories: hexo
author: Jared Qiu
tags: hexo
cover_picture: http://xxx.xx/xxx.jpg
top: 1
---
在hexo plugins搜索“link”,已经有几个插件可以将url转换成不同的格式(如下),我这里选用了hexo-translate-title
,也是觉得这个比较适合自身风格。
下面简单介绍一下安装操作过程。
// 用cnpm会比较好
npm install hexo-translate-title --save
修改hexo根项目下的_config.yml
,建议用google翻译毕竟贴地气,但实测并不稳定,所以也可以用baidu_no_appid
,这样也不需要额外的认证配置。
translate_title:
translate_way: google # google,youdao,baidu_with_appid,baidu_no_appid
is_need_proxy: false # true | false
# proxy_url: http://localhost:50018 # Your proxy_url
# youdao_api_key: '' # Your youdao_api_key
# youdao_keyfrom: xxxx-blog # Your youdao_keyfrom
# baidu_appid: '' # Your baidu_appid
# baidu_appkey: '' # Your baidu_appkey
# 修改原链接格式:permalink: :year/:month/:day/:title/
permalink: :year:month:day/:translate_title.html
用hexo d
重新生成,留意控制台输出以及public
目录下是否有生成相应的<hexo-translate-title>.html
文件,如果有代表成功了,再用hexo d
部署即可。
按上述流程安装、配置和部署,但生成的链接都是undefined.html,随后给作者提issue,回复后留意hexo g
输出,并且看了源码,用hexo config
查看配置信息后未发现问题,最终定位为Google翻译服务的不稳定。
hexo-translate-title - GitHub hexo-abbrlink介绍 hexo链接持久化终极解决之道 hexo-abbrlink - GitHub