mirror of
https://gitlab.com/Anson-Projects/zine.git
synced 2025-06-16 05:26:40 +00:00
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.
This commit is contained in:
parent
f2475fba37
commit
4ac4aac8ec
@ -26,13 +26,22 @@ pub fn read_feed(path: &str) -> Vec<Entry> {
|
||||
}
|
||||
}
|
||||
|
||||
// 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<chrono::Utc> {
|
||||
entry.published.unwrap_or(entry.updated.unwrap_or_default())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user