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:
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tavern"
|
name = "tavern"
|
||||||
version = "0.2.7"
|
version = "0.2.8"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
description = "A blogging system that will allow you to write your blog in Markdown and then display it in HTML using Dioxus."
|
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"
|
repository = "/CyberMages/tavern"
|
||||||
|
|||||||
@ -336,23 +336,28 @@ impl Database
|
|||||||
}
|
}
|
||||||
|
|
||||||
let rows = q.fetch_all(&mut *tx).await?;
|
let rows = q.fetch_all(&mut *tx).await?;
|
||||||
|
let current_time = chrono::Utc::now().naive_utc();
|
||||||
|
|
||||||
for row in rows
|
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 date_str: String = row.try_get("publish_date")?;
|
||||||
let publish_date = chrono::NaiveDateTime::parse_from_str(&date_str, "%Y-%m-%d %H:%M:%S")
|
let publish_date = chrono::NaiveDateTime::parse_from_str(&date_str, "%Y-%m-%d %H:%M:%S")
|
||||||
.map_err(|e| sqlx::Error::Decode(e.into()))?;
|
.map_err(|e| sqlx::Error::Decode(e.into()))?;
|
||||||
|
|
||||||
tales.push(Lore { title: row.try_get("title")?,
|
// Only give tales that are ready to be published.
|
||||||
slug: row.try_get("slug")?,
|
if current_time <= publish_date
|
||||||
summary: row.try_get("summary")?,
|
{
|
||||||
author: row.try_get("author")?,
|
let tags_str: Option<String> = row.try_get("tags")?;
|
||||||
publish_date,
|
let tags = tags_str.map(|s| s.split(',').map(String::from).collect())
|
||||||
tags });
|
.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.
|
tx.commit().await?; // Explicit commit, even for read transactions.
|
||||||
@ -381,16 +386,24 @@ impl Database
|
|||||||
|
|
||||||
tx.commit().await?;
|
tx.commit().await?;
|
||||||
|
|
||||||
|
|
||||||
|
let current_time = chrono::Utc::now().naive_utc();
|
||||||
|
|
||||||
if let Some(row) = tale_row
|
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 date_str: String = row.try_get("publish_date")?;
|
||||||
let publish_date = chrono::NaiveDateTime::parse_from_str(&date_str, "%Y-%m-%d %H:%M:%S")
|
let publish_date = chrono::NaiveDateTime::parse_from_str(&date_str, "%Y-%m-%d %H:%M:%S")
|
||||||
.map_err(|e| Error::Decode(e.into()))?;
|
.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")?,
|
let lore = Lore { title: row.try_get("title")?,
|
||||||
slug: row.try_get("slug")?,
|
slug: row.try_get("slug")?,
|
||||||
summary: row.try_get("summary")?,
|
summary: row.try_get("summary")?,
|
||||||
|
|||||||
Reference in New Issue
Block a user