diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 59 |
1 files changed, 43 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs index 8668a82..9e08418 100644 --- a/src/main.rs +++ b/src/main.rs @@ -989,7 +989,8 @@ fn add_examples(all_batches: &mut [Batch], examples: &[Example]) { for (i, batch) in all_batches.iter_mut().enumerate() { chars = chars.union(&batch.chars); - let candidates = examples.iter() + let candidates = examples + .iter() .filter(|x| x.chars.inter_len(&batch.chars) > 0) .filter(|x| x.chars.diff(&chars).len() == 0) .filter(|x| batch.examples.iter().all(|y| y.ja != x.ja)); @@ -997,12 +998,14 @@ fn add_examples(all_batches: &mut [Batch], examples: &[Example]) { for c in candidates { cand_by_chars.insert(c.chars.to_string(), c.clone()); } - let mut candidates = cand_by_chars.into_iter().map(|(_, ex)| ex).collect::<Vec<_>>(); + let mut candidates = cand_by_chars + .into_iter() + .map(|(_, ex)| ex) + .collect::<Vec<_>>(); candidates.shuffle(&mut thread_rng()); candidates.truncate(20); batch.extra_examples = candidates; - println!("---- BATCH #{:03} ----", i); for ex in batch.extra_examples.iter() { println!("{} - {}", ex.ja, ex.en); @@ -1125,20 +1128,33 @@ fn format_batch_aux<'a>( writeln!(f, "<hr />")?; format_vocab( &mut f, - &batch.extra_vocab.iter().filter(|v| batch.level.contains(&v.level)).collect::<Vec<_>>(), - "Extra vocabulary (this level)")?; + &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)")?; + &batch + .extra_vocab + .iter() + .filter(|v| !batch.level.contains(&v.level)) + .collect::<Vec<_>>(), + "Extra vocabulary (previous levels)", + )?; - writeln!(f, r#"<details><summary>Extra examples (reading practice)</summary><table class="extratable">"#)?; + writeln!( + f, + r#"<details><summary>Extra examples (reading practice)</summary><table class="extratable">"# + )?; for ex in batch.extra_examples.iter() { - writeln!( - f, - r#"<tr><td style="text-align: center"><span style="font-size: 1.2em"> {} </span><br />{}</td></tr>"#, - ex.ja, ex.en - )?; + writeln!( + f, + r#"<tr><td style="text-align: center"><span style="font-size: 1.2em"> {} </span><br />{}</td></tr>"#, + ex.ja, ex.en + )?; } writeln!(f, r#"</table></details>"#)?; @@ -1152,7 +1168,11 @@ fn format_batch_aux<'a>( 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)?; + writeln!( + f, + r#"<details><summary>{}</summary><table class="vocabtable">"#, + t + )?; for v in vocab { writeln!( f, @@ -1287,9 +1307,16 @@ fn format_about() -> Result<()> { )?; writeln!(f, r#"<div class="about_page">"#)?; - writeln!(f, r#"<p><a href="index.html">Back to lessons</a></p><hr />"#)?; + writeln!( + f, + r#"<p><a href="index.html">Back to lessons</a></p><hr />"# + )?; - writeln!(f, "{}", markdown::to_html(&fs::read_to_string("README.md")?))?; + writeln!( + f, + "{}", + markdown::to_html(&fs::read_to_string("README.md")?) + )?; writeln!(f, r#"</div></body></html>"#)?; |