Immersive Multilingual Hexo Blog Based On Nginx

Table of Content
  1. 1. Immersive Mutilingual Hexo Blog
  2. 2. Try One by One
    1. 2.1. Hexo official internationalization: failed
    2. 2.2. hexo-generator-i18n plugin: failed
    3. 2.3. hexo-multilingual: failed
  3. 3. Nginx Location Alias:bingo
    1. 3.1. Set up two blogs
    2. 3.2. Nginx Configuration
    3. 3.3. Final Preview
  4. 4. Conclusion

Immersive Mutilingual Hexo Blog

I did a little improvement on my blog during Dragon Boat Festival. One of the purposes: multilingual support(mainly English / Chinese), requirement:immersive reading

After reseaching, i found the following tools about Hexo internationalization:

Try One by One

Hexo official internationalization: failed

It’s mainly to meet template multi-language requirement

hexo-generator-i18n plugin: failed

Add configuration in _config.yml, to generate multi-language folder,

1
2
3
i18n:
type: [page, post]
generator: [index, archive, category, tag]

The biggest problem is the blogs belong to different language will mix together, can not read the goal: immersive reading.

hexo-multilingual: failed

Change hexo blog package.json dependencies from:

1
2
3
"hexo-generator-archive": "^0.1.4",
"hexo-generator-category": "^0.1.3",
"hexo-generator-index": "^0.2.0",

to customized generators:

1
2
3
"hexo-generator-multilingual-archive": "^0.2.0",
"hexo-generator-multilingual-category": "^0.3.2",
"hexo-generator-multilingual-index": "^0.3.1",

The plugin will consider language information in the generated pages. By adding the configuration files as follows, the plugin will override configuration of different language, such as title, subtitle, etc.

1
2
3
4
5
6
7
8
9
├── source
│   ├── _data
│   │   ├── config_cn.yml
│   │   ├── config_en.yml
│   │   ├── theme_cn.yml
│   │   └── theme_en.yml
│   ├── _posts
│   │   ├── cn
│   │   └── en

config_xx.yml will override the root configuration file: _config ,

theme_xx.yml will override the theme configuration file: themes/your-theme/_config.

The custumized generators and overrided configuration file can meat part of the immersive reading requirement, except for the following critical bugs:

When i run:

1
hexo server

The languages will be seperated well, however, when i run:

1
hexo g

the generated public folder and it’s files has following problems:

  • Some link is not considering language, this will lead to dead link
  • Configuration override failed, screw up
  • Other hexo plugins, such as hexo-generator-sitemap, rely on the single language principle, then they all fail in this circumstance, oh no!

Personally won’t give too much time on this stuff.

Nginx Location Alias:bingo

My blog is using static files generated by Hexo and Nginx as reverse proxy. I remember here i can take advantage of alias for the different location: en/cn.

General Ideas:

  • Set up multiple (two) independent blogs, each handle the post and theme of one language
  • Use Nginx to acchive location dispatch

The final solution:

Set up two blogs

1
2
├── kvh.io.cn
├── kvh.io.en

Config the blogs, the critical part of root _config will be:

1
2
3
language: 
- cn
root: /cn

and

1
2
3
language: 
- en
root: /en

Then you can write your post and decorate your theme as you wish.

Nginx Configuration

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
server {

root /home/changbinhe/kvh.io.cn/public;

location /cn {
alias /www/kvh.io.cn/public;
}

location /en {
alias /www/kvh.io.en/public;
}

error_page 404 = @missing;

location @missing {
rewrite .* / permanent;
}
}

Please refer tonginx-offical-docs if you are interested in this rule.

Final Preview

checkout my blog:http://kvh.io/en

Conclusion

This artical describes a workaround to set up immersive multilingual hexo blog, by setting up multiple Hexo blogs, and using Nginx to dispatch visitting to different alias.

Related Articles

No related post.