diff options
Diffstat (limited to 'src/main.rs')
-rwxr-xr-x | src/main.rs | 55 |
1 files changed, 47 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index 5784588..acf0dc5 100755 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ mod templated; mod timeparse; mod util; -use std::{os::unix::fs::MetadataExt, str::FromStr}; +use std::{io::Write, os::unix::fs::MetadataExt, str::FromStr}; use axum::{ body::Body, @@ -25,7 +25,7 @@ pub use error::RuntimeError; use fs::Filesystem; use settings::Settings; use tokio_util::io::ReaderStream; -use tracing_subscriber::{prelude::*, EnvFilter}; +use tracing_subscriber::{fmt::time, prelude::*, EnvFilter}; use util::{Referer, RemoteIp, SessionId}; use crate::{ @@ -130,12 +130,27 @@ async fn falible_handler( send_file(resolve.filepath).await } else { let content = Filesystem::read_to_string(&resolve.filepath).await?; - match Templated::from_str(&content) { - Ok(templated) => send_template(templated, resolve, webpath, settings).await, - Err(_) => Ok(Response::builder() - .header(header::CONTENT_TYPE, "text/html") - .body(Body::from(content)) - .unwrap()), + + let result = Templated::from_str(&content); + tracing::trace!("full return from Templated::from_str"); + + match result { + Ok(templated) => { + //tracing::trace!("sending template for {resolve}"); + + std::io::stdout().write_all(b"meow meow meow!!").unwrap(); + std::io::stdout().flush().unwrap(); + + send_template(templated, resolve, webpath, settings).await + } + Err(e) => { + tracing::warn!("error sending template {e}"); + + Ok(Response::builder() + .header(header::CONTENT_TYPE, "text/html") + .body(Body::from(content)) + .unwrap()) + } } } } @@ -297,6 +312,30 @@ async fn send_template( } } + 'published: { + if let Some(mut published_pattern) = template.get_pattern("published") { + let publish_date_result = templated + .frontmatter + .get("published") + .map(|ts| timeparse::parse(ts)); + + match publish_date_result { + None => break 'published, + Some(Err(_e)) => { + tracing::warn!("template {resolve} has malformed `published` frontmatter"); + break 'published; + } + Some(Ok(datetime)) => { + let published_human = timeparse::format_long(&datetime); + let published_machine = timeparse::iso8601(&datetime); + + variables!(published_pattern, published_human, published_machine); + template.set_pattern(published_pattern); + } + } + } + } + // insert the page content itself let markedup = markup::process(&templated.content); template.set("main", markedup); |