diff options
author | Alex Auvolat <alex@adnab.me> | 2024-03-15 16:41:14 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2024-03-15 16:49:31 +0100 |
commit | 32dccce54d58e81ea16463321b1a54de9371c555 (patch) | |
tree | 40f24f46609dd1f21e9d91ee28247fa174638d7b /src | |
parent | 6150eba66beb96d03a3e2af839737e3ef4c0a086 (diff) | |
download | datagengo-32dccce54d58e81ea16463321b1a54de9371c555.tar.gz datagengo-32dccce54d58e81ea16463321b1a54de9371c555.zip |
add backlinks to kanji in generated practice
Diffstat (limited to 'src')
-rw-r--r-- | src/server.rs | 41 |
1 files changed, 41 insertions, 0 deletions
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<State>) -> tide::Result { </div> <div id="gen_ex_words" class="vocabtable"> </div> + <div id="gen_ex_kanji" class="vocabtable"> + </div> </div> </div> </body> @@ -261,11 +263,50 @@ async fn gen_examples_page(mut req: Request<State>) -> tide::Result { } } + let mut kanji = "<table>".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::<Vec<_>>(), + ) + }) + .collect::<Vec<_>>(); + 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#"<tr><td class="tab_large font_ja">{} "#, chr); + } else { + kanji += &format!(r#"<tr><td>"#); + } + kanji += &format!( + r#"</td><td><a href="{:03}.html">{:03}</a> </td><td class="tab_large font_ja">{}</td></tr>"#, + ib, ib, ex.ja + ); + } + } + let item = serde_json::json!({ "ja": ex.ja, "en": ex.en, "furi": ex.furigana_markup(), "vocab": expl + "</table>", + "kanji": kanji + "</table>", }); tx.send_blocking(Ok(format!( "<script> add_example({}); </script>\n", |