Skip to content

Commit

Permalink
添加中英文语言切换功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunshine40 committed Jun 12, 2024
1 parent 3077475 commit 3a9fcd7
Show file tree
Hide file tree
Showing 7 changed files with 509 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "en"]
path = en
url = https://github.com/rust-lang/nomicon.git
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,26 @@ cargo install mdbook --git https://github.com/Sunshine40/mdBook --branch search-

### `mdBook` 用法

使用 `build` 命令构建《Rust 秘典》_(先确保工作路径位于本项目文件夹根路径)_
为了方便一键构建《Rust 秘典》双语对照版本,建议使用:
_(先确保工作路径位于本项目文件夹根路径)_

```bash
mdbook build
./build.sh
```

构建结果会存放到 `book` 子目录中。用浏览器打开其中的 `index.html` 文件即可查看效果。如果在执行 `./build.sh` 时附带 `--open` 标志,(构建成功后)它就会直接用默认浏览器打开书籍首页,和 `cargo doc --open` 同理:

```bash
./build.sh --open
```

构建结果会存放到 `book` 子目录中。用浏览器打开其中的 `index.html` 文件即可查看效果。如果在执行 `mdbook build` 时附带 `--open` 标志,(构建成功后)它就会直接用默认浏览器打开书籍首页,和 `cargo doc --open` 同理
也可以使用 `mdbook build` 命令单独构建中文版本(构建英文版本需要仿照 `build.sh` 配置参数)

```bash
mdbook build --open
mdbook build
```

还有一个 `test` 子命令用于测试书中包含的所有代码样例:
`mdbook` 还有一个 `test` 子命令用于测试书中包含的所有代码样例:

```bash
mdbook test
Expand All @@ -80,7 +87,7 @@ sh linkcheck.sh --all nomicon-zh-Hans
## 后续规划

- [x] 完成代码中注释的翻译
- [ ] 完成中英文双语版本,支持页内一键切换语言
- [x] 完成中英文双语版本,支持页内一键切换语言
- [ ] 搭建自动发版部署流程
- [ ] 有没有可能支持更新订阅?(RSS?)或者有重要更新时邮件提醒?
- [ ] more(欢迎通过 issue 提出)
13 changes: 9 additions & 4 deletions book.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
[book]
author = ["The Rust Project Developers", "Pure White."]
title = "Rust 秘典(死灵书)"
description = "Unsafe Rust 的黑魔法指南"
language = "zh-hans"
description = "高级 Unsafe Rust 编程的黑科技指南"
language = "zh-Hans"

[output.html]
additional-css = ["theme/nomicon.css"]
additional-css = [
"theme/nomicon.css",
"theme/language-picker.css",
]
git-repository-url = "https://github.com/rust-lang-cn/nomicon-zh-Hans"
search.use-boolean-and = true

[output.html.search]
use-boolean-and = true

[output.html.redirect]
# Vec-related chapters.
Expand Down
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

mdbook build "$@"
MDBOOK_OUTPUT__HTML__THEME=../theme MDBOOK_OUTPUT__HTML__ADDITIONAL_CSS='["../theme/nomicon.css", "../theme/language-picker.css"]' mdbook build en -d ../book/en
1 change: 1 addition & 0 deletions en
Submodule en added at 0ebdac
452 changes: 452 additions & 0 deletions theme/index.hbs

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions theme/language-picker.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#language-list {
left: auto;
right: 10px;
}

[dir="rtl"] #language-list {
left: 10px;
right: auto;
}

#language-list a {
color: inherit;
}

#menu-bar .icon-button-wrapper {
padding: 0;
font: inherit;
}

#menu-bar .theme-popup{
overflow: visible;
}

#menu-bar .theme-link {
display: inline-block;
box-sizing: border-box;
}

0 comments on commit 3a9fcd7

Please sign in to comment.