diff --git a/src/blog.rs b/src/blog.rs index abdf569..ff42808 100644 --- a/src/blog.rs +++ b/src/blog.rs @@ -86,7 +86,7 @@ impl ResourceMethods for ResourceMetadata eyre::Result { Ok(EmbedMetadata { title: self.title.clone(), - site_name: &site_config.title, + site_name: site_config.title.clone(), description: Some(self.inner.desc.clone()), image: Some(self.inner.get_header_image(site_config)?), url: None, diff --git a/src/builder.rs b/src/builder.rs index 8ccf87b..aab6768 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -21,6 +21,8 @@ struct TemplateData<'a, T> { pub page: &'a str, /// The page's title. pub title: &'a str, + /// Custom head data for the page. + pub head: Option, /// The page's custom scripts. pub scripts: &'a [String], /// the page's custom styles. @@ -214,11 +216,17 @@ impl<'a> SiteBuilder<'a> { _ => self.site.config.title.clone(), }; + let head = page_metadata.embed.map(|mut embed| { + embed.site_name.clone_from(&self.site.config.title); + embed.build() + }); + let out = self.reg.render( &page_metadata.template.unwrap_or_else(|| "base".to_string()), &TemplateData { page: page_html, title: &title, + head, scripts: &page_metadata.scripts, styles: &page_metadata.styles, extra_data, diff --git a/src/images.rs b/src/images.rs index 6c92a90..d0e7a22 100644 --- a/src/images.rs +++ b/src/images.rs @@ -68,7 +68,7 @@ impl ResourceMethods for ResourceMetadata { fn get_head_data(&self, site_config: &SiteConfig) -> eyre::Result { Ok(EmbedMetadata { title: self.title.clone(), - site_name: &site_config.title, + site_name: site_config.title.clone(), description: self.inner.desc.clone(), image: Some(self.inner.get_image_url(site_config)?), url: None, diff --git a/src/lib.rs b/src/lib.rs index 521d968..2b7703f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,7 @@ use std::{ }; use eyre::Context; +use resource::EmbedMetadata; use serde::Deserialize; use url::Url; use util::get_name; @@ -67,6 +68,9 @@ pub struct PageMetadata { pub title: Option, /// The template to use for the page. If not specified, it defaults to "base". pub template: Option, + /// custom embed info for a template + #[serde(default)] + pub embed: Option, /// The page's custom scripts, if any. #[serde(default)] pub scripts: Vec, diff --git a/src/resource.rs b/src/resource.rs index 6b198a4..ca3502b 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -80,18 +80,24 @@ where } /// struct for adding custom meta content embeds -#[derive(Debug)] -pub struct EmbedMetadata<'s> { +#[derive(Debug, Deserialize)] +pub struct EmbedMetadata { pub title: String, - pub site_name: &'s str, + #[serde(default)] + pub site_name: String, + #[serde(default)] pub description: Option, + #[serde(default)] pub url: Option, + #[serde(default)] pub image: Option, + #[serde(default = "EmbedMetadata::default_theme_color")] pub theme_color: String, + #[serde(default)] pub large_image: bool, } -impl<'s> EmbedMetadata<'s> { +impl EmbedMetadata { /// builds the embed html tags pub fn build(self) -> String { let mut s = format!(r#""#, self.title); @@ -118,6 +124,10 @@ impl<'s> EmbedMetadata<'s> { s } + + fn default_theme_color() -> String { + "rgb(255, 196, 252)".to_string() + } } #[derive(Debug, Serialize)]