diff --git a/Cargo.lock b/Cargo.lock index 4a5210b..f5bee1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -72,6 +72,61 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[package]] +name = "askama" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b79091df18a97caea757e28cd2d5fda49c6cd4bd01ddffd7ff01ace0c0ad2c28" +dependencies = [ + "askama_derive", + "askama_escape", + "humansize", + "num-traits", + "percent-encoding", +] + +[[package]] +name = "askama_axum" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a41603f7cdbf5ac4af60760f17253eb6adf6ec5b6f14a7ed830cf687d375f163" +dependencies = [ + "askama", + "axum-core 0.4.1", + "http 1.0.0", +] + +[[package]] +name = "askama_derive" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a0fc7dcf8bd4ead96b1d36b41df47c14beedf7b0301fc543d8f2384e66a2ec0" +dependencies = [ + "askama_parser", + "basic-toml", + "mime", + "mime_guess", + "proc-macro2", + "quote", + "serde", + "syn 2.0.39", +] + +[[package]] +name = "askama_escape" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" + +[[package]] +name = "askama_parser" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c268a96e01a4c47c8c5c2472aaa570707e006a875ea63e819f75474ceedaf7b4" +dependencies = [ + "nom", +] + [[package]] name = "async-stream" version = "0.3.5" @@ -293,6 +348,15 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "basic-toml" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f2139706359229bfa8f19142ac1155b4b80beafb7a60471ac5dd109d4a19778" +dependencies = [ + "serde", +] + [[package]] name = "bit_field" version = "0.10.2" @@ -360,6 +424,8 @@ dependencies = [ name = "cch23-8bit" version = "0.1.0" dependencies = [ + "askama", + "askama_axum", "axum 0.7.2", "axum-extra", "base64", @@ -1152,6 +1218,15 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "humansize" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7" +dependencies = [ + "libm", +] + [[package]] name = "hyper" version = "0.14.27" diff --git a/Cargo.toml b/Cargo.toml index 508b4c2..f4bbdc9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" edition = "2021" [dependencies] +askama = { version = "0.12.1", features = ["with-axum"] } +askama_axum = "0.4.0" axum = { version = "0.7.2", features = ["macros", "multipart"] } axum-extra = { version = "0.9.0", features = ["typed-header"] } base64 = "0.21.5" diff --git a/askama.toml b/askama.toml new file mode 100644 index 0000000..09b17df --- /dev/null +++ b/askama.toml @@ -0,0 +1,2 @@ +[general] +dirs = ["src/assets"] diff --git a/src/assets/day14/index.html b/src/assets/day14/index.html new file mode 100644 index 0000000..512acc3 --- /dev/null +++ b/src/assets/day14/index.html @@ -0,0 +1,8 @@ + + + CCH23 Day 14 + + + {{ content }} + + \ No newline at end of file diff --git a/src/cal/day14.rs b/src/cal/day14.rs new file mode 100644 index 0000000..4c878af --- /dev/null +++ b/src/cal/day14.rs @@ -0,0 +1,37 @@ +use axum::{response::IntoResponse, routing::post, Json, Router}; + +pub(crate) fn router() -> Router { + Router::new() + .route("/14/unsafe", post(unsafefn)) + .route("/14/safe", post(safefn)) +} + +#[derive(serde::Deserialize)] +struct Content { + content: String, +} + +#[derive(askama::Template)] +#[template(path = "day14/index.html", escape = "none")] +struct UnsafeTemplate { + content: String, +} + +async fn unsafefn(Json(content): Json) -> impl IntoResponse { + UnsafeTemplate { + content: content.content, + } +} + +#[derive(askama::Template)] +#[template(path = "day14/index.html")] +struct SafeTemplate { + content: String, +} + +#[axum::debug_handler] +async fn safefn(Json(content): Json) -> impl IntoResponse { + SafeTemplate { + content: content.content, + } +} diff --git a/src/cal/mod.rs b/src/cal/mod.rs index 19b86c6..8edecbe 100644 --- a/src/cal/mod.rs +++ b/src/cal/mod.rs @@ -7,6 +7,7 @@ mod day08; mod day11; mod day12; mod day13; +mod day14; pub(crate) fn router(pool: sqlx::PgPool) -> axum::Router { axum::Router::new() @@ -19,4 +20,5 @@ pub(crate) fn router(pool: sqlx::PgPool) -> axum::Router { .nest("/", day11::router()) .nest("/", day12::router()) .nest("/", day13::router(pool)) + .nest("/", day14::router()) }