diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index 69e5d6f..06c0a07 100644 --- a/src/main.rs +++ b/src/main.rs @@ -160,6 +160,7 @@ fn main() { let kanji_levels = read_kanji_levels().expect("read_kanji_levels"); format_index(&batches, &kanji_levels).expect("format_index"); + format_about().expect("format_about"); } } } @@ -966,7 +967,7 @@ fn format_batch_aux<'a>( <title>Batch #{:03}</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> - <body>"#, + <body><div class="batch_page">"#, i )?; @@ -981,11 +982,20 @@ fn format_batch_aux<'a>( writeln!(f, r#"</p>"#)?; writeln!(f, "<p>Level: {}</p>", batch.level)?; - writeln!( - f, - r#"<p class="ja chars">【{}】</p>"#, - batch.chars.to_string() - )?; + write!(f, r#"<p class="ja">"#)?; + let mut ex_prev = Charset::default(); + for ex in batch.examples.iter() { + let ex_chars = ex.chars.inter(&batch.chars); + for c in ex_chars.diff(&ex_prev).chars().iter() { + write!( + f, + r#"<a href="https://jisho.org/search/{}%20%23kanji">{}</a>"#, + c, c + )?; + } + ex_prev = ex_prev.union(&ex_chars); + } + writeln!(f, r#"</p>"#)?; for ex in batch.examples.iter() { writeln!(f, "<hr />")?; @@ -1079,7 +1089,7 @@ fn format_batch_aux<'a>( writeln!(f, "<hr />")?; writeln!(f, "<p>\(≧▽≦)/</p>")?; - write!(f, "</body></html>")?; + write!(f, "<div></body></html>")?; f.flush()?; Ok(()) } @@ -1135,6 +1145,8 @@ fn format_index(batches: &[Batch], kanji_levels: &[(String, String)]) -> Result< <body>"# )?; + writeln!(f, r#"<p><a href="about.html">About / How-to</a></p><hr />"#)?; + writeln!(f, "<table>")?; writeln!(f, "<tr><th>Num</th><th>Level</th><th>Chars</th><th>Examples</th><th>B-1</th><th>B-2</th><th>Ignore</th></tr>")?; for (i, batch) in batches.iter().enumerate() { @@ -1188,3 +1200,27 @@ fn format_index(batches: &[Batch], kanji_levels: &[(String, String)]) -> Result< f.flush()?; Ok(()) } + +fn format_about() -> Result<()> { + let mut f = io::BufWriter::new(fs::File::create("public/about.html")?); + write!( + f, + r#"<!DOCTYPE html> + <html> + <head> + <meta charset=\"UTF-8\" /> + <title>Datagengo README</title> + <link rel="stylesheet" type="text/css" href="style.css" /> + </head> + <body>"# + )?; + + writeln!(f, r#"<div class="about_page">"#)?; + 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, r#"</div></body></html>"#)?; + + Ok(()) +} |