Skip to content

Commit f9613c0

Browse files
fix: embed tera templates correctly
1 parent f9df697 commit f9613c0

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2021"
77
axum = "0.7.7"
88
axum-embed = "0.1.0"
99
dotenvy = "0.15.7"
10+
include_dir = "0.7.4"
1011
lazy_static = "1.5.0"
1112
rust-embed = "8.5.0"
1213
serde = { version = "1.0.217", features = ["serde_derive"] }

src/main.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use axum::{
1515
Router,
1616
};
1717
use lazy_static::lazy_static;
18+
use rust_embed::RustEmbed;
1819
use sqlx::{sqlite::SqlitePool, Pool, Sqlite};
1920
use tera::{Context, Tera};
2021
use tower_http::trace::TraceLayer;
@@ -105,9 +106,22 @@ impl IntoResponse for MainPage {
105106
}
106107
}
107108

109+
#[derive(RustEmbed)]
110+
#[folder = "templates/"]
111+
struct Templates;
112+
108113
lazy_static! {
109114
pub static ref TEMPLATES: Tera = {
110-
let tera = Tera::new("templates/**/*").unwrap();
115+
let mut tera = Tera::default();
116+
117+
let templates_to_add = Templates::iter().map(|path| {
118+
let contents = Templates::get(path.as_ref()).unwrap().data;
119+
let content_string = String::from_utf8(contents.into_owned()).unwrap();
120+
(path, content_string)
121+
});
122+
123+
tera.add_raw_templates(templates_to_add)
124+
.expect("Failed to add raw templates");
111125

112126
return tera;
113127
};

0 commit comments

Comments
 (0)