mirror of
https://github.com/zyllian/webdog.git
synced 2025-01-18 03:32:21 -08:00
implement cdn prefix for embed metadata images
This commit is contained in:
parent
58ba627b9d
commit
762344b5da
3 changed files with 13 additions and 7 deletions
|
@ -59,6 +59,8 @@ the embed's description. optional.
|
|||
|
||||
full url to an image to use for the embed. optional.
|
||||
|
||||
prefixing a url with `cdn$` will join it with the site's cdn url as defined in the site config.
|
||||
|
||||
#### `theme_color`
|
||||
|
||||
the theme color to use for the embed. optional, but the default is currently nonconfigurable.
|
||||
|
|
|
@ -287,10 +287,11 @@ impl SiteBuilder {
|
|||
_ => self.site.config.title.clone(),
|
||||
};
|
||||
|
||||
let head = page_metadata.embed.map(|mut embed| {
|
||||
embed.site_name.clone_from(&self.site.config.title);
|
||||
embed.build(self)
|
||||
});
|
||||
let head = if let Some(embed) = page_metadata.embed {
|
||||
Some(embed.build(self)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let out = self.tera.render(
|
||||
&page_metadata
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue