add: content_text_size and content_text_color compatibility
This commit is contained in:
parent
9e885a6718
commit
a8dc6f0d57
2 changed files with 52 additions and 8 deletions
|
@ -317,7 +317,7 @@ globalThis.toggle_metadata_css = (e) => {
|
||||||
METADATA_CSS_ENABLED = !METADATA_CSS_ENABLED;
|
METADATA_CSS_ENABLED = !METADATA_CSS_ENABLED;
|
||||||
if (!METADATA_CSS_ENABLED) {
|
if (!METADATA_CSS_ENABLED) {
|
||||||
media_theme_pref(); // user user theme
|
media_theme_pref(); // user user theme
|
||||||
document.getElementById("metadata_css").remove(); // remove css
|
document.documentElement.classList.add("no_meta"); // remove css
|
||||||
|
|
||||||
// reset colored text
|
// reset colored text
|
||||||
for (const element of Array.from(
|
for (const element of Array.from(
|
||||||
|
|
58
src/model.rs
58
src/model.rs
|
@ -323,11 +323,14 @@ pub struct EntryMetadata {
|
||||||
pub content_text_shadow_blur: String,
|
pub content_text_shadow_blur: String,
|
||||||
/// The name of a font from Google Fonts to use.
|
/// The name of a font from Google Fonts to use.
|
||||||
#[serde(default, alias = "CONTENT_FONT")]
|
#[serde(default, alias = "CONTENT_FONT")]
|
||||||
#[validate(max_length = 32)]
|
#[validate(max_length = 128)]
|
||||||
pub content_font: String,
|
pub content_font: String,
|
||||||
/// The weight to use for the body text.
|
/// The weight to use for the body text.
|
||||||
#[serde(default, alias = "CONTENT_FONT_WEIGHT")]
|
#[serde(default, alias = "CONTENT_FONT_WEIGHT")]
|
||||||
pub content_font_weight: u32,
|
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.
|
/// The text size of elements by element tag.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
|
@ -335,11 +338,14 @@ pub struct EntryMetadata {
|
||||||
/// # ...
|
/// # ...
|
||||||
/// content_text_size = [["h1", "16px"]]
|
/// content_text_size = [["h1", "16px"]]
|
||||||
/// ```
|
/// ```
|
||||||
#[serde(default, alias = "CONTENT_TEXT_SIZE")]
|
#[serde(default, alias = "CONTENT_TEXT_SIZE_ARRAY")]
|
||||||
pub content_text_size: Vec<(String, String)>,
|
pub content_text_size_array: Vec<(String, String)>,
|
||||||
/// The default text alignment.
|
/// The default text alignment.
|
||||||
#[serde(default, alias = "CONTENT_TEXT_ALIGN")]
|
#[serde(default, alias = "CONTENT_TEXT_ALIGN")]
|
||||||
pub content_text_align: TextAlignment,
|
pub content_text_align: TextAlignment,
|
||||||
|
/// The base text color.
|
||||||
|
#[serde(default, alias = "CONTENT_TEXT_COLOR")]
|
||||||
|
pub content_text_color: String,
|
||||||
/// The color of links.
|
/// The color of links.
|
||||||
#[serde(default, alias = "CONTENT_LINK_COLOR")]
|
#[serde(default, alias = "CONTENT_LINK_COLOR")]
|
||||||
pub content_link_color: String,
|
pub content_link_color: String,
|
||||||
|
@ -349,7 +355,7 @@ pub struct EntryMetadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! metadata_css {
|
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() {
|
if !$self.$field.is_empty() {
|
||||||
$output.push_str(&format!(
|
$output.push_str(&format!(
|
||||||
"{} {{ {}: {}; }}\n",
|
"{} {{ {}: {}; }}\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() {
|
if !$self.$field.is_empty() {
|
||||||
$output.push_str(&format!(
|
$output.push_str(&format!(
|
||||||
"{} {{ {}: {} !important; }}\n",
|
"{} {{ {}: {} !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() {
|
if !$self.$field.is_empty() {
|
||||||
$output.push_str(&format!(
|
$output.push_str(&format!(
|
||||||
"{} {{ {}: {}; }}\n",
|
"{} {{ {}: {}; }}\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 {
|
impl EntryMetadata {
|
||||||
pub fn head_tags(&self) -> String {
|
pub fn head_tags(&self) -> String {
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
|
@ -477,6 +504,7 @@ impl EntryMetadata {
|
||||||
metadata_css!(".container", "box-shadow", self.container_shadow->output);
|
metadata_css!(".container", "box-shadow", self.container_shadow->output);
|
||||||
metadata_css!(".container", "text-shadow", self.content_text_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-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 {
|
if self.content_text_align != TextAlignment::Left {
|
||||||
output.push_str(&format!(
|
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 == "*" {
|
if element == "*" {
|
||||||
output.push_str(&format!(
|
output.push_str(&format!(
|
||||||
".container, .container * {{ font-size: {}; }}\n",
|
".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() {
|
if !self.content_font.is_empty() {
|
||||||
output.push_str(&format!(
|
output.push_str(&format!(
|
||||||
".container {{ font-family: \"{}\", system-ui; }}",
|
".container {{ font-family: \"{}\", system-ui; }}",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue