aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-09-26 13:12:26 +0200
committerAlex Auvolat <alex@adnab.me>2023-09-26 13:12:26 +0200
commitfff245eaa5db1289a652da41ff7826bd368d7180 (patch)
tree709bfd4ea485a6a95ab9d03d8ebb37477663ddd1
parent9729e8f0ac43516c2c7d25f7e51c46df0be27ab6 (diff)
downloaddatagengo-fff245eaa5db1289a652da41ff7826bd368d7180.tar.gz
datagengo-fff245eaa5db1289a652da41ff7826bd368d7180.zip
add readme to site; style for batches; order kanji like in sentences
-rw-r--r--Cargo.lock18
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs50
-rw-r--r--static/style.css13
4 files changed, 75 insertions, 7 deletions
diff --git a/Cargo.lock b/Cargo.lock
index a3cfa5c..c5b3374 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -118,6 +118,7 @@ name = "datagengo"
version = "0.1.0"
dependencies = [
"anyhow",
+ "markdown",
"rand",
"rayon",
"regex",
@@ -187,6 +188,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
[[package]]
+name = "markdown"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ef3aab6a1d529b112695f72beec5ee80e729cb45af58663ec902c8fac764ecdd"
+dependencies = [
+ "lazy_static",
+ "pipeline",
+ "regex",
+]
+
+[[package]]
name = "memchr"
version = "2.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -212,6 +224,12 @@ dependencies = [
]
[[package]]
+name = "pipeline"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d15b6607fa632996eb8a17c9041cb6071cb75ac057abd45dece578723ea8c7c0"
+
+[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 915d362..5b31955 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,6 +7,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0"
+markdown = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
structopt = "0.3"
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(())
+}
diff --git a/static/style.css b/static/style.css
index 329817f..8721461 100644
--- a/static/style.css
+++ b/static/style.css
@@ -44,3 +44,16 @@ td {
details .chars {
font-size: 3rem;
}
+
+.about_page, .batch_page {
+ max-width: 800px;
+ margin: auto;
+ text-align: justify;
+}
+
+.about_page h2 {
+ border-bottom: 1px solid #aaa;
+}
+.about_page h3:before {
+ content: "➤ ";
+}