Post page now is completely done in SSR.

This was done to make loading time faster as it's all static information
and to make it so blog posts can be linked to and get OpenGraph data.
This commit is contained in:
2025-10-10 11:19:14 -04:00
parent 1a57f3d143
commit e8a4c19fdb
3 changed files with 48 additions and 30 deletions

2
Cargo.lock generated
View File

@ -297,7 +297,7 @@ dependencies = [
[[package]]
name = "bard"
version = "0.3.12"
version = "0.3.13"
dependencies = [
"dioxus",
"tavern",

View File

@ -1,6 +1,6 @@
[package]
name = "bard"
version = "0.3.12"
version = "0.3.13"
edition = "2024"
description = "Dioxus components that will display a Tavern blogging system Blog."
repository = "/CyberMages/tavern"

View File

@ -23,29 +23,55 @@ pub fn BlogAuthor() -> Element
#[component]
pub fn PostHeaderAuthor(adventurer: Adventurer) -> Element
pub fn PostHeaderAuthor(author: Option<Adventurer>) -> Element
{
rsx!
match author
{
document::Meta
Some(adventurer) =>
{
name: "author",
content: "{adventurer.name}"
rsx!
{
document::Meta
{
name: "author",
content: "{adventurer.name}"
}
p
{
b
{
"Author: ",
a { href: "{adventurer.legend.profile}", "{adventurer.name}" }
}
}
}
}
p
None=>
{
b
rsx!
{
"Author: ",
a { href: "{adventurer.legend.profile}", "{adventurer.name}" }
document::Meta
{
name: "author",
content: "Unknown"
}
p
{
b
{
"Author: Unknown"
}
}
}
}
}
}
#[component]
pub fn PostHeader(tale: Tale) -> Element
pub fn PostHeader(tale: Tale, adventurer: Option<Adventurer>) -> Element
{
// Get the pages URL.
let url: Page = use_route();
@ -55,13 +81,6 @@ pub fn PostHeader(tale: Tale) -> Element
// Retrieve the provided settings from context.
let settings = use_context::<BardSettings>();
let author_future = use_server_future(move ||
{
let handle: String = tale.lore.author.clone();
async move { get_author(handle).await }
})?;
rsx!
{
// Adding for SEO and OpenGraph post sharing.
@ -91,14 +110,7 @@ pub fn PostHeader(tale: Tale) -> Element
}
}
if let Some(Ok(Some(adventurer))) = (author_future.value())()
{
PostHeaderAuthor { adventurer: adventurer }
}
else
{
p { "Loading author..." }
}
PostHeaderAuthor { author: adventurer }
}
}
@ -125,7 +137,12 @@ pub fn BlogPost(slug: Signal<String>, children: Element) -> Element
// Make this reactive so that as the page changes it should rerun this.
let url_slug = slug();
async move { get_blog_post(url_slug).await }
async move
{
let post = get_blog_post(url_slug).await?;
let author = get_author(post.lore.author.clone()).await?;
Ok::<_, ServerFnError>((post, author))
}
})?;
rsx!
@ -134,11 +151,12 @@ pub fn BlogPost(slug: Signal<String>, children: Element) -> Element
{
class: "blog_post",
if let Some(Ok(tale)) = (post_future.value())()
if let Some(Ok((tale, adventurer))) = (post_future.value())()
{
PostHeader
{
tale: tale.clone()
tale: tale.clone(),
adventurer: adventurer.clone()
}
Story { text: tale.story }