implement cdn prefix for embed metadata images

This commit is contained in:
zyl 2024-11-13 11:09:12 -08:00
parent 58ba627b9d
commit 762344b5da
Signed by: zyl
SSH key fingerprint: SHA256:uxxbSXbdroP/OnKBGnEDk5q7EKB2razvstC/KmzdXXs
3 changed files with 13 additions and 7 deletions

View file

@ -81,7 +81,7 @@ pub struct EmbedMetadata {
impl EmbedMetadata {
/// builds the embed html tags
pub fn build(self, builder: &SiteBuilder) -> String {
pub fn build(self, builder: &SiteBuilder) -> eyre::Result<String> {
let mut s = format!(
r#"<meta content="{}" property="og:title"><meta content="{}" property="og:url">"#,
self.title, builder.site.config.base_url
@ -93,7 +93,10 @@ impl EmbedMetadata {
if let Some(description) = self.description {
s = format!(r#"{s}<meta content="{description}" property="og:description">"#);
}
if let Some(image) = self.image {
if let Some(mut image) = self.image {
if image.starts_with("cdn$") {
image = builder.site.config.cdn_url(&image[4..])?.to_string();
}
s = format!(r#"{s}<meta content="{image}" property="og:image">"#);
}
s = format!(
@ -104,7 +107,7 @@ impl EmbedMetadata {
s = format!(r#"{s}<meta name="twitter:card" content="summary_large_image">"#);
}
s
Ok(s)
}
pub fn default_theme_color() -> String {