Hexo Blogging in Both Chinese and English
Bilingualism Makes a Blog More Professional
This blog uses butterfly as its theme, which is quite aesthetically pleasing. The official example is also bilingual, but there is no relevant configuration found in the settings. However, I found an official demo that individually configures files for both languages and compiles them twice. Based on this, I have further optimized it for easier deployment.
Bilingual Content
Place bilingual files in the _posts directory under the source directory. The naming convention must be standardized:
- Chinese filename:
myblog_with_both_zh_en-zh.md - English filename:
myblog_with_both_zh_en-en.md
Differentiation is made based on the suffix, which is also used for subsequent compilation.
"Dual" Themes
- Under the
themesdirectory, create a theme namedbutterfly-en, which is essentially a copy of thebutterflytheme. - Prepare two theme configuration files:
_config.butterfly-en.ymland_config.butterfly.yml, corresponding to the two themes respectively. - This is done because when generating the
index.htmlpage, the top status bar needs to be distinguished in Chinese and English. The content of the top bar in the two files is as follows:
1 | # _config.butterfly.yml |
1 | # _config.butterfly-en.yml |
Dual Configuration
In
_config.yml, add the following configuration changes:1
2
3
4
5
6language: zh-CN
root: /
permalink: posts/:title/
ignore:
- "**/*-en.md" # Ignore English files
theme: butterflyIn
config-en.yml, add the following configuration changes:1
2
3
4
5
6
7language: en
root: /en/
permalink: posts/:title/
public_dir: public/en # Directly generate output to the position, saving the subsequent move
ignore:
- "**/*-zh.md" # Ignore Chinese files
theme: butterfly-en
Compilation
When compiling, you need to switch between config-en.yml and _config.yml and compile twice.
Integrated script:
1 | hexo clean |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
