From 9fb4c4cd654247ec2ad7e52c4a330235b71270c3 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Sat, 14 Oct 2023 13:06:56 -0400 Subject: [PATCH] mini jinja templates not tera --- .gitignore | 1 + Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + links.yaml | 2 +- src/main.rs | 17 +++++++---------- templates/{main.tera => main.html} | 0 6 files changed, 20 insertions(+), 11 deletions(-) rename templates/{main.tera => main.html} (100%) diff --git a/.gitignore b/.gitignore index b399671..9c205d6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target tags /output +.idea \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 61ee011..5fce9f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -329,6 +329,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "minijinja" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80084fa3099f58b7afab51e5f92e24c2c2c68dcad26e96ad104bd6011570461d" +dependencies = [ + "serde", +] + [[package]] name = "num-traits" version = "0.2.15" @@ -518,6 +527,7 @@ name = "rustylinks" version = "0.1.0" dependencies = [ "chrono", + "minijinja", "serde", "serde_yaml", "tera", diff --git a/Cargo.toml b/Cargo.toml index a612e41..c392dee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,4 @@ tera = "1" serde = { version = "1.0.144", features = ["derive"] } serde_yaml = "0.9.22" chrono = "0.4.26" +minijinja = "1.0.8" diff --git a/links.yaml b/links.yaml index 0bf1ac8..d3306f1 100644 --- a/links.yaml +++ b/links.yaml @@ -29,7 +29,7 @@ links: links: - text: Matrix icon: fa fa-matrix-org - href: https://matrix.to/#/@tyrel:tyrel.dev + href: https://matrix.to/#/@tyrelsouza:matrix.org - text: Discord icon: fa fa-discord href: https://discordapp.com/users/73990019756339200 diff --git a/src/main.rs b/src/main.rs index 4dffe25..6cf9881 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use std::path::Path; use chrono::{DateTime, Utc}; use serde_yaml::{self}; -use tera::{Tera,Context}; +use minijinja::{Environment}; mod links; use links::{RustyLinks,MetaData}; @@ -38,16 +38,13 @@ fn load_links(file_name: &str) -> RustyLinks { } fn render_links(rusty_links: RustyLinks) -> String { - let tera = match Tera::new("templates/*.tera") { - Ok(t) => t, - Err(e) => { - println!("Parsing error(s): {}", e); - ::std::process::exit(1); - } - }; + let main = std::fs::read_to_string("templates/main.html").expect("Could not find main.html"); - let context: Context = Context::from_serialize(&rusty_links).expect("Could not parse"); - tera.render("main.tera", &context).expect("Could not parse") + + let mut env = Environment::new(); + env.add_template("main", &*main).unwrap(); + let tmpl = env.get_template("main").unwrap(); + tmpl.render(rusty_links).unwrap() } fn write_file(html: String) { diff --git a/templates/main.tera b/templates/main.html similarity index 100% rename from templates/main.tera rename to templates/main.html