From fff245eaa5db1289a652da41ff7826bd368d7180 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 26 Sep 2023 13:12:26 +0200 Subject: add readme to site; style for batches; order kanji like in sentences --- Cargo.lock | 18 ++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 50 +++++++++++++++++++++++++++++++++++++++++++------- static/style.css | 13 +++++++++++++ 4 files changed, 75 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a3cfa5c..c5b3374 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -118,6 +118,7 @@ name = "datagengo" version = "0.1.0" dependencies = [ "anyhow", + "markdown", "rand", "rayon", "regex", @@ -186,6 +187,17 @@ version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +[[package]] +name = "markdown" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef3aab6a1d529b112695f72beec5ee80e729cb45af58663ec902c8fac764ecdd" +dependencies = [ + "lazy_static", + "pipeline", + "regex", +] + [[package]] name = "memchr" version = "2.6.3" @@ -211,6 +223,12 @@ dependencies = [ "libc", ] +[[package]] +name = "pipeline" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d15b6607fa632996eb8a17c9041cb6071cb75ac057abd45dece578723ea8c7c0" + [[package]] name = "ppv-lite86" version = "0.2.17" diff --git a/Cargo.toml b/Cargo.toml index 915d362..5b31955 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] anyhow = "1.0" +markdown = "0.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" structopt = "0.3" diff --git a/src/main.rs b/src/main.rs index 69e5d6f..06c0a07 100644 --- a/src/main.rs +++ b/src/main.rs @@ -160,6 +160,7 @@ fn main() { let kanji_levels = read_kanji_levels().expect("read_kanji_levels"); format_index(&batches, &kanji_levels).expect("format_index"); + format_about().expect("format_about"); } } } @@ -966,7 +967,7 @@ fn format_batch_aux<'a>( Batch #{:03} - "#, +
"#, i )?; @@ -981,11 +982,20 @@ fn format_batch_aux<'a>( writeln!(f, r#"

"#)?; writeln!(f, "

Level: {}

", batch.level)?; - writeln!( - f, - r#"

【{}】

"#, - batch.chars.to_string() - )?; + write!(f, r#"

"#)?; + let mut ex_prev = Charset::default(); + for ex in batch.examples.iter() { + let ex_chars = ex.chars.inter(&batch.chars); + for c in ex_chars.diff(&ex_prev).chars().iter() { + write!( + f, + r#"{}"#, + c, c + )?; + } + ex_prev = ex_prev.union(&ex_chars); + } + writeln!(f, r#"

"#)?; for ex in batch.examples.iter() { writeln!(f, "
")?; @@ -1079,7 +1089,7 @@ fn format_batch_aux<'a>( writeln!(f, "
")?; writeln!(f, "

\(≧▽≦)/

")?; - write!(f, "")?; + write!(f, "
")?; f.flush()?; Ok(()) } @@ -1135,6 +1145,8 @@ fn format_index(batches: &[Batch], kanji_levels: &[(String, String)]) -> Result< "# )?; + writeln!(f, r#"

About / How-to


"#)?; + writeln!(f, "")?; writeln!(f, "")?; for (i, batch) in batches.iter().enumerate() { @@ -1188,3 +1200,27 @@ fn format_index(batches: &[Batch], kanji_levels: &[(String, String)]) -> Result< f.flush()?; Ok(()) } + +fn format_about() -> Result<()> { + let mut f = io::BufWriter::new(fs::File::create("public/about.html")?); + write!( + f, + r#" + + + + Datagengo README + + + "# + )?; + + writeln!(f, r#"
"#)?; + writeln!(f, r#"

Back to lessons


"#)?; + + writeln!(f, "{}", markdown::to_html(&fs::read_to_string("README.md")?))?; + + writeln!(f, r#"
"#)?; + + Ok(()) +} diff --git a/static/style.css b/static/style.css index 329817f..8721461 100644 --- a/static/style.css +++ b/static/style.css @@ -44,3 +44,16 @@ td { details .chars { font-size: 3rem; } + +.about_page, .batch_page { + max-width: 800px; + margin: auto; + text-align: justify; +} + +.about_page h2 { + border-bottom: 1px solid #aaa; +} +.about_page h3:before { + content: "➤ "; +} -- cgit v1.2.3
NumLevelCharsExamplesB-1B-2Ignore