From 2224f5557a3f2d522a82de27cee73234fa856298 Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 30 Mar 2025 00:54:24 +0300 Subject: Allow sending HTML without plain-text pre-processing by the server This might be useful if your server is misbehaving, or if you wish to write your HTML by hand. Alternative options (like client-side preprocessing) can also be added in the future using this setting as a framework. --- src/components/post_editor.rs | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'src/components/post_editor.rs') diff --git a/src/components/post_editor.rs b/src/components/post_editor.rs index 25069be..863e515 100644 --- a/src/components/post_editor.rs +++ b/src/components/post_editor.rs @@ -32,40 +32,52 @@ pub struct Post { pub visibility: Visibility } -impl From for microformats::types::Item { - fn from(post: Post) -> Self { - use microformats::types::{Item, Class, KnownClass, PropertyValue}; +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub struct PostConversionSettings { + pub send_html_directly: bool, +} + +impl Post { + pub fn into_mf2(self, settings: PostConversionSettings) -> microformats::types::Item { + use microformats::types::{Item, Class, KnownClass, PropertyValue, Fragment}; let mut mf2 = Item::new(vec![Class::Known(KnownClass::Entry)]); - if let Some(name) = post.name { + if let Some(name) = self.name { mf2.properties.insert( "name".to_owned(), vec![PropertyValue::Plain(name)] ); } - if let Some(summary) = post.summary { + if let Some(summary) = self.summary { mf2.properties.insert( "summary".to_owned(), vec![PropertyValue::Plain(summary)] ); } - if !post.tags.is_empty() { + if !self.tags.is_empty() { mf2.properties.insert( "category".to_string(), - post.tags.into_iter().map(PropertyValue::Plain).collect() + self.tags.into_iter().map(PropertyValue::Plain).collect() ); } mf2.properties.insert( "visibility".to_string(), - vec![PropertyValue::Plain(post.visibility.to_string())] + vec![PropertyValue::Plain(self.visibility.to_string())] ); - mf2.properties.insert( - "content".to_string(), - vec![PropertyValue::Plain(post.content)] - ); + let content = if settings.send_html_directly { + PropertyValue::Fragment(Fragment { + html: self.content.clone(), + value: self.content, + lang: None + }) + } else { + PropertyValue::Plain(self.content) + }; + + mf2.properties.insert("content".to_string(), vec![content]); mf2 } -- cgit 1.4.1