From a8dc6f0d57e493f69e4b3e9a5f0f577831bdba49 Mon Sep 17 00:00:00 2001 From: trisua Date: Fri, 25 Jul 2025 19:02:03 -0400 Subject: [PATCH] add: content_text_size and content_text_color compatibility --- app/public/app.js | 2 +- src/model.rs | 58 +++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/app/public/app.js b/app/public/app.js index 1596389..86c6617 100644 --- a/app/public/app.js +++ b/app/public/app.js @@ -317,7 +317,7 @@ globalThis.toggle_metadata_css = (e) => { METADATA_CSS_ENABLED = !METADATA_CSS_ENABLED; if (!METADATA_CSS_ENABLED) { media_theme_pref(); // user user theme - document.getElementById("metadata_css").remove(); // remove css + document.documentElement.classList.add("no_meta"); // remove css // reset colored text for (const element of Array.from( diff --git a/src/model.rs b/src/model.rs index b1c6594..0c4af85 100644 --- a/src/model.rs +++ b/src/model.rs @@ -323,11 +323,14 @@ pub struct EntryMetadata { pub content_text_shadow_blur: String, /// The name of a font from Google Fonts to use. #[serde(default, alias = "CONTENT_FONT")] - #[validate(max_length = 32)] + #[validate(max_length = 128)] pub content_font: String, /// The weight to use for the body text. #[serde(default, alias = "CONTENT_FONT_WEIGHT")] pub content_font_weight: u32, + /// The text size of elements (separated by space). + #[serde(default, alias = "CONTENT_TEXT_SIZE")] + pub content_text_size: String, /// The text size of elements by element tag. /// /// # Example @@ -335,11 +338,14 @@ pub struct EntryMetadata { /// # ... /// content_text_size = [["h1", "16px"]] /// ``` - #[serde(default, alias = "CONTENT_TEXT_SIZE")] - pub content_text_size: Vec<(String, String)>, + #[serde(default, alias = "CONTENT_TEXT_SIZE_ARRAY")] + pub content_text_size_array: Vec<(String, String)>, /// The default text alignment. #[serde(default, alias = "CONTENT_TEXT_ALIGN")] pub content_text_align: TextAlignment, + /// The base text color. + #[serde(default, alias = "CONTENT_TEXT_COLOR")] + pub content_text_color: String, /// The color of links. #[serde(default, alias = "CONTENT_LINK_COLOR")] pub content_link_color: String, @@ -349,7 +355,7 @@ pub struct EntryMetadata { } macro_rules! metadata_css { - ($selector:literal, $property:literal, $self:ident.$field:ident->$output:ident) => { + ($selector:expr, $property:literal, $self:ident.$field:ident->$output:ident) => { if !$self.$field.is_empty() { $output.push_str(&format!( "{} {{ {}: {}; }}\n", @@ -360,7 +366,18 @@ macro_rules! metadata_css { } }; - ($selector:literal, $property:literal !important, $self:ident.$field:ident->$output:ident) => { + ($selector:expr, $property:literal, $field:ident->$output:ident) => { + if !$field.is_empty() { + $output.push_str(&format!( + "{} {{ {}: {}; }}\n", + $selector, + $property, + EntryMetadata::css_escape(&$field) + )); + } + }; + + ($selector:expr, $property:literal !important, $self:ident.$field:ident->$output:ident) => { if !$self.$field.is_empty() { $output.push_str(&format!( "{} {{ {}: {} !important; }}\n", @@ -371,7 +388,7 @@ macro_rules! metadata_css { } }; - ($selector:literal, $property:literal, $format:literal, $self:ident.$field:ident->$output:ident) => { + ($selector:expr, $property:literal, $format:literal, $self:ident.$field:ident->$output:ident) => { if !$self.$field.is_empty() { $output.push_str(&format!( "{} {{ {}: {}; }}\n", @@ -383,6 +400,16 @@ macro_rules! metadata_css { }; } +macro_rules! text_size { + ($selector:literal, $split:ident, $idx:literal, $output:ident) => { + if let Some(x) = $split.get($idx) { + if *x != "default" && *x != "0" { + metadata_css!($selector, "font-size", x->$output); + } + } + } +} + impl EntryMetadata { pub fn head_tags(&self) -> String { let mut output = String::new(); @@ -477,6 +504,7 @@ impl EntryMetadata { metadata_css!(".container", "box-shadow", self.container_shadow->output); metadata_css!(".container", "text-shadow", self.content_text_shadow->output); metadata_css!("*, html *", "--color-link" !important, self.content_link_color->output); + metadata_css!("*, html *", "--color-text" !important, self.content_text_color->output); if self.content_text_align != TextAlignment::Left { output.push_str(&format!( @@ -485,7 +513,7 @@ impl EntryMetadata { )); } - for (element, size) in &self.content_text_size { + for (element, size) in &self.content_text_size_array { if element == "*" { output.push_str(&format!( ".container, .container * {{ font-size: {}; }}\n", @@ -502,6 +530,22 @@ impl EntryMetadata { )); } + if !self.content_text_size.is_empty() { + let split: Vec<&str> = self.content_text_size.split(" ").collect(); + text_size!("body", split, 0, output); + text_size!("body p", split, 1, output); + text_size!("body h1", split, 2, output); + text_size!("body h2", split, 3, output); + text_size!("body h3", split, 4, output); + text_size!("body h4", split, 5, output); + text_size!("body h5", split, 6, output); + text_size!("body h6", split, 7, output); + text_size!("body li", split, 8, output); + text_size!("body link", split, 9, output); + text_size!("body blockquote", split, 10, output); + text_size!("body code", split, 11, output); + } + if !self.content_font.is_empty() { output.push_str(&format!( ".container {{ font-family: \"{}\", system-ui; }}",