From 32dccce54d58e81ea16463321b1a54de9371c555 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 15 Mar 2024 16:41:14 +0100 Subject: add backlinks to kanji in generated practice --- src/server.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src') diff --git a/src/server.rs b/src/server.rs index 774cff4..5e5d61b 100644 --- a/src/server.rs +++ b/src/server.rs @@ -211,6 +211,8 @@ async fn gen_examples_page(mut req: Request) -> tide::Result {
+
+
@@ -261,11 +263,50 @@ async fn gen_examples_page(mut req: Request) -> tide::Result { } } + let mut kanji = "".to_string(); + let mut chrvec = ex + .chars + .iter() + .map(|chr| { + ( + chr, + req.state() + .batches + .iter() + .take(last_level + 1) + .enumerate() + .flat_map(|(ib, b)| { + b.examples + .iter() + .filter(|ex| ex.chars.contains(chr)) + .map(move |ex| (ib, ex)) + }) + .collect::>(), + ) + }) + .collect::>(); + chrvec.sort_by_key(|(_, exs)| exs.len()); + for (chr, exs) in chrvec.iter().take(5) { + for (cnt, (ib, ex)) in exs.iter().enumerate().take(4) { + if cnt == 0 { + kanji += + &format!(r#""#, + ib, ib, ex.ja + ); + } + } + let item = serde_json::json!({ "ja": ex.ja, "en": ex.en, "furi": ex.furigana_markup(), "vocab": expl + "
{}  "#, chr); + } else { + kanji += &format!(r#"
"#); + } + kanji += &format!( + r#"{:03}  {}
", + "kanji": kanji + "", }); tx.send_blocking(Ok(format!( "\n", -- cgit v1.2.3