Made it so publish date is checked for tales.

Basically it will check against the UTC time and see if a tale should be
shown. If not, it doesn't return it.
This commit is contained in:
2025-09-08 21:12:16 -04:00
parent fe87b2f195
commit 6e643f6aab
2 changed files with 28 additions and 15 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "tavern"
version = "0.2.7"
version = "0.2.8"
edition = "2024"
description = "A blogging system that will allow you to write your blog in Markdown and then display it in HTML using Dioxus."
repository = "/CyberMages/tavern"

View File

@ -336,23 +336,28 @@ impl Database
}
let rows = q.fetch_all(&mut *tx).await?;
let current_time = chrono::Utc::now().naive_utc();
for row in rows
{
let tags_str: Option<String> = row.try_get("tags")?;
let tags = tags_str.map(|s| s.split(',').map(String::from).collect())
.unwrap_or_default();
let date_str: String = row.try_get("publish_date")?;
let publish_date = chrono::NaiveDateTime::parse_from_str(&date_str, "%Y-%m-%d %H:%M:%S")
.map_err(|e| sqlx::Error::Decode(e.into()))?;
tales.push(Lore { title: row.try_get("title")?,
slug: row.try_get("slug")?,
summary: row.try_get("summary")?,
author: row.try_get("author")?,
publish_date,
tags });
// Only give tales that are ready to be published.
if current_time <= publish_date
{
let tags_str: Option<String> = row.try_get("tags")?;
let tags = tags_str.map(|s| s.split(',').map(String::from).collect())
.unwrap_or_default();
tales.push(Lore { title: row.try_get("title")?,
slug: row.try_get("slug")?,
summary: row.try_get("summary")?,
author: row.try_get("author")?,
publish_date,
tags });
}
}
tx.commit().await?; // Explicit commit, even for read transactions.
@ -381,16 +386,24 @@ impl Database
tx.commit().await?;
let current_time = chrono::Utc::now().naive_utc();
if let Some(row) = tale_row
{
let tags_str: Option<String> = row.try_get("tags")?;
let tags = tags_str.map(|s| s.split(',').map(String::from).collect())
.unwrap_or_default();
let date_str: String = row.try_get("publish_date")?;
let publish_date = chrono::NaiveDateTime::parse_from_str(&date_str, "%Y-%m-%d %H:%M:%S")
.map_err(|e| Error::Decode(e.into()))?;
if current_time > publish_date
{
return Ok(None);
}
let tags_str: Option<String> = row.try_get("tags")?;
let tags = tags_str.map(|s| s.split(',').map(String::from).collect())
.unwrap_or_default();
let lore = Lore { title: row.try_get("title")?,
slug: row.try_get("slug")?,
summary: row.try_get("summary")?,