Build Chinese language user manual (#1219)

This commit is contained in:
Casey Rodarmor 2022-06-08 20:04:06 -05:00 committed by GitHub
parent 89c5e6adb6
commit 97fde19a93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 78 additions and 40 deletions

View File

@ -84,8 +84,10 @@ jobs:
if: ${{ matrix.os == 'ubuntu-latest' }} if: ${{ matrix.os == 'ubuntu-latest' }}
run: | run: |
cargo run --package generate-book cargo run --package generate-book
mdbook build book mdbook build book/en
cp screenshot.png www/man mdbook build book/zh
cp screenshot.png www/man/en
cp screenshot.png www/man/zh
- name: Deploy Pages - name: Deploy Pages
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3

3
.gitignore vendored
View File

@ -1,6 +1,7 @@
/.vagrant /.vagrant
/README.html /README.html
/book/src /book/en/src
/book/zh/src
/fuzz/artifacts /fuzz/artifacts
/fuzz/corpus /fuzz/corpus
/fuzz/target /fuzz/target

View File

@ -23,7 +23,7 @@
`just` is a handy way to save and run project-specific commands. `just` is a handy way to save and run project-specific commands.
This readme is also available as a [book](https://just.systems/man/); This readme is also available as a [book](https://just.systems/man/en/);
(中文文档在 [这里](README.中文.md), 快看过来!) (中文文档在 [这里](README.中文.md), 快看过来!)

View File

@ -23,7 +23,7 @@
`just` 为您提供一种保存和运行项目特有命令的便捷方式。 `just` 为您提供一种保存和运行项目特有命令的便捷方式。
本指南同时也可以以 [](https://just.systems/man/) 的形式提供在线阅读; 本指南同时也可以以 [](https://just.systems/man/zh/) 的形式提供在线阅读;
命令,在此也称为配方,存储在一个名为 `justfile` 的文件中,其语法受 `make` 启发: 命令,在此也称为配方,存储在一个名为 `justfile` 的文件中,其语法受 `make` 启发:

View File

@ -8,11 +8,34 @@ use {
std::{error::Error, fs}, std::{error::Error, fs},
}; };
fn main() -> Result<(), Box<dyn Error>> { enum Language {
fs::remove_dir_all("book/src").ok(); English,
fs::create_dir("book/src")?; Chinese,
}
let txt = fs::read_to_string("README.md")?; impl Language {
fn code(&self) -> &'static str {
match self {
Self::English => "en",
Self::Chinese => "zh",
}
}
fn suffix(&self) -> &'static str {
match self {
Self::English => "",
Self::Chinese => ".中文",
}
}
}
fn main() -> Result<(), Box<dyn Error>> {
for language in [Language::English, Language::Chinese] {
let src = format!("book/{}/src", language.code());
fs::remove_dir_all(&src).ok();
fs::create_dir(&src)?;
let txt = fs::read_to_string(format!("README{}.md", language.suffix()))?;
let mut chapters = vec![(1usize, Vec::new())]; let mut chapters = vec![(1usize, Vec::new())];
@ -35,7 +58,7 @@ fn main() -> Result<(), Box<dyn Error>> {
txt.lines().next().unwrap().split_once(' ').unwrap().1 txt.lines().next().unwrap().split_once(' ').unwrap().1
}; };
let path = format!("book/src/chapter_{}.md", i + 1); let path = format!("{}/chapter_{}.md", src, i + 1);
fs::write(&path, &txt)?; fs::write(&path, &txt)?;
summary.push_str(&format!( summary.push_str(&format!(
"{}- [{}](chapter_{}.md)\n", "{}- [{}](chapter_{}.md)\n",
@ -45,7 +68,8 @@ fn main() -> Result<(), Box<dyn Error>> {
)); ));
} }
fs::write("book/src/SUMMARY.md", summary)?; fs::write(format!("{}/SUMMARY.md", src), summary).unwrap();
}
Ok(()) Ok(())
} }

View File

@ -1,9 +1,8 @@
[book] [book]
authors = ["Casey Rodarmor"] authors = ["Casey Rodarmor"]
language = "en" language = "en"
multilingual = false
src = "src" src = "src"
title = "Just Programmer's Manual" title = "Just Programmer's Manual"
[build] [build]
build-dir = "../www/man" build-dir = "../../www/man/en"

8
book/zh/book.toml Normal file
View File

@ -0,0 +1,8 @@
[book]
authors = ["Casey Rodarmor"]
language = "zh"
src = "src"
title = "Just Programmer's Manual"
[build]
build-dir = "../../www/man/zh"

View File

@ -12,9 +12,13 @@
<div id="s"></div> <div id="s"></div>
<div id="t"></div> <div id="t"></div>
<a href="https://github.com/casey/just">github</a> <a href="https://github.com/casey/just">github</a>
<a href="man/">manual</a> <a href="man/en/">manual</a>
<a href="https://discord.gg/ezYScXR">discord</a> <a href="https://discord.gg/ezYScXR">discord</a>
<a href="https://crates.io/crates/just">crates.io</a> <a href="https://crates.io/crates/just">crates.io</a>
<div></div>
<a href="man/zh/">手冊</a>
<div></div>
<div></div>
</body> </body>
</html> </html>
<!-- Love, Casey --> <!-- Love, Casey -->