From 888359fead247780024ccbed421685bbe970cdf5 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Tue, 7 May 2024 21:23:36 -0500 Subject: [PATCH] Templates! --- Cargo.lock | 14 ++++++++++++++ Cargo.toml | 2 +- pages/index.html.jinja | 7 +++++++ src/main.rs | 8 ++++---- templates/{page.html => page.html.jinja} | 1 + 5 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 pages/index.html.jinja rename templates/{page.html => page.html.jinja} (85%) diff --git a/Cargo.lock b/Cargo.lock index 3a92c16..9009c1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -788,6 +788,12 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +[[package]] +name = "memo-map" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "374c335b2df19e62d4cb323103473cbc6510980253119180de862d89184f6a83" + [[package]] name = "mime" version = "0.3.17" @@ -810,6 +816,8 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7165d0e94806d52ad5295e4b54a95176d831814840bc067298ca647e1c956338" dependencies = [ + "memo-map", + "self_cell", "serde", ] @@ -1216,6 +1224,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "self_cell" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a" + [[package]] name = "serde" version = "1.0.200" diff --git a/Cargo.toml b/Cargo.toml index d60806f..b1bc9d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ axum = { version = "0.7.5", features = ["macros", "tokio"] } color-eyre = "0.6.3" config = "0.14.0" futures = "0.3.30" -minijinja = "2.0.1" +minijinja = { version = "2.0.1", features = ["loader"] } notify = "6.1.1" redact = { version = "0.1.9", features = ["serde"] } sled = "0.34.7" diff --git a/pages/index.html.jinja b/pages/index.html.jinja new file mode 100644 index 0000000..afa4658 --- /dev/null +++ b/pages/index.html.jinja @@ -0,0 +1,7 @@ +{% extends "page.html.jinja" %} +{% block body %} +

Index

+

+ Welcome to my awesome homepage. +

+{% endblock %} diff --git a/src/main.rs b/src/main.rs index 3b27f18..aa0efb8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,11 +54,11 @@ async fn main() -> Besult<()> { info!("Tailwind spawned. {tw:#?}"); }); - let mut templates = Arc::new(Mutex::new(Environment::new())); + let templates = Arc::new(Mutex::new(Environment::new())); while let Some(d) = tokio::fs::read_dir("templates").await?.next_entry().await? { - templates.clone().lock().await.add_template( - d.path().to_string_lossy().as_ref(), - &std::fs::read_to_string(d.path())?, + templates.clone().lock().await.add_template_owned( + d.file_name().into_string().unwrap(), + std::fs::read_to_string(d.path())?, )?; } diff --git a/templates/page.html b/templates/page.html.jinja similarity index 85% rename from templates/page.html rename to templates/page.html.jinja index f05da38..67cda10 100644 --- a/templates/page.html +++ b/templates/page.html.jinja @@ -7,6 +7,7 @@ +{% block body %}{% endblock %}