中英双语更显专业

本博客采用 butterfly 作为主题,相当美观,官方的示例也是中英双语的,但在设置中没有找到相关的配置。不过,找到了官方的一个demo,其中是对中英双语的文件分别进行了配置,有两个配置文件,编译两次,在此基础上,进一步优化了一下,方便部署。

双语内容

source目录下的_posts文件夹中放置中英双语的文件,其中命名需要规范:

  1. 中文文件名:myblog_with_both_zh_en-zh.md
  2. 英文文件名:myblog_with_both_zh_en-en.md
    基于后缀的不同进行区分,这也是后续编译用于区分

“双”主题

  1. themes目录下,创建一个名为butterfly-en的主题,其实就是butterfly主题的复制
  2. 准备两个主题配置文件:_config.butterfly-en.yml_config.butterfly.yml,也就分别对应了两个主题
  3. 之所以这样是因为在生成index.html页面时,顶部状态栏的中英区分,两个文件中的顶部栏内容分别如下:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    # _config.butterfly.yml
    menu:
    主页: / || fas fa-home
    研究: /researchs || fas fa-flask
    目录 || fa-solid fa-compass:
    归档: /archives/ || fas fa-archive
    标签: /tags/ || fas fa-tags
    分类: /categories/ || fas fa-folder-open
    # List||fas fa-list:
    # Music: /music/ || fas fa-music
    # Movie: /movies/ || fas fa-video
    # Link: /link/ || fas fa-link
    # About: /about/ || fas fa-heart
    语言||fas fa-language:
    English: /en/ || fas fa-e
    中文: / || fas fa-c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# _config.butterfly-en.yml
menu:
Home: / || fas fa-home
Research: /researchs || fas fa-flask
Docs || fa-solid fa-compass:
archives: /archives/ || fas fa-archive
tags: /tags/ || fas fa-tags
categories: /categories/ || fas fa-folder-open
# List||fas fa-list:
# Music: /music/ || fas fa-music
# Movie: /movies/ || fas fa-video
# Link: /link/ || fas fa-link
# About: /about/ || fas fa-heart
Language || fas fa-language:
English: /en/ || fas fa-e
中文: /../ || fas fa-c
# 注意这里,用了静态的向上跳转,之所以这样是因为英文页面的root是/en/,只有这样能跳转到上级的中文页面

双配置

  1. _config.yml中,添加配置修改如下:

    1
    2
    3
    4
    5
    6
    language: zh-CN
    root: /
    permalink: posts/:title/
    ignore:
    - "**/*-en.md" #忽略英文文件
    theme: butterfly
  2. config-en.yml中,添加配置修改如下:

    1
    2
    3
    4
    5
    6
    7
    language: en
    root: /en/
    permalink: posts/:title/
    public_dir: public/en # 直接生成输出到位,省去后续再次移动
    ignore:
    - "**/*-zh.md" # 忽略中文文件
    theme: butterfly-en

编译

编译时,需要将config-en.yml_config.yml进行切换,编译两次
集成后的脚本:

1
2
3
4
hexo clean
hexo gen
hexo gen --config config-en.yml
hexo depl