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

相关内容

实现方法

创建 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的子文件夹下

灵感来源

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详细页面中所有包含中文的模版部分