add: near perfect metadata compatibility
This commit is contained in:
parent
b505199492
commit
f8dac8f491
8 changed files with 434 additions and 22 deletions
235
src/model.rs
235
src/model.rs
|
@ -10,6 +10,7 @@ pub struct Entry {
|
|||
pub created: usize,
|
||||
pub edited: usize,
|
||||
pub content: String,
|
||||
#[serde(default)]
|
||||
pub metadata: String,
|
||||
}
|
||||
|
||||
|
@ -69,7 +70,7 @@ pub struct EntryMetadata {
|
|||
#[validate(max_length = 256)]
|
||||
pub page_description: String,
|
||||
/// The favicon of the page.
|
||||
#[serde(default, alias = "PAGE_icon")]
|
||||
#[serde(default, alias = "PAGE_ICON")]
|
||||
#[validate(max_length = 128)]
|
||||
pub page_icon: String,
|
||||
/// The title of the page shown in external embeds.
|
||||
|
@ -99,38 +100,171 @@ pub struct EntryMetadata {
|
|||
#[serde(default, alias = "ACCESS_EASY_READ")]
|
||||
#[validate(max_length = 32)]
|
||||
pub access_easy_read: String,
|
||||
/// The color of the text in the inner container.
|
||||
#[serde(default, alias = "CONTAINER_INNER_FOREGROUND")]
|
||||
/// The padding of the container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/padding>
|
||||
#[serde(default, alias = "CONTAINER_PADDING")]
|
||||
#[validate(max_length = 32)]
|
||||
pub container_inner_foreground: String,
|
||||
pub container_padding: String,
|
||||
/// The maximum width of the container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/max-width>
|
||||
#[serde(default, alias = "CONTAINER_MAX_WIDTH")]
|
||||
#[validate(max_length = 16)]
|
||||
pub container_max_width: String,
|
||||
/// The padding of the container.
|
||||
/// The color of the text in the inner container.
|
||||
#[serde(default, alias = "CONTAINER_INNER_FOREGROUND_COLOR")]
|
||||
#[validate(max_length = 32)]
|
||||
pub container_inner_foreground_color: String,
|
||||
/// The background of the inner container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/background>
|
||||
#[serde(default, alias = "CONTAINER_INNER_BACKGROUND")]
|
||||
#[validate(max_length = 256)]
|
||||
pub container_inner_background: String,
|
||||
/// The color of the text in the outer container.
|
||||
#[serde(default, alias = "CONTAINER_OUTER_FOREGROUND")]
|
||||
/// The background of the inner container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/background-color>
|
||||
#[serde(default, alias = "CONTAINER_INNER_BACKGROUND_COLOR")]
|
||||
#[validate(max_length = 32)]
|
||||
pub container_outer_foreground: String,
|
||||
pub container_inner_background_color: String,
|
||||
/// The background of the inner container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/background-image>
|
||||
#[serde(default, alias = "CONTAINER_INNER_BACKGROUND_IMAGE")]
|
||||
#[validate(max_length = 128)]
|
||||
pub container_inner_background_image: String,
|
||||
/// The background of the inner container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/background-repeat>
|
||||
#[serde(default, alias = "CONTAINER_INNER_BACKGROUND_IMAGE_REPEAT")]
|
||||
#[validate(max_length = 16)]
|
||||
pub container_inner_background_image_repeat: String,
|
||||
/// The background of the inner container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/background-position>
|
||||
#[serde(default, alias = "CONTAINER_INNER_BACKGROUND_IMAGE_POSITION")]
|
||||
#[validate(max_length = 16)]
|
||||
pub container_inner_background_image_position: String,
|
||||
/// The background of the inner container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/background-size>
|
||||
#[serde(default, alias = "CONTAINER_INNER_BACKGROUND_IMAGE_SIZE")]
|
||||
#[validate(max_length = 16)]
|
||||
pub container_inner_background_image_size: String,
|
||||
/// The color of the text in the outer container.
|
||||
#[serde(default, alias = "CONTAINER_OUTER_FOREGROUND_COLOR")]
|
||||
#[validate(max_length = 32)]
|
||||
pub container_outer_foreground_color: String,
|
||||
/// The background of the outer container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/background>
|
||||
#[serde(default, alias = "CONTAINER_OUTER_BACKGROUND")]
|
||||
#[validate(max_length = 256)]
|
||||
pub container_outer_background: String,
|
||||
/// The background of the outer container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/background-color>
|
||||
#[serde(default, alias = "CONTAINER_OUTER_BACKGROUND_COLOR")]
|
||||
#[validate(max_length = 32)]
|
||||
pub container_outer_background_color: String,
|
||||
/// The background of the outer container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/background-image>
|
||||
#[serde(default, alias = "CONTAINER_OUTER_BACKGROUND_IMAGE")]
|
||||
#[validate(max_length = 128)]
|
||||
pub container_outer_background_image: String,
|
||||
/// The background of the outer container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/background-repeat>
|
||||
#[serde(default, alias = "CONTAINER_OUTER_BACKGROUND_IMAGE_REPEAT")]
|
||||
#[validate(max_length = 16)]
|
||||
pub container_outer_background_image_repeat: String,
|
||||
/// The background of the outer container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/background-position>
|
||||
#[serde(default, alias = "CONTAINER_OUTER_BACKGROUND_IMAGE_POSITION")]
|
||||
#[validate(max_length = 16)]
|
||||
pub container_outer_background_image_position: String,
|
||||
/// The background of the outer container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/background-size>
|
||||
#[serde(default, alias = "CONTAINER_OUTER_BACKGROUND_IMAGE_SIZE")]
|
||||
#[validate(max_length = 16)]
|
||||
pub container_outer_background_image_size: String,
|
||||
/// The border around the container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/border>
|
||||
#[serde(default, alias = "CONTAINER_BORDER")]
|
||||
#[validate(max_length = 256)]
|
||||
pub container_border: String,
|
||||
/// The border around the container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/border-image>
|
||||
#[serde(default, alias = "CONTAINER_BORDER_IMAGE")]
|
||||
#[validate(max_length = 128)]
|
||||
pub container_border_image: String,
|
||||
/// The border around the container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/border-image-slice>
|
||||
#[serde(default, alias = "CONTAINER_BORDER_IMAGE_SLICE")]
|
||||
#[validate(max_length = 16)]
|
||||
pub container_border_image_slice: String,
|
||||
/// The border around the container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/border-image-width>
|
||||
#[serde(default, alias = "CONTAINER_BORDER_IMAGE_WIDTH")]
|
||||
#[validate(max_length = 16)]
|
||||
pub container_border_image_width: String,
|
||||
/// The border around the container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/border-image-outset>
|
||||
#[serde(default, alias = "CONTAINER_BORDER_IMAGE_OUTSET")]
|
||||
#[validate(max_length = 32)]
|
||||
pub container_border_image_outset: String,
|
||||
/// The border around the container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/border-image-repeat>
|
||||
#[serde(default, alias = "CONTAINER_BORDER_IMAGE_REPEAT")]
|
||||
#[validate(max_length = 16)]
|
||||
pub container_border_image_repeat: String,
|
||||
/// The border around the container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/border-color>
|
||||
#[serde(default, alias = "CONTAINER_BORDER_COLOR")]
|
||||
#[validate(max_length = 32)]
|
||||
pub container_border_color: String,
|
||||
/// The border around the container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/border-width>
|
||||
#[serde(default, alias = "CONTAINER_BORDER_WIDTH")]
|
||||
#[validate(max_length = 16)]
|
||||
pub container_border_width: String,
|
||||
/// The border around the container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/border-style>
|
||||
#[serde(default, alias = "CONTAINER_BORDER_STYLE")]
|
||||
#[validate(max_length = 16)]
|
||||
pub container_border_style: String,
|
||||
/// The border around the container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius>
|
||||
#[serde(default, alias = "CONTAINER_BORDER_RADIUS")]
|
||||
#[validate(max_length = 16)]
|
||||
pub container_border_radius: String,
|
||||
/// The shadow around the container.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow>
|
||||
#[serde(default, alias = "CONTAINER_SHADOW")]
|
||||
#[validate(max_length = 32)]
|
||||
pub container_shadow: String,
|
||||
/// The shadow under text.
|
||||
///
|
||||
/// Syntax: <https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow>
|
||||
#[serde(default, alias = "CONTENT_TEXT_SHADOW")]
|
||||
#[validate(max_length = 32)]
|
||||
pub content_text_shadow: String,
|
||||
/// The name of a font from Google Fonts to use.
|
||||
#[serde(default, alias = "CONTENT_FONT")]
|
||||
#[validate(max_length = 32)]
|
||||
|
@ -166,6 +300,17 @@ macro_rules! metadata_css {
|
|||
));
|
||||
}
|
||||
};
|
||||
|
||||
($selector:literal, $property:literal, $format:literal, $self:ident.$field:ident->$output:ident) => {
|
||||
if !$self.$field.is_empty() {
|
||||
$output.push_str(&format!(
|
||||
"{} {{ {}: {}; }}\n",
|
||||
$selector,
|
||||
$property,
|
||||
format!($format, EntryMetadata::css_escape(&$self.$field))
|
||||
));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl EntryMetadata {
|
||||
|
@ -233,12 +378,34 @@ impl EntryMetadata {
|
|||
pub fn css(&self) -> String {
|
||||
let mut output = "<style>".to_string();
|
||||
|
||||
metadata_css!(".container", "color", self.container_inner_foreground->output);
|
||||
metadata_css!(".container", "padding", self.container_padding->output);
|
||||
metadata_css!(".container", "max-width", self.container_max_width->output);
|
||||
metadata_css!(".container", "color", self.container_inner_foreground_color->output);
|
||||
metadata_css!(".container", "background", self.container_inner_background->output);
|
||||
metadata_css!("body", "color", self.container_outer_foreground->output);
|
||||
metadata_css!(".container", "background-color", self.container_inner_background_color->output);
|
||||
metadata_css!(".container", "background-image", "url('{}')", self.container_inner_background_image->output);
|
||||
metadata_css!(".container", "background-repeat", self.container_inner_background_image_repeat->output);
|
||||
metadata_css!(".container", "background-position", self.container_inner_background_image_position->output);
|
||||
metadata_css!(".container", "background-size", self.container_inner_background_image_size->output);
|
||||
metadata_css!("body", "color", self.container_outer_foreground_color->output);
|
||||
metadata_css!("body", "background", self.container_outer_background->output);
|
||||
metadata_css!("body", "background-color", self.container_outer_background_color->output);
|
||||
metadata_css!("body", "background-image", "url('{}')", self.container_outer_background_image->output);
|
||||
metadata_css!("body", "background-repeat", self.container_outer_background_image_repeat->output);
|
||||
metadata_css!("body", "background-position", self.container_outer_background_image_position->output);
|
||||
metadata_css!("body", "background-size", self.container_outer_background_image_size->output);
|
||||
metadata_css!(".container", "border", self.container_border->output);
|
||||
metadata_css!(".container", "border-image", "url('{}')", self.container_border_image->output);
|
||||
metadata_css!(".container", "border-image-slice", self.container_border_image_slice->output);
|
||||
metadata_css!(".container", "border-image-repeat", self.container_border_image_repeat->output);
|
||||
metadata_css!(".container", "border-image-outset", self.container_border_image_outset->output);
|
||||
metadata_css!(".container", "border-image-width", self.container_border_image_width->output);
|
||||
metadata_css!(".container", "border-color", self.container_border_color->output);
|
||||
metadata_css!(".container", "border-style", self.container_border_style->output);
|
||||
metadata_css!(".container", "border-width", self.container_border_width->output);
|
||||
metadata_css!(".container", "border-radius", self.container_border_radius->output);
|
||||
metadata_css!(".container", "box-shadow", self.container_shadow->output);
|
||||
metadata_css!(".container", "text-shadow", self.content_text_shadow->output);
|
||||
metadata_css!(".container a", "color", self.content_text_link_color->output);
|
||||
|
||||
if self.content_text_align != TextAlignment::Left {
|
||||
|
@ -272,4 +439,54 @@ impl EntryMetadata {
|
|||
|
||||
output + "</style>"
|
||||
}
|
||||
|
||||
pub fn ini_to_toml(input: &str) -> String {
|
||||
let mut output = String::new();
|
||||
|
||||
for line in input.split("\n") {
|
||||
if !line.contains("=") {
|
||||
// no equal sign, skip line (some other toml function)
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut key = String::new();
|
||||
let mut value = String::new();
|
||||
|
||||
let mut chars = line.chars();
|
||||
let mut in_value = false;
|
||||
|
||||
while let Some(char) = chars.next() {
|
||||
if !in_value {
|
||||
key.push(char);
|
||||
|
||||
if char == '=' {
|
||||
in_value = true;
|
||||
}
|
||||
|
||||
continue;
|
||||
} else {
|
||||
value.push(char);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
value = value.trim().to_string();
|
||||
|
||||
// determine if we need to stringify
|
||||
let mut is_numeric = false;
|
||||
|
||||
for char in value.chars() {
|
||||
is_numeric = char.is_numeric();
|
||||
}
|
||||
|
||||
if !is_numeric && !value.starts_with("[") && !value.starts_with("\"") {
|
||||
value = format!("\"{value}\"");
|
||||
}
|
||||
|
||||
// push line
|
||||
output.push_str(&format!("{key} {value}\n"));
|
||||
}
|
||||
|
||||
output
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue