From 4100e7db9fc88cbc9a6e9bbe508097f971761269 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Wed, 31 Jan 2024 17:52:44 +0000 Subject: change Post updated_at to an option --- src/atom.rs | 18 +++++++++++++----- src/posts.rs | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/atom.rs b/src/atom.rs index 4410edb..a64a6aa 100644 --- a/src/atom.rs +++ b/src/atom.rs @@ -68,11 +68,19 @@ pub async fn atom(ctx: Context, entries: Vec

) -> Feed { .clone() .into_iter() .fold(DateTime::::MIN_UTC, |acc, entry| { - let updated_at = entry.updated_at().to_owned(); - if updated_at > acc { - updated_at + if let Some(updated_at) = entry.updated_at() { + if *updated_at > acc { + *updated_at + } else { + acc + } } else { - acc + let published_at = entry.published_at(); + if *published_at > acc { + *published_at + } else { + acc + } } }) .into(), @@ -118,7 +126,7 @@ pub async fn atom(ctx: Context, entries: Vec

) -> Feed { r#type: TextType::Text, }, id: entry.link(), - updated: entry.updated_at().to_owned().into(), + updated: (*entry.updated_at().unwrap_or_else(|| entry.published_at())).into(), authors: authors.clone(), categories, contributors: authors.clone(), diff --git a/src/posts.rs b/src/posts.rs index 415f743..a8e9f90 100644 --- a/src/posts.rs +++ b/src/posts.rs @@ -13,7 +13,7 @@ pub trait Post { fn id(&self) -> &str; fn subject(&self) -> Option<&str>; fn published_at(&self) -> &DateTime; - fn updated_at(&self) -> &DateTime; + fn updated_at(&self) -> Option<&DateTime>; fn tags(&self) -> &Vec; fn lang(&self) -> &str; fn post_type(&self) -> PostType; -- cgit