about summary refs log tree commit diff
path: root/splorm/src/handler/templated.rs
diff options
context:
space:
mode:
Diffstat (limited to 'splorm/src/handler/templated.rs')
-rw-r--r--splorm/src/handler/templated.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/splorm/src/handler/templated.rs b/splorm/src/handler/templated.rs
index 4a5fa62..dee93ba 100644
--- a/splorm/src/handler/templated.rs
+++ b/splorm/src/handler/templated.rs
@@ -8,15 +8,25 @@ use crate::{
 	RuntimeError,
 	config::Settings,
 	fs::{self, RequestPath, SafePathBuf},
+	state::SplormState,
 	templated::TemplateVariables,
 };
 
-pub async fn send_file(path: RequestPath, settings: &Settings) -> Result<Response, RuntimeError> {
+pub async fn send_file(
+	path: RequestPath,
+	state: SplormState,
+	settings: &Settings,
+) -> Result<Response, RuntimeError> {
 	let safe = path.system_path().to_owned();
 	let string = fs::read_file_to_string(path.system_path()).await?;
 	let template = Templated::from_str(&string)
 		.map_err(|_| RuntimeError::not_a_template(path.system_path().to_path_buf()))?;
 	let tvars = TemplateVariables::build(safe.as_path(), &template.frontmatter);
+	tracing::trace!(
+		"page {} has features {:?}",
+		path.web_path(),
+		tvars.features()
+	);
 
 	let pt_path = match tvars.template() {
 		Some(name) => {
@@ -40,7 +50,12 @@ pub async fn send_file(path: RequestPath, settings: &Settings) -> Result<Respons
 	tvars.apply_pathnav(&mut page_template, &path);
 	tvars.apply_opengraph(&mut page_template, &settings, &path);
 
-	let content = tvars.apply_markup(&mut page_template, template.content);
+	let mut content = template.content;
+	if !tvars.features().is_empty() {
+		content = tvars.apply_features(content, &state).await;
+	}
+
+	let content = tvars.apply_markup(&mut page_template, content);
 	page_template.set("main", content);
 
 	Response::builder()