Hexo,添加标题翻译插件
文章背景
hexo生成的默认文章链接格式是这样的:https://blog.mariojd.cn/2013/07/14/
方案一:添加urlname属性(手动)
在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: jiuyang
tags: hexo
cover_picture: http://xxx.xx/xxx.jpg
top: 1
---
方案二:利用hexo插件(自动)
在hexo plugins搜索link,已经有几个插件可以将url转换成不同的格式(如下),我这里选用了hexo-translate-title,也是觉得这个比较适合自身风格。
hexo-translate-title: Translate the chinese title of Hexo blog to english words automatially
hexo-permalink-pinyin: A Hexo plugin which convert Chinese title to transliterate permalink.
hexo-abbrlink: Auto create one and only link for every post for hexo
hexo-number-title: The hexo blog post url is displayed as a number.
下面简单介绍一下安装操作过程。
安装
// 用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翻译服务的不稳定。

浙公网安备 33010602011771号