summary refs log tree commit diff
path: root/src/components/post_editor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/post_editor.rs')
-rw-r--r--src/components/post_editor.rs36
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
     }