about summary refs log tree commit diff
path: root/templates-neo/src
diff options
context:
space:
mode:
Diffstat (limited to 'templates-neo/src')
-rw-r--r--templates-neo/src/mf2.rs69
1 files changed, 36 insertions, 33 deletions
diff --git a/templates-neo/src/mf2.rs b/templates-neo/src/mf2.rs
index 8190720..3cf453f 100644
--- a/templates-neo/src/mf2.rs
+++ b/templates-neo/src/mf2.rs
@@ -64,7 +64,7 @@ impl TryFrom<Item> for Card {
             });
         }
 
-        let mut props = card.properties.take();
+        let mut props = card.properties;
         let uid = {
             let uids = props.remove("uid").ok_or(Error::NoUid)?;
             if let Some(PropertyValue::Url(uid)) = uids.into_iter().take(1).next() {
@@ -106,12 +106,12 @@ impl TryFrom<Item> for Card {
                 .unwrap_or_default()
                 .into_iter()
                 .next()
-                .and_then(|v| match v {
-                    PropertyValue::Plain(plain) => Some(Ok(plain)),
-                    other => Some(Err(Error::WrongValueType {
+                .map(|v| match v {
+                    PropertyValue::Plain(plain) => Ok(plain),
+                    other => Err(Error::WrongValueType {
                         expected: "string",
                         got: other,
-                    })),
+                    }),
                 })
                 .transpose()?,
             photo: props
@@ -122,10 +122,13 @@ impl TryFrom<Item> for Card {
                 .ok_or(Error::MissingProperty("photo"))
                 .and_then(|v| match v {
                     PropertyValue::Url(url) => Ok(Image::Plain(url)),
-                    PropertyValue::Image(image) => Ok(Image::Accessible {
-                        src: image.src,
-                        alt: image.alt,
-                    }),
+                    PropertyValue::Image(image) => match image.alt {
+                        Some(alt) => Ok(Image::Accessible {
+                            src: image.value,
+                            alt,
+                        }),
+                        None => Ok(Image::Plain(image.value))
+                    },
                     other => Err(Error::WrongValueType {
                         expected: "string",
                         got: other,
@@ -198,7 +201,7 @@ impl Card {
                 for url in urls {
                     let url = String::from(url);
                     ul.list_item(move |li| {
-                        li.push({ Anchor::builder().href(url.clone()).text(url).build() })
+                        li.push(Anchor::builder().href(url.clone()).text(url).build())
                     });
                 }
 
@@ -215,7 +218,7 @@ impl TryFrom<PropertyValue> for Card {
 
     fn try_from(v: PropertyValue) -> Result<Self, Self::Error> {
         match v {
-            PropertyValue::Item(item) => item.take().try_into(),
+            PropertyValue::Item(item) => item.try_into(),
             other => Err(Error::WrongValueType {
                 expected: "h-card",
                 got: other,
@@ -229,7 +232,7 @@ pub struct Cite {
     url: Vec<url::Url>,
     in_reply_to: Option<Vec<Citation>>,
     author: Card,
-    published: Option<chrono::DateTime<chrono::FixedOffset>>,
+    published: Option<time::OffsetDateTime>,
     content: Content,
 }
 
@@ -258,7 +261,7 @@ impl TryFrom<PropertyValue> for Citation {
     fn try_from(v: PropertyValue) -> Result<Self, Self::Error> {
         match v {
             PropertyValue::Url(url) => Ok(Self::Brief(url)),
-            PropertyValue::Item(item) => Ok(Self::Full(item.take().try_into()?)),
+            PropertyValue::Item(item) => Ok(Self::Full(item.try_into()?)),
             other => Err(Error::WrongValueType {
                 expected: "url or h-cite",
                 got: other,
@@ -287,7 +290,7 @@ pub struct Entry {
     author: Card,
     category: Vec<String>,
     syndication: Vec<url::Url>,
-    published: chrono::DateTime<chrono::FixedOffset>,
+    published: time::OffsetDateTime,
     content: Content,
 }
 
@@ -301,7 +304,7 @@ impl TryFrom<Item> for Entry {
             });
         }
 
-        let mut props = entry.properties.take();
+        let mut props = entry.properties;
         let uid = {
             let uids = props.remove("uid").ok_or(Error::NoUid)?;
             if let Some(PropertyValue::Url(uid)) = uids.into_iter().take(1).next() {
@@ -369,23 +372,26 @@ impl TryFrom<Item> for Entry {
                 .into_iter()
                 .next()
                 .map(
-                    |v| -> Result<chrono::DateTime<chrono::FixedOffset>, Error> {
+                    |v| -> Result<time::OffsetDateTime, Error> {
                         match v {
-                            PropertyValue::Temporal(Temporal::Timestamp(dt)) => {
+                            PropertyValue::Temporal(Temporal::Timestamp(ref dt)) => {
                                 // This is incredibly sketchy.
                                 let (date, time, offset) = (
-                                    dt.date.clone().unwrap().data,
-                                    dt.as_time().unwrap().data.clone(),
-                                    dt.as_time().unwrap().offset.unwrap().data,
+                                    dt.date.to_owned().ok_or_else(|| Error::WrongValueType {
+                                        expected: "timestamp (date, time, offset)",
+                                        got: v.clone()
+                                    })?.data,
+                                    dt.time.to_owned().ok_or_else(|| Error::WrongValueType {
+                                        expected: "timestamp (date, time, offset)",
+                                        got: v.clone()
+                                    })?.data,
+                                    dt.offset.to_owned().ok_or_else(|| Error::WrongValueType {
+                                        expected: "timestamp (date, time, offset)",
+                                        got: v.clone()
+                                    })?.data,
                                 );
 
-                                date.and_time(time)
-                                    .and_local_timezone(offset)
-                                    .single()
-                                    .ok_or_else(|| Error::WrongValueType {
-                                        expected: "datetime with timezone",
-                                        got: PropertyValue::Temporal(Temporal::Timestamp(dt)),
-                                    })
+                                Ok(date.with_time(time).assume_offset(offset))
                             }
                             other => Err(Error::WrongValueType {
                                 expected: "timestamp",
@@ -428,13 +434,10 @@ impl Entry {
                                         html::inline_text::Time::builder()
                                             .text(
                                                 self.published
-                                                    .format("%Y-%m-%d %a %H:%M:%S %z")
-                                                    .to_string(),
+                                                    .format(&time::format_description::well_known::Rfc2822)
+                                                    .unwrap()
                                             )
-                                            .date_time(self.published.to_rfc3339_opts(
-                                                chrono::SecondsFormat::Secs,
-                                                false,
-                                            ))
+                                            .date_time(self.published.format(&time::format_description::well_known::Rfc3339).unwrap())
                                             .build(),
                                     )
                                 })