diff options
author | gennyble <gen@nyble.dev> | 2024-05-03 10:43:53 -0500 |
---|---|---|
committer | gennyble <gen@nyble.dev> | 2024-05-03 10:43:53 -0500 |
commit | b0f6242b8b936d47b32c227cab5b18b4902cf9c4 (patch) | |
tree | 07645afa7286b3fa7f9555742a1ddba1bb6ba126 /src/main.rs | |
parent | 71a9330b728c1b7d7688d3aac2c6b4e8adffb1b0 (diff) | |
download | awake-b0f6242b8b936d47b32c227cab5b18b4902cf9c4.tar.gz awake-b0f6242b8b936d47b32c227cab5b18b4902cf9c4.zip |
opengraph embeds :)
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index 57c373e..0c61389 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ use axum::{ routing::get, Extension, Router, }; -use bempline::{Document, Options}; +use bempline::{variables, Document, Options}; use camino::Utf8PathBuf; use confindent::Confindent; pub use error::RuntimeError; @@ -54,6 +54,7 @@ async fn main() { let conf = Confindent::from_file(std::env::args().nth(2).unwrap()).unwrap(); let webroot: Utf8PathBuf = conf.child_parse("Webroot").unwrap(); let templates = conf.child_value("Templates").unwrap(); + let hostname = conf.child_owned("Hostname").unwrap(); let fs = Filesystem::new(&webroot); @@ -61,6 +62,7 @@ async fn main() { template_dir: Utf8PathBuf::from(webroot.join(templates)) .canonicalize_utf8() .unwrap(), + hostname, }; let app = Router::new() @@ -213,10 +215,35 @@ async fn send_template( ) .unwrap(); - template.set( - "title", - templated.frontmatter.get("title").unwrap_or(filename), - ); + let title = templated.frontmatter.get("title").unwrap_or(filename); + + template.set("title", title); + + if let Some(og_description) = templated.frontmatter.get("description") { + let og_title = title; + let og_url = format!("https://{}{}", &settings.hostname, webpath); + + if let Some(art_relpath) = templated.frontmatter.get("art") { + let serving_dir = Utf8PathBuf::from(webpath.first_dir()); + let art_path = serving_dir.join(art_relpath); + + let og_image_alt = match templated.frontmatter.get("art_alt") { + Some(alt) => alt, + None => { + tracing::warn!("{} has art but no alt", resolve.filepath); + "" + } + }; + + let og_image = format!("https://{}/{}", &settings.hostname, art_path); + + variables!(template, og_image, og_image_alt); + } + + let og_site_name = &settings.hostname; + + variables!(template, og_title, og_url, og_description, og_site_name); + } // styles the templated stuff wants let style_pattern = template.get_pattern("styles").unwrap(); |