add theme_color to config and use it for embed metadata

resolves #1
This commit is contained in:
zyl 2024-11-13 11:23:09 -08:00
parent 1875cc9d5c
commit 847f0c7ee7
Signed by: zyl
SSH key fingerprint: SHA256:uxxbSXbdroP/OnKBGnEDk5q7EKB2razvstC/KmzdXXs
5 changed files with 16 additions and 8 deletions

View file

@ -1,6 +1,7 @@
base_url: "https://webdog.zyl.gay" base_url: "https://webdog.zyl.gay"
title: webdog title: webdog
description: "static site builder for dogs" description: "static site builder for dogs"
theme_color: "#ffc4fc"
sass_styles: [index.scss] sass_styles: [index.scss]
cdn_url: "https://i.zyl.gay/webdog/" cdn_url: "https://i.zyl.gay/webdog/"
code_theme: base16-ocean.dark # options: base16-ocean.dark, base16-eighties.dark, base16-mocha.dark, base16-ocean.light, InspiredGitHub, Solarized (dark), and Solarized (light) code_theme: base16-ocean.dark # options: base16-ocean.dark, base16-eighties.dark, base16-mocha.dark, base16-ocean.light, InspiredGitHub, Solarized (dark), and Solarized (light)

View file

@ -19,6 +19,10 @@ the site's base title applied to all pages.
presently unused field, set this to any string you like. presently unused field, set this to any string you like.
## `theme_color`
the default theme color to use for embed metadata.
## `build` ## `build`
the directory for the site to build to. defaults to `<site-path>/build` if not specified. the directory for the site to build to. defaults to `<site-path>/build` if not specified.

View file

@ -59,7 +59,7 @@ prefixing a url with `cdn$` will join it with the site's cdn url as defined in t
#### `theme_color` #### `theme_color`
the theme color to use for the embed. optional, but the default is currently nonconfigurable. the theme color to use for the embed. optional, defaults to the value in your site's configuration.
#### `large_image` #### `large_image`

View file

@ -42,6 +42,8 @@ pub struct SiteConfig {
pub title: String, pub title: String,
/// The site's description? Not sure if this will actually be used or not /// The site's description? Not sure if this will actually be used or not
pub description: String, pub description: String,
/// the site's theme color for embed metadata
pub theme_color: String,
/// The site's build directory. Defaults to <site>/build if not specified. /// The site's build directory. Defaults to <site>/build if not specified.
pub build: Option<String>, pub build: Option<String>,
/// A list of Sass stylesheets that will be built. /// A list of Sass stylesheets that will be built.
@ -68,6 +70,7 @@ impl SiteConfig {
base_url, base_url,
title, title,
description: Default::default(), description: Default::default(),
theme_color: "#ffc4fc".to_string(),
build: None, build: None,
sass_styles: vec!["index.scss".into()], sass_styles: vec!["index.scss".into()],
cdn_url, cdn_url,

View file

@ -71,8 +71,7 @@ pub struct EmbedMetadata {
pub description: Option<String>, pub description: Option<String>,
#[serde(default)] #[serde(default)]
pub image: Option<String>, pub image: Option<String>,
#[serde(default = "EmbedMetadata::default_theme_color")] pub theme_color: Option<String>,
pub theme_color: String,
#[serde(default)] #[serde(default)]
pub large_image: bool, pub large_image: bool,
} }
@ -93,10 +92,11 @@ impl EmbedMetadata {
} }
s = format!(r#"{s}<meta content="{image}" property="og:image">"#); s = format!(r#"{s}<meta content="{image}" property="og:image">"#);
} }
s = format!( let theme_color = self
r#"{s}<meta content="{}" name="theme-color">"#, .theme_color
self.theme_color .as_ref()
); .unwrap_or(&builder.site.config.theme_color);
s = format!(r#"{s}<meta content="{theme_color}" name="theme-color">"#);
if self.large_image { if self.large_image {
s = format!(r#"{s}<meta name="twitter:card" content="summary_large_image">"#); s = format!(r#"{s}<meta name="twitter:card" content="summary_large_image">"#);
} }
@ -261,7 +261,7 @@ impl ResourceBuilder {
} else { } else {
None None
}, },
theme_color: EmbedMetadata::default_theme_color(), theme_color: None,
large_image: true, large_image: true,
}), }),
..Default::default() ..Default::default()