add: content_text_color light/dark mode color support

This commit is contained in:
trisua 2025-08-21 15:47:33 -04:00
parent e647e54916
commit be9189a474
3 changed files with 47 additions and 2 deletions

View file

@ -6,7 +6,7 @@
(meta ("name" "viewport") ("content" "width=device-width, initial-scale=1.0")) (meta ("name" "viewport") ("content" "width=device-width, initial-scale=1.0"))
(meta ("http-equiv" "X-UA-Compatible") ("content" "ie=edge")) (meta ("http-equiv" "X-UA-Compatible") ("content" "ie=edge"))
(link ("rel" "stylesheet") ("href" "{{ tetratto }}/css/utility.css?v={{ build_code }}")) (link ("rel" "stylesheet") ("href" "https://repodelivery.tetratto.com/tetratto/crates/app/src/public/css/utility.css"))
(link ("rel" "stylesheet") ("href" "/public/style.css?v={{ build_code }}")) (link ("rel" "stylesheet") ("href" "/public/style.css?v={{ build_code }}"))
(style (text ":root { --color-primary: {{ theme_color }}; }")) (style (text ":root { --color-primary: {{ theme_color }}; }"))

View file

@ -600,6 +600,40 @@ impl EntryMetadata {
input.replace("}", "").replace(";", "").replace("/*", "") input.replace("}", "").replace(";", "").replace("/*", "")
} }
/// Split the given input string by the given character while skipping over
/// CSS colors.
pub fn css_color_split(c: char, input: &str) -> Vec<String> {
let mut out = Vec::new();
let mut buffer = String::new();
let mut in_function = false;
for x in input.chars() {
if x == c && !in_function {
out.push(buffer.clone());
buffer.clear();
continue;
}
match x {
'(' => {
in_function = true;
buffer.push(x);
}
')' => {
in_function = false;
buffer.push(x);
}
_ => buffer.push(x),
}
}
if !buffer.is_empty() {
out.push(buffer);
}
out
}
pub fn css(&self) -> String { pub fn css(&self) -> String {
let mut output = "<style>".to_string(); let mut output = "<style>".to_string();
@ -638,6 +672,17 @@ impl EntryMetadata {
metadata_css!("*, html *", "--color-link" !important, self.content_link_color->output); metadata_css!("*, html *", "--color-link" !important, self.content_link_color->output);
metadata_css!("*, html *", "--color-text" !important, self.content_text_color->output); metadata_css!("*, html *", "--color-text" !important, self.content_text_color->output);
if !self.content_text_color.is_empty() {
let slices = Self::css_color_split(' ', &self.content_text_color);
let light = slices.get(0).unwrap();
let dark = slices.get(1).unwrap_or(light);
output.push_str(&format!(
"html * {{ --color-text: {light} !important; }}\n.dark * {{ --color-text: {dark} !important; }}\n"
));
}
if self.content_text_align != TextAlignment::Left { if self.content_text_align != TextAlignment::Left {
output.push_str(&format!( output.push_str(&format!(
".container {{ text-align: {}; }}\n", ".container {{ text-align: {}; }}\n",