Merge pull request 'mini jinja templates not tera' (#1) from minijinja into main

Reviewed-on: #1
This commit is contained in:
Tyrel Souza 2023-10-14 17:13:26 +00:00
commit 4dc5c1c29d
6 changed files with 20 additions and 11 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/target
tags
/output
.idea

10
Cargo.lock generated
View File

@ -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",

View File

@ -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"

View File

@ -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

View File

@ -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) {