From 4ac4aac8eca7cf711b6d2d22a952cc0960831b92 Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Tue, 12 Mar 2024 03:26:52 +0000 Subject: [PATCH] Validate that timestamps are correct There was a bug where timestamps could be in the future, which would make the zine show the same post every single day. --- src/utilities.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/utilities.rs b/src/utilities.rs index f6a2c6b..ee10e10 100644 --- a/src/utilities.rs +++ b/src/utilities.rs @@ -26,13 +26,22 @@ pub fn read_feed(path: &str) -> Vec { } } - // Remove any entries that don't have a timestamp, and then sort by timestamps - entries.retain(|entry| entry.published.is_some() || entry.updated.is_some()); + entries.retain(validate_entry_date); entries.sort_by_key(|entry| Reverse(get_entry_date(entry))); entries } +fn validate_entry_date(entry: &Entry) -> bool { + // Check that entry has a timestamp associated with it + if entry.published.is_some() || entry.updated.is_some() { + // Make sure post doesn't "exist in the future" + get_entry_date(entry) < chrono::Utc::now() + } else { + false + } +} + pub fn get_entry_date(entry: &Entry) -> chrono::DateTime { entry.published.unwrap_or(entry.updated.unwrap_or_default()) }