add: content_text_color light/dark mode color support
This commit is contained in:
parent
e647e54916
commit
be9189a474
3 changed files with 47 additions and 2 deletions
|
@ -6,7 +6,7 @@ Fluffle is a familiar Markdown pastebin-y site :)
|
|||
|
||||
Once you've cloned the repository, cd into the `app` directory and run `cargo run -r`.
|
||||
|
||||
After you start the server the first time, a `fluffle.toml`file will be created in the current directory. You'll need to edit that file to configure your PostgreSQL connection, instance name/theme color, etc.
|
||||
After you start the server the first time, a `fluffle.toml` file will be created in the current directory. You'll need to edit that file to configure your PostgreSQL connection, instance name/theme color, etc.
|
||||
|
||||
## Customization
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
(meta ("name" "viewport") ("content" "width=device-width, initial-scale=1.0"))
|
||||
(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 }}"))
|
||||
|
||||
(style (text ":root { --color-primary: {{ theme_color }}; }"))
|
||||
|
|
45
src/model.rs
45
src/model.rs
|
@ -600,6 +600,40 @@ impl EntryMetadata {
|
|||
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 {
|
||||
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-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 {
|
||||
output.push_str(&format!(
|
||||
".container {{ text-align: {}; }}\n",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue