diff options
-rw-r--r-- | src/main.rs | 54 | ||||
-rw-r--r-- | 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, "<hr />")?; - writeln!( - f, - r#"<details><summary>Extra vocabulary (this level)</summary>"# - )?; - for v in batch.extra_vocab.iter() { - if batch.level.contains(&v.level) { - writeln!( - f, - r#"<p>({}) {} [{}] {}</p>"#, - v.level, v.kanji, v.kana, v.en - )?; - } - } - writeln!(f, r#"</details>"#)?; - if !batch.level.contains("N4") { - writeln!( - f, - r#"<details><summary>Extra vocabulary (previous levels)</summary>"# - )?; - for v in batch.extra_vocab.iter() { - if !batch.level.contains(&v.level) { - writeln!( - f, - r#"<p>({}) {} [{}] {}</p>"#, - v.level, v.kanji, v.kana, v.en - )?; - } - } - writeln!(f, r#"</details>"#)?; - } + format_vocab( + &mut f, + &batch.extra_vocab.iter().filter(|v| batch.level.contains(&v.level)).collect::<Vec<_>>(), + "Extra vocabulary (this level)")?; + format_vocab( + &mut f, + &batch.extra_vocab.iter().filter(|v| !batch.level.contains(&v.level)).collect::<Vec<_>>(), + "Extra vocabulary (previous levels)")?; + writeln!(f, "<hr />")?; writeln!(f, "<p>\(≧▽≦)/</p>")?; @@ -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#"<details><summary>{}</summary><table class="vocabtable">"#, t)?; + for v in vocab { + writeln!( + f, + r#"<tr><td>{}</td><td> <span style="font-size: 1.2em">{}</span> </td><td>{}</td><td>{}</td></tr>"#, + v.level, v.kanji, v.en, v.kana + )?; + } + writeln!(f, "</table></details>")?; + } + 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; +} |