From d602f00607aa23cf49485637fc88f0484746a80d Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 6 Oct 2023 14:30:48 +0200 Subject: improve vocab table format --- src/main.rs | 54 ++++++++++++++++++++++++------------------------------ static/style.css | 7 +++++++ 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/main.rs b/src/main.rs index 597ebdf..ce352d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1066,36 +1066,15 @@ fn format_batch_aux<'a>( } writeln!(f, "
")?; - writeln!( - f, - r#"
Extra vocabulary (this level)"# - )?; - for v in batch.extra_vocab.iter() { - if batch.level.contains(&v.level) { - writeln!( - f, - r#"

({}) {} [{}] {}

"#, - v.level, v.kanji, v.kana, v.en - )?; - } - } - writeln!(f, r#"
"#)?; - if !batch.level.contains("N4") { - writeln!( - f, - r#"
Extra vocabulary (previous levels)"# - )?; - for v in batch.extra_vocab.iter() { - if !batch.level.contains(&v.level) { - writeln!( - f, - r#"

({}) {} [{}] {}

"#, - v.level, v.kanji, v.kana, v.en - )?; - } - } - writeln!(f, r#"
"#)?; - } + format_vocab( + &mut f, + &batch.extra_vocab.iter().filter(|v| batch.level.contains(&v.level)).collect::>(), + "Extra vocabulary (this level)")?; + format_vocab( + &mut f, + &batch.extra_vocab.iter().filter(|v| !batch.level.contains(&v.level)).collect::>(), + "Extra vocabulary (previous levels)")?; + writeln!(f, "
")?; writeln!(f, "

\(≧▽≦)/

")?; @@ -1104,6 +1083,21 @@ fn format_batch_aux<'a>( Ok(()) } +fn format_vocab(f: &mut impl Write, vocab: &[&JlptVocab], t: &str) -> Result<()> { + if !vocab.is_empty() { + writeln!(f, r#"
{}"#, t)?; + for v in vocab { + writeln!( + f, + r#""#, + v.level, v.kanji, v.en, v.kana + )?; + } + writeln!(f, "
{}  {}  {}{}
")?; + } + Ok(()) +} + fn expl_clean_word(w: &str) -> (&str, Option<&str>) { let mut ret = w; for delim in ['(', '{', '['] { diff --git a/static/style.css b/static/style.css index 384388e..7c26ea0 100644 --- a/static/style.css +++ b/static/style.css @@ -67,3 +67,10 @@ details .chars { .about_page h3:before { content: "➤ "; } + +.vocabtable { + min-width: 50%; + margin: auto; + margin-top: 8px; + margin-bottom: 8px; +} -- cgit v1.2.3