Fix env vars

This commit is contained in:
august kline 2025-01-06 20:17:49 -05:00
parent 35331ef076
commit ab494f8381
1 changed files with 32 additions and 5 deletions

View File

@ -1,3 +1,4 @@
use std::borrow::Borrow;
use std::{env, vec}; use std::{env, vec};
use blogdb::posts::Post; use blogdb::posts::Post;
@ -447,14 +448,30 @@ where
element_content_handlers: vec![element!("meta", |meta| { element_content_handlers: vec![element!("meta", |meta| {
if let Some(attr) = meta.get_attribute("property") { if let Some(attr) = meta.get_attribute("property") {
let content = match attr.as_str() { let content = match attr.as_str() {
"og:url" => &["https://", env!("DOMAIN"), slug.as_ref()].concat(), "og:url" => {
#[cfg(debug_assertions)]
{
&["http://localhost", slug.as_ref()].concat()
}
#[cfg(not(debug_assertions))]
{
&["https://", env!("DOMAIN"), slug.as_ref()].concat()
}
}
"og:type" => "article", "og:type" => "article",
"og:title" => title.as_ref(), "og:title" => title.as_ref(),
"og:description" => description.as_ref(), "og:description" => description.as_ref(),
"og:image" => { "og:image" => {
let image = image.as_ref(); let image = image.as_ref();
if !image.is_empty() { if !image.is_empty() {
&["https://", env!("DOMAIN"), image].concat() #[cfg(debug_assertions)]
{
&["http://localhost", image].concat()
}
#[cfg(not(debug_assertions))]
{
&["https://", env!("DOMAIN"), image].concat()
}
} else { } else {
meta.remove(); meta.remove();
"" ""
@ -482,7 +499,7 @@ where
let html = make_page(template, PageSettings::title("Blog")); let html = make_page(template, PageSettings::title("Blog"));
let post = db.get_post(id).await.unwrap_or_default(); let post = db.get_post(id).await.unwrap_or_default();
let head = head::<_, _, [String; 0]>(post.title, []); let head_content = head::<_, _, [String; 0]>(post.title, []);
let post_content: Blocks = serde_json::from_str(&post.content).unwrap_or_default(); let post_content: Blocks = serde_json::from_str(&post.content).unwrap_or_default();
let post_html: String = post_content.to_html(); let post_html: String = post_content.to_html();
let image = if let Some(url) = post_content.image() { let image = if let Some(url) = post_content.image() {
@ -504,8 +521,17 @@ where
time.after(&post_html, ContentType::Html); time.after(&post_html, ContentType::Html);
time.replace( time.replace(
&[ &[
r#"<a class="animated-link" style="align-self: flex-start; margin-block-end: 0" href="https://"#, r#"<a class="animated-link" style="align-self: flex-start; margin-block-end: 0" href=""#,
env!("DOMAIN"), {
#[cfg(debug_assertions)]
{
"http://localhost"
}
#[cfg(not(debug_assertions))]
{
&["https://", env!("DOMAIN")].concat()
}
},
"/blog/", "/blog/",
&post.id, &post.id,
r#""><time>"#, r#""><time>"#,
@ -517,6 +543,7 @@ where
); );
Ok(()) Ok(())
}), element!("head", |head| { }), element!("head", |head| {
head.replace(&head_content, ContentType::Html);
head.append(&meta, ContentType::Html); head.append(&meta, ContentType::Html);
Ok(()) Ok(())
})], })],