Add meta tags to blog posts

This commit is contained in:
august kline 2025-01-06 19:16:25 -05:00
parent cb6e666a6e
commit f7b850d62a
2 changed files with 8 additions and 12 deletions

View File

@ -447,14 +447,14 @@ 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" => &[env!("DOMAIN"), slug.as_ref()].concat(), "og:url" => &["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() {
image &["https://", env!("DOMAIN"), image].concat()
} else { } else {
meta.remove(); meta.remove();
"" ""
@ -516,8 +516,10 @@ where
ContentType::Html, ContentType::Html,
); );
Ok(()) Ok(())
}), element!("head", |head| {
head.append(&meta, ContentType::Html);
Ok(())
})], })],
..RewriteStrSettings::new() ..RewriteStrSettings::new()
}, },
) )
@ -769,12 +771,6 @@ where
.unwrap_or_default() .unwrap_or_default()
} }
// fn footer<S>(input: S) -> String
// where
// S: AsRef<str>,
// {
// }
pub(crate) fn sanitize<S: AsRef<str>>(input: S) -> String { pub(crate) fn sanitize<S: AsRef<str>>(input: S) -> String {
rewrite_str( rewrite_str(
input.as_ref(), input.as_ref(),

View File

@ -2,8 +2,8 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="/assets/css/style.css" /> <link rel="stylesheet" href="/assets/css/style.css" />
</head> </head>