Hexo Blog Setup: How to Support Multilingual Switching
Introduction
- Why Support Multiple Languages: To reach a broader user base. Although the internet theoretically connects people worldwide, most individuals instinctively cluster around their native languages. English and Chinese are the two most widely used languages globally, so support for these two languages is prioritized.
- This document is part of the Hexo blog setup guide series, version 1.4, which mainly introduces the configuration and optimization plan for the Hexo blog using the Butterfly theme that supports language switching. The entire blog setup guide series can be found at: Hexo Blog Setup Guide: Systematic Solutions and Detailed Construction Process.
- Overall Plan:
- Hexo blog using the Butterfly theme.
- The Chinese and English blogs are set up as two independent projects:
- Chinese blog: my-hexo-blog-cn; English blog: my-hexo-blog-en.
- Benefits: mutual backup; simplified management, reducing interference between Chinese and English versions.
- The Chinese and English blogs are constructed as subdirectories rather than subdomains, which helps consolidate their search weight.
- Refer to Hexo Blog Setup Guide: Systematic Solutions and Detailed Construction Process for an overall understanding of the current multi-language plan, as shown below:

Overall Process:

Explanation:
- The overall process includes three stages: preparation, multi-language configuration support, and additional optimizations, comprising four modules: local Hexo - Chinese blog, local Hexo - English blog, GitHub, Cloudflare.
- Use the “Switch language” feature to toggle between the Chinese and English blogs by adding or removing the /en/ prefix in the address bar.
- Since the blog can only be deployed to Cloudflare Pages at the root directory, a Cloudflare worker is required to implement subdirectory deployment. The free quota is 100,000 requests per day, which is generally sufficient during language switching.
Preparation
Setting Up and Deploying the Chinese Blog
- Build and deploy the blog from scratch. Refer to versions 1.0, 1.1, and 1.2 of this blog series for details: Hexo Blog Setup Guide: Systematic Solutions and Detailed Construction Process.
Setting Up and Deploying the English Blog
- The process for setting up and deploying the English blog is similar to that of the Chinese blog.
- Notes:
- The GitHub repository name for the English blog should be /en/.
Multi-Language Configuration Support
Local Configuration for Chinese Blog
Configuration of hexo’s config file
1 | # Set basic URL and root directory for the website |
Configuration of _config.butterfly.yml file
- Add a language switch button to the navigation bar.
1 | menu: # Navigation menu names |
Adding Switch Language Logic
- Add the following code to layout.pug (my-hexo-blog-cn/themes/butterfly/layout/includes/layout.pug):
1 | - var globalPageType = getPageType(page, is_home) |
Local Configuration for English Blog
Configuration of hexo’s config file
1 | # Set basic URL and root directory for the website |
Configuration of _config.butterfly.yml file
1 | menu: # Navigation menu names |
Adding Switch Language Logic
- Add Switch language logic in layout.pug (my-hexo-blog-en/themes/butterfly/layout/includes/layout.pug), with code similar to that in the Chinese blog.
New no-match.md File
- Purpose: When switching from Chinese to English, if no corresponding content exists, redirect to no-match first, then use Cloudflare worker to redirect to the English blog homepage.
- Content of no-match (my-blog/my-hexo-blog-en/source/no-match.md):
1 | --- |
Cloudflare Worker Configuration for English Blog
Worker Code Configuration
- Log in to Cloudflare Dashboard and create a new Worker in the “Workers & Pages” section.
- Use the following code to proxy requests starting with
/en/to the English blog project:
1 | addEventListener('fetch', event => { |
Binding Worker to Main Domain
- Log in to Cloudflare Dashboard.
- Go to Workers & Pages.
- In the left menu, select Workers & Pages.
- Find your newly created Worker (e.g., for multi-language proxy).
- Configure worker routing rules:
- Domain: dmindie.com
- Route:
blog.dmindie.com/en* - Fallback mode: Open automatically on failure.

Deployment Preview
- After modifying both versions of the blog, deploy them to GitHub Pages and Cloudflare.
- Open a browser and visit both versions of the blog:
https://blog.dmindie.com/https://blog.dmindie.com/en
With these configurations in place, you can freely switch between languages on key pages such as home, categories, tags, archives, about, and links.
Multi-Language Optimization Support
Supporting Multi-Language Switching for Posts
Keeping Permalink Consistent
To facilitate quick switching between Chinese and English posts on blogs, ensure that their URLs remain consistent except for the difference in prefixes (/en/) in permalinks:
- Chinese post URL example: https://blog.dmindie.com/p/start-indie-hacker-journey/
- English post URL example: https://blog.dmindie.com/en/p/start-indie-hacker-journey/
Implementation Steps
- Notion configuration: Both Chinese and English versions of Notion databases should include a field named
urlname. - Elog configuration: Configure synchronization rules by adding
urlnamefield in elog.config.js:
1 | module.exports = { |
- For details on syncing Notion content with Hexo blogs using Elog, refer to Hexo Blog Setup Guide via Elog Syncing Notion Content.
- Verify results by checking how articles switch between their Chinese and English versions.
SEO Optimization Based on Hreflang Tags
Adding Hreflang Tags
For the Chinese blog in head.pug (projects/my-blog/my-hexo-blog-cn/themes/butterfly/layout/includes/head.pug), add:
1 | // Add hreflang tags |
For the English blog in head.pug (projects/my-blog/my-hexo-blog-en/themes/butterfly/layout/includes/head.pug), add:
1 | // Add hreflang tags |
Other Multi-Language Solutions
Simplified Multi-Language Deployment Only on GitHub Pages
Deployment Plan Adjustments
- The first version of the blog will be deployed at GitHub Pages root directory.
- Remaining versions will be deployed in subdirectories under GitHub Pages since multiple versions are automatically deployed into subdirectories there.
- No longer deploy on Cloudflare Pages.
Adjusting Switch Language Logic
The config files for hexo and _config.butterfly.yml will remain consistent with previous plans.
For both Chinese and English projects within layout.pug (my-hexo-blog-cn/themes/butterfly/layout/includes/layout.pug) and layout.pug (my-hexo-blog-en/themes/butterfly/layout/includes/layout.pug), add Switch language logic as follows:
1 | - var globalPageType = getPageType(page, is_home) |
Conclusion
With these configurations completed, anyone can set up a Hexo blog that supports multi-language switching effectively. Moving forward based on this multi-language solution will lead to further optimizations along with continuous updates of this article’s content.
If you have better solutions or ideas, please feel free to share them with us; we will continue updating this article to keep its content current and optimal.