autofill url field for #1

This commit is contained in:
zyl 2024-11-13 10:50:08 -08:00
parent 83c5f6038f
commit d3f424f24f
Signed by: zyl
SSH key fingerprint: SHA256:uxxbSXbdroP/OnKBGnEDk5q7EKB2razvstC/KmzdXXs
2 changed files with 6 additions and 9 deletions

View file

@ -289,7 +289,7 @@ impl SiteBuilder {
let head = page_metadata.embed.map(|mut embed| { let head = page_metadata.embed.map(|mut embed| {
embed.site_name.clone_from(&self.site.config.title); embed.site_name.clone_from(&self.site.config.title);
embed.build() embed.build(self)
}); });
let out = self.tera.render( let out = self.tera.render(

View file

@ -72,8 +72,6 @@ pub struct EmbedMetadata {
#[serde(default)] #[serde(default)]
pub description: Option<String>, pub description: Option<String>,
#[serde(default)] #[serde(default)]
pub url: Option<String>,
#[serde(default)]
pub image: Option<String>, pub image: Option<String>,
#[serde(default = "EmbedMetadata::default_theme_color")] #[serde(default = "EmbedMetadata::default_theme_color")]
pub theme_color: String, pub theme_color: String,
@ -83,8 +81,11 @@ pub struct EmbedMetadata {
impl EmbedMetadata { impl EmbedMetadata {
/// builds the embed html tags /// builds the embed html tags
pub fn build(self) -> String { pub fn build(self, builder: &SiteBuilder) -> String {
let mut s = format!(r#"<meta content="{}" property="og:title">"#, self.title); let mut s = format!(
r#"<meta content="{}" property="og:title"><meta content="{}" property="og:url">"#,
self.title, builder.site.config.base_url
);
s = format!( s = format!(
r#"{s}<meta content="{}" property="og:site_name">"#, r#"{s}<meta content="{}" property="og:site_name">"#,
self.site_name self.site_name
@ -92,9 +93,6 @@ impl EmbedMetadata {
if let Some(description) = self.description { if let Some(description) = self.description {
s = format!(r#"{s}<meta content="{description}" property="og:description">"#); s = format!(r#"{s}<meta content="{description}" property="og:description">"#);
} }
if let Some(url) = self.url {
s = format!(r#"{s}<meta content="{url}" property="og:url">"#);
}
if let Some(image) = self.image { if let Some(image) = self.image {
s = format!(r#"{s}<meta content="{image}" property="og:image">"#); s = format!(r#"{s}<meta content="{image}" property="og:image">"#);
} }
@ -267,7 +265,6 @@ impl ResourceBuilder {
} else { } else {
None None
}, },
url: None,
theme_color: EmbedMetadata::default_theme_color(), theme_color: EmbedMetadata::default_theme_color(),
large_image: true, large_image: true,
}), }),