Hexo多语言解决方案实践记录

多语言选择

有什么用

这个自定义方案结合了:

1、利用hexo-generator-i18n插件,在文章中加入lang标识来区分,然后在渲染的时候在利用模版程序判断生成

2、直接部署两套Hexo,上传到不同的库当中,然后页面上添加手动切换

怎么用

cd ~/AppTesting/blog && hexo clean && hexo g && cd ~/AppTesting/article_en && hexo clean && hexo g && cd ~/AppTesting/blog && cp -r ~/AppTesting/article_en/public/. ~/AppTesting/blog/public/en/ && HTTPS_PROXY=”socks5://127.0.0.1:7890” hexo d

是的,浓缩起来就是上面这段命令,实现多语言版发布hexo到github服务器上

1
cd ~/AppTesting/blog && hexo clean && hexo g && cd ~/AppTesting/article_en && hexo clean && hexo g && cd ~/AppTesting/blog && cp -r ~/AppTesting/article_en/public/. ~/AppTesting/blog/public/en/ && HTTPS_PROXY="socks5://127.0.0.1:7890" hexo d

相关内容

实现方法

创建 Github Workflow

简单解释一下,当我们推送内容到远程 master 分支的时候,就会触发这个 Workflow。

我的发布都是直接 hexo d的,没有额外/单独有git push的动作。

利用skip_render排除不同的文件

source/_posts下面新建两个文件cnen里面放中文和英文的文章,然后在系统配置文件当中利用skip_render来区分:

_config.yml里面

1
2
skip_render:
- _posts/en/**

_config_en.yml

1
2
skip_render:
- _posts/cn/**

先实现,手动的把两个目录下生成的md文件;都上传到两个不同的github repository

11:27am 如何让不同的文件夹下的md 生成到不同的目标文件夹中去?

实现了article_en下独立的hexo的运行

复制出一个article_en文件夹下的内容之后:

1
rm -rf node_modules && npm install      

下一步deploy流程(单命令实现)

cd ~/AppTesting/blog && hexo clean && hexo g &&cd ~/AppTesting/article_en && hexo clean && hexo g && cd ~/AppTesting/blog && cp -r ~/AppTesting/article_en/public/. ~/AppTesting/blog/public/en/ && hexo d

1
2
3
4
目录结构:
AppTesting
- blog
- article_en

需要一个node的程序,或接口,可以简易的把blog下的某个.md文件全文翻译成英语(或其他语言),然后将生成的心的文件放到article_en的子文件夹下

命令运行异常处理

这种git在push到远程服务器上的错误,一般就是因为天朝网络的特殊性来不可把控的

1
2
3
4
5
6
7
 create mode 100644 "tags/\346\221\207\346\235\206/index.html"
fatal: unable to access 'https://github.com/chuanzhuo/blog.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
Error: Spawn failed
at ChildProcess.<anonymous> (/Users/@@@@/blog/node_modules/hexo-util/lib/spawn.js:51:21)
at ChildProcess.emit (node:events:514:28)
at ChildProcess._handle.onexit (node:internal/child_process:294:12)

解决办法:

搭配浏览器的插件,测试socks5://127.0.0.1:7890的可用性(比如打开google网址等)

确保服务的实时有效性,然后执行:

1
hexo deploy

类似的输出是这样的

image-20240611163943966

灵感来源

https://www.igerm.ee/experience/%E5%AE%8C%E7%BE%8E%E7%9A%84Hexo%E5%A4%9A%E8%AF%AD%E8%A8%80%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88


https://github.com/CrazyMayfly/Free-Markdown-Translator/tree/master

如何让python的运行在有proxy的状态下?

又下载测试了这个方案:https://github.com/soimort/translate-shell
homebrew下了半天,运行 翻译,也是无效了。

还是用自己架设的chat gpt吧;
复制黏贴回车,在复制结果,粘贴进Typora;
格式还都保留了(html也保留了,很漂亮)

cd ~/AppTesting/blog && hexo clean && hexo g &&cd ~/AppTesting/article_en && hexo clean && hexo g && cd ~/AppTesting/blog && cp -r ~/AppTesting/article_en/public/. ~/AppTesting/blog/public/en/ && hexo d

目录结构
AppTesting
    - blog
    - article_en

Updates:
en站的footer
把hexo-server/index.js改到本地4001端口,这样两个站点可以同时打开调试。
post详细页面中所有包含中文的模版部分