diff options
author | Vika <vika@fireburn.ru> | 2025-03-30 00:54:24 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2025-03-30 00:54:24 +0300 |
commit | 2224f5557a3f2d522a82de27cee73234fa856298 (patch) | |
tree | b0b8cd37a84766502f451ae101c2867d7d62ea55 /src/components/post_editor.rs | |
parent | 20f1d890bd87a3d0e72cb150e02433340abb0e9d (diff) | |
download | bowl-2224f5557a3f2d522a82de27cee73234fa856298.tar.zst |
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.
Diffstat (limited to 'src/components/post_editor.rs')
-rw-r--r-- | src/components/post_editor.rs | 36 |
1 files changed, 24 insertions, 12 deletions
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<Post> 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 } |