mini jinja templates not tera
This commit is contained in:
parent
d524250cbc
commit
9fb4c4cd65
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
/target
|
/target
|
||||||
tags
|
tags
|
||||||
/output
|
/output
|
||||||
|
.idea
|
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -329,6 +329,15 @@ version = "2.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "minijinja"
|
||||||
|
version = "1.0.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "80084fa3099f58b7afab51e5f92e24c2c2c68dcad26e96ad104bd6011570461d"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-traits"
|
name = "num-traits"
|
||||||
version = "0.2.15"
|
version = "0.2.15"
|
||||||
@ -518,6 +527,7 @@ name = "rustylinks"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"minijinja",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
"tera",
|
"tera",
|
||||||
|
@ -10,3 +10,4 @@ tera = "1"
|
|||||||
serde = { version = "1.0.144", features = ["derive"] }
|
serde = { version = "1.0.144", features = ["derive"] }
|
||||||
serde_yaml = "0.9.22"
|
serde_yaml = "0.9.22"
|
||||||
chrono = "0.4.26"
|
chrono = "0.4.26"
|
||||||
|
minijinja = "1.0.8"
|
||||||
|
@ -29,7 +29,7 @@ links:
|
|||||||
links:
|
links:
|
||||||
- text: Matrix
|
- text: Matrix
|
||||||
icon: fa fa-matrix-org
|
icon: fa fa-matrix-org
|
||||||
href: https://matrix.to/#/@tyrel:tyrel.dev
|
href: https://matrix.to/#/@tyrelsouza:matrix.org
|
||||||
- text: Discord
|
- text: Discord
|
||||||
icon: fa fa-discord
|
icon: fa fa-discord
|
||||||
href: https://discordapp.com/users/73990019756339200
|
href: https://discordapp.com/users/73990019756339200
|
||||||
|
17
src/main.rs
17
src/main.rs
@ -3,7 +3,7 @@ use std::path::Path;
|
|||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde_yaml::{self};
|
use serde_yaml::{self};
|
||||||
use tera::{Tera,Context};
|
use minijinja::{Environment};
|
||||||
|
|
||||||
mod links;
|
mod links;
|
||||||
use links::{RustyLinks,MetaData};
|
use links::{RustyLinks,MetaData};
|
||||||
@ -38,16 +38,13 @@ fn load_links(file_name: &str) -> RustyLinks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn render_links(rusty_links: RustyLinks) -> String {
|
fn render_links(rusty_links: RustyLinks) -> String {
|
||||||
let tera = match Tera::new("templates/*.tera") {
|
let main = std::fs::read_to_string("templates/main.html").expect("Could not find main.html");
|
||||||
Ok(t) => t,
|
|
||||||
Err(e) => {
|
|
||||||
println!("Parsing error(s): {}", e);
|
|
||||||
::std::process::exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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) {
|
fn write_file(html: String) {
|
||||||
|
Loading…
Reference in New Issue
Block a user